Skip to content

Commit

Permalink
CMake: Generate deployment information for each deployable target
Browse files Browse the repository at this point in the history
When using CMake 3.19 or newer, we generate a .qt/QtDeployTargets.cmake
file per project. This contains the following information for each
deployable target:

1. The full path to the produced artifact. This will allow us to avoid
the file name heuristics when deploying QML plugins.

2. The DLLs that are needed at runtime, when using CMake 3.21 or newer
on Windows. This will allow us to deploy QML module backing libraries
and runtime DLLs of to-be-deployed targets.

Task-number: QTBUG-117948
Task-number: QTBUG-118153
Change-Id: I8a670e44f62a872f1a21174e947d87ccb8191073
Reviewed-by: Alexandru Croitor <[email protected]>
  • Loading branch information
jobor committed Dec 4, 2023
1 parent 2c3116b commit d08fa86
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/corelib/Qt6CoreMacros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2750,6 +2750,22 @@ function(_qt_internal_setup_deploy_support)
set(target ${aliased_target})
endif()

# Generate deployment information for each target if the CMake version is recent enough.
# The call is deferred to have all targets of the projects available.
if(CMAKE_VERSION GREATER_EQUAL "3.19.0")
if(is_multi_config)
set(targets_file "${deploy_impl_dir}/QtDeployTargets-$<CONFIG>.cmake")
else()
set(targets_file "${deploy_impl_dir}/QtDeployTargets.cmake")
endif()
cmake_language(EVAL CODE
"cmake_language(DEFER
DIRECTORY [[${CMAKE_SOURCE_DIR}]]
CALL _qt_internal_write_target_deploy_info [[${targets_file}]])"
)
set_property(TARGET ${target} PROPERTY _qt_deploy_support_files "${targets_file}")
endif()

# Make sure to look under the Qt bin dir with find_program, rather than randomly picking up
# a deployqt tool in the system.
# QT6_INSTALL_PREFIX is not set during Qt build, so add the hints conditionally.
Expand Down Expand Up @@ -2914,6 +2930,22 @@ unset(__qt_deploy_support_files)
")
endfunction()

# Write deployment information for the targets of the project.
function(_qt_internal_write_target_deploy_info out_file)
_qt_internal_collect_buildsystem_targets(targets
"${CMAKE_SOURCE_DIR}" INCLUDE EXECUTABLE SHARED_LIBRARY MODULE_LIBRARY)
set(content "")
foreach(target IN LISTS targets)
set(var_prefix "__QT_DEPLOY_TARGET_${target}")
string(APPEND content "set(${var_prefix}_FILE $<TARGET_FILE:${target}>)\n")
if(WIN32 AND CMAKE_VERSION GREATER_EQUAL "3.21")
string(APPEND content
"set(${var_prefix}_RUNTIME_DLLS $<TARGET_RUNTIME_DLLS:${target}>)\n")
endif()
endforeach()
file(GENERATE OUTPUT "${out_file}" CONTENT "${content}")
endfunction()

# We basically mirror CMake's policy setup
# A policy can be set to OLD, set to NEW or unset
# unset is the default state
Expand Down

0 comments on commit d08fa86

Please sign in to comment.