From c097256ee4b207284148a8026bb29fc4453efeae Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Wed, 15 May 2019 11:30:57 +0200 Subject: [PATCH] Encapsulate commands for building other repos into two macros Currently to build qtsvg we have some copy-pasted code to set up the paths for QtSetup and QtPostProcess to be found. To make it cleaner, introduce two new macros called qt_build_repo_begin and qt_build_repo_end(). The first one should be called in a child repo like qtsvg, right after a find_package(Qt5) call, and the second one at the end of the repo top-level CMakeLists.txt file. In order for the macros to work, extract some of the variables which were set in Qt5Config into Qt5CoreConfig instead. This makes sure that it works also for find_package(Qt5Core) calls. Task-number: QTBUG-75580 Change-Id: I85267c6bd86f9291ec2e170fddab1006ab684b5c Reviewed-by: Simon Hausmann --- cmake/QtBuild.cmake | 15 +++++++++++++-- cmake/QtConfig.cmake.in | 3 --- src/corelib/Qt5CoreMacros.cmake | 23 +++++++++++++++++++++++ 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/cmake/QtBuild.cmake b/cmake/QtBuild.cmake index 87a48b0aca7..bfbd0f69e4d 100644 --- a/cmake/QtBuild.cmake +++ b/cmake/QtBuild.cmake @@ -928,10 +928,21 @@ function(add_qt_module target) set(extra_cmake_code "") - # Propagate developer builds to other modules via QtCore module. - if(FEATURE_developer_build AND target STREQUAL Core) + if(target STREQUAL Core) + # Propagate common variables via QtCore package. + string(APPEND extra_cmake_code "set(QT_BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS})") string(APPEND extra_cmake_code " +option(BUILD_SHARED_LIBS \"Build Qt statically or dynamically\" ${BUILD_SHARED_LIBS})") + string(APPEND extra_cmake_code " +set(QT_CMAKE_EXPORT_NAMESPACE ${QT_CMAKE_EXPORT_NAMESPACE})") + string(APPEND extra_cmake_code " +set(_qt_core_cmake_dir \${CMAKE_CURRENT_LIST_DIR})") + + # Propagate developer builds to other modules via QtCore package. + if(FEATURE_developer_build) + string(APPEND extra_cmake_code " set(FEATURE_developer_build ON CACHE BOOL \"Developer build.\" FORCE)") + endif() endif() configure_package_config_file( diff --git a/cmake/QtConfig.cmake.in b/cmake/QtConfig.cmake.in index 73871747e08..df6068f9a37 100644 --- a/cmake/QtConfig.cmake.in +++ b/cmake/QtConfig.cmake.in @@ -36,9 +36,6 @@ foreach(module ${@INSTALL_CMAKE_NAMESPACE@_FIND_COMPONENTS}) endif() endforeach() -set(QT_BUILD_SHARED_LIBS @BUILD_SHARED_LIBS@) -set(QT_CMAKE_EXPORT_NAMESPACE @QT_CMAKE_EXPORT_NAMESPACE@) - if (_Qt_NOTFOUND_MESSAGE) set(@INSTALL_CMAKE_NAMESPACE@_NOT_FOUND_MESSAGE "${_Qt_NOTFOUND_MESSAGE}") set(@INSTALL_CMAKE_NAMESPACE@_FOUND False) diff --git a/src/corelib/Qt5CoreMacros.cmake b/src/corelib/Qt5CoreMacros.cmake index bae1518375b..feab963a801 100644 --- a/src/corelib/Qt5CoreMacros.cmake +++ b/src/corelib/Qt5CoreMacros.cmake @@ -38,6 +38,29 @@ include(CMakeParseArguments) +macro(qt_build_repo_begin) + # Set up the paths for the modules. + set(QT_CMAKE_MODULE_PATH "${_qt_core_cmake_dir}/../${QT_CMAKE_EXPORT_NAMESPACE}") + list(APPEND CMAKE_MODULE_PATH ${QT_CMAKE_MODULE_PATH}) + + # Qt specific setup common for all modules: + include(QtSetup) + include(FeatureSummary) +endmacro() + +macro(qt_build_repo_end) + # Delayed actions on some of the Qt targets: + include(QtPostProcess) + + # Print a feature summary: + feature_summary(WHAT PACKAGES_FOUND + REQUIRED_PACKAGES_NOT_FOUND + RECOMMENDED_PACKAGES_NOT_FOUND + OPTIONAL_PACKAGES_NOT_FOUND + RUNTIME_PACKAGES_NOT_FOUND + FATAL_ON_MISSING_REQUIRED_PACKAGES) +endmacro() + # macro used to create the names of output files preserving relative dirs macro(QT5_MAKE_OUTPUT_FILE infile prefix ext outfile ) string(LENGTH ${CMAKE_CURRENT_BINARY_DIR} _binlength)