vcpkg
vcpkg copied to clipboard
[qtbase] CMake deployment (windeployqt) functions do not work properly in Debug config with Visual Studio
Describe the bug For multi-configs builds such as with Visual Studio, the CMake deployment support macros do not work correctly in Debug config.
Environment
- OS: Windows
- Compiler: VS 17.10.3 with CMake 3.29.6
To Reproduce Steps to reproduce the behavior:
- Do something like the below in CMake (also fails for non-QML projects):
qt_generate_deploy_qml_app_script(
TARGET ${TARGET_NAME}
OUTPUT_SCRIPT deploy_script
)
install(SCRIPT ${deploy_script})
- Perform CMake INSTALL in Debug config
- Observe that not all the expected files are installed. Furthermore, the CMake output will have errors like the below:
Unable to find dependent libraries of C:\my_project\build\dev-vs\vcpkg_installed\x64-windows\bin\Qt6Cored.dll :Cannot open 'C:/my_project/build/dev-vs/vcpkg_installed/x64-windows/bin/Qt6Cored.dll': The system cannot find the file specified.
Cause/Investigation
In Debug config, the CMake deployment support functions are looking for the Qt binaries in the wrong location (bin
instead of debug/bin
). This is due to CMake not choosing the correct qtpaths
executable: qtpaths.debug.bat
should be used, but qtpaths6.exe
is incorrectly used.
The changes introduced by the fix_deploy_windows.patch
port patch are not working as intended for multi-config builds. This is because the CMAKE_BUILD_TYPE STREQUAL "Debug"
condition added by the patch is evaluated during CMake configure and will not be correct if CMAKE_BUILD_TYPE is not explicitly set to Debug.
Workaround
Workaround is hacky and is to manually clear the internal CMake var which points to the incorrect qtpaths
tool. We then rely on qtpaths.debug.bat
to provide the correct path to the tool (which it does).
QML projects:
qt_generate_deploy_script(
TARGET ${TARGET_NAME}
OUTPUT_SCRIPT deploy_script
CONTENT "
# Workaround so that 'qtpaths.debug.bat' is used in Debug config.
if(\$<CONFIG:Debug>)
set(__QT_DEPLOY_TARGET_QT_PATHS_PATH \"\")
endif()
qt_deploy_qml_imports(
TARGET ${TARGET_NAME}
PLUGINS_FOUND plugins_found
)
qt_deploy_runtime_dependencies(
EXECUTABLE $<TARGET_FILE:${TARGET_NAME}>
ADDITIONAL_MODULES \${plugins_found}
)
")
install(SCRIPT ${deploy_script})
or non-QML projects:
qt_generate_deploy_script(
TARGET ${TARGET_NAME}
OUTPUT_SCRIPT deploy_script
CONTENT "
# Workaround so that 'qtpaths.debug.bat' is used in Debug config.
if(\$<CONFIG:Debug>)
set(__QT_DEPLOY_TARGET_QT_PATHS_PATH \"\")
endif()
qt_deploy_runtime_dependencies(
EXECUTABLE $<TARGET_FILE:${TARGET_NAME}>
DEPLOY_TOOL_OPTIONS ${WINDEPLOYQT_ARGS}
)
")
install(SCRIPT ${deploy_script})