From 92ee9bd6b885879090ba57e49c8bd84a06d42b2b Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Mon, 3 Aug 2020 16:28:16 +0200 Subject: CMake: Properly handle CONFIG += thread aka Threads::Threads mkspecs/features/qt.prf adds a dependency on the system threading library if the Qt Core thread feature is enabled. Because qt.prf is loaded by any public or internal Qt project, it's essentially a public dependency for any Qt consumer. To mimic that in CMake, we check if the thread feature is enabled, and and set the Threads::Threads library as a dependency of Qt6::Platform, which is a public target used by all Qt modules and plugins and Qt consumers. We also need to create a Qt6Dependencies.cmake file so we find_package(Threads) every time find_package(Qt6) is called. For the .prl files to be usable, we have to filter out some CMake implementation specific directory separator tokens 'CMAKE_DIRECTORY_ID_SEP' aka '::@', which are added because we call target_link_libraries() with a target created in a different scope (I think). As a result of this change, we shouldn't have to hardcode Threads::Threads in other projects, because it's now a global public dependency. Task-number: QTBUG-85801 Task-number: QTBUG-85877 Change-Id: Ib5d662c43b28e63f7da49d3bd77d0ad751220b31 Reviewed-by: Qt CI Bot Reviewed-by: Cristian Adam --- cmake/QtPostProcess.cmake | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'cmake/QtPostProcess.cmake') diff --git a/cmake/QtPostProcess.cmake b/cmake/QtPostProcess.cmake index 2ad06a5a7b..2bc6d7ae3a 100644 --- a/cmake/QtPostProcess.cmake +++ b/cmake/QtPostProcess.cmake @@ -262,10 +262,57 @@ function(qt_internal_create_plugin_depends_file target) endif() endfunction() +function(qt_internal_create_qt6_dependencies_file) + # This is used for substitution in the configured file. + set(target "${INSTALL_CMAKE_NAMESPACE}") + + # This is the actual target we're querying. + set(actual_target Platform) + get_target_property(public_depends "${actual_target}" INTERFACE_LINK_LIBRARIES) + + # We need to collect third party deps that are set on the public Platform target, + # like Threads::Threads. + # This mimics find_package part of the CONFIG += thread assignment in mkspecs/features/qt.prf. + qt_collect_third_party_deps(${actual_target}) + + # For Threads we also need to write an extra variable assignment. + set(third_party_extra "") + if(third_party_deps MATCHES "Threads") + string(APPEND third_party_extra "if(NOT QT_NO_THREADS_PREFER_PTHREAD_FLAG) + set(THREADS_PREFER_PTHREAD_FLAG TRUE) +endif()") + endif() + + if(third_party_deps) + # Setup build and install paths. + set(path_suffix "${INSTALL_CMAKE_NAMESPACE}") + + qt_path_join(config_build_dir ${QT_CONFIG_BUILD_DIR} ${path_suffix}) + qt_path_join(config_install_dir ${QT_CONFIG_INSTALL_DIR} ${path_suffix}) + + # Configure and install QtDependencies file. + configure_file( + "${QT_CMAKE_DIR}/QtConfigDependencies.cmake.in" + "${config_build_dir}/${target}Dependencies.cmake" + @ONLY + ) + + qt_install(FILES + "${config_build_dir}/${target}Dependencies.cmake" + DESTINATION "${config_install_dir}" + COMPONENT Devel + ) + endif() +endfunction() + # Create Depends.cmake & Depends.h files for all modules and plug-ins. function(qt_internal_create_depends_files) qt_internal_get_qt_repo_known_modules(repo_known_modules) + if(PROJECT_NAME STREQUAL "QtBase") + qt_internal_create_qt6_dependencies_file() + endif() + foreach (target ${repo_known_modules}) qt_internal_create_module_depends_file(${target}) endforeach() -- cgit v1.2.3