microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
22.92k stars 6.33k forks source link

[qtbase] CMake deployment (windeployqt) functions do not work properly in Debug config with Visual Studio #39534

Open nickdademo opened 3 months ago

nickdademo commented 3 months ago

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

To Reproduce Steps to reproduce the behavior:

  1. 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})
  2. Perform CMake INSTALL in Debug config
  3. 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})
LilyWangLL commented 3 months ago

Thanks for posting this issue. I checked the configure log of qtbase, and macro CMAKE_BUILD_TYPE was passed correctly as below. There is no issue with patch fix_deploy_windows.patch.

"-DCMAKE_BUILD_TYPE=Release"
"-DCMAKE_BUILD_TYPE=Debug"
nickdademo commented 3 months ago

Thanks for posting this issue. I checked the configure log of qtbase, and macro CMAKE_BUILD_TYPE was passed correctly as below. There is no issue with patch fix_deploy_windows.patch.

"-DCMAKE_BUILD_TYPE=Release"
"-DCMAKE_BUILD_TYPE=Debug"

Which log exactly? Was this a command line build? Did you try with Visual Studio IDE?

LilyWangLL commented 3 months ago

The config-x64-windows-out.log of qtbase, there are macros "-DCMAKE_BUILD_TYPE=Release" and "-DCMAKE_BUILD_TYPE=Debug" in cmake.exe command.

dg0yt commented 3 months ago

The config-x64-windows-out.log of qtbase, there are macros "-DCMAKE_BUILD_TYPE=Release" and "-DCMAKE_BUILD_TYPE=Debug" in cmake.exe command.

@LilyWangLL you are asking details about building Qt. But the issue is about using Qt with multi-config generators.

nickdademo commented 3 months ago

The config-x64-windows-out.log of qtbase, there are macros "-DCMAKE_BUILD_TYPE=Release" and "-DCMAKE_BUILD_TYPE=Debug" in cmake.exe command.

CMake correctly generates all the required files for each config; the problem is during executing these CMake deployment functions/macros during build (as @dg0yt mentioned).

github-actions[bot] commented 2 months ago

This is an automated message. Per our repo policy, stale issues get closed if there has been no activity in the past 28 days. The issue will be automatically closed in 14 days. If you wish to keep this issue open, please add a new comment.