diff options
author | Joerg Bornemann <joerg.bornemann@qt.io> | 2021-09-30 15:05:52 +0200 |
---|---|---|
committer | Joerg Bornemann <joerg.bornemann@qt.io> | 2021-10-05 19:35:47 +0200 |
commit | 165e01d5d51d16377542c1b3ffbc22f03fb75e97 (patch) | |
tree | e118b1ac097480798769ea6f3d480ed10b0f35c5 | |
parent | 719990d4ef4729ba5e145306f555bcd73ea944e7 (diff) |
CMake: Ensure that UNIX is set for INTEGRITY
Certain platform-related variables, in this case UNIX, must be set in a
platform module, because they get cleared after the toolchain file is
loaded. Such platform modules live in upstream CMake, but there is none
yet for INTEGRITY. This manifests in an undefined UNIX variable and
"System is unknown to CMake" warnings for the project and every
configure test.
Add the CMake module "Platform/Integrity" in the cmake/platforms
directory. Add this directory to CMAKE_MODULE_PATH to let CMake load
Platform/Integrity when the toolchain file set CMAKE_SYSTEM_NAME to
"Integrity".
CMake's module directory takes precedence, when loading platform
modules. This is special for platform modules and different from the
documented behavior of CMAKE_MODULE_PATH and include().
In case the user wants to provide their own platform modules via
CMAKE_MODULE_PATH, they can instruct Qt to not add its path by setting
QT_AVOID_CUSTOM_PLATFORM_MODULES to ON.
Make sure that configure tests with project files also load the custom
platform module.
Pick-to: 6.2
Fixes: QTBUG-96998
Change-Id: I9855d620d24dc66353cec5e847a2675b464ace26
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
-rw-r--r-- | cmake/QtAutoDetect.cmake | 6 | ||||
-rw-r--r-- | cmake/QtBaseGlobalTargets.cmake | 5 | ||||
-rw-r--r-- | cmake/QtFeature.cmake | 21 | ||||
-rw-r--r-- | cmake/platforms/Platform/Integrity.cmake | 8 | ||||
-rw-r--r-- | cmake/qt.toolchain.cmake.in | 6 |
5 files changed, 45 insertions, 1 deletions
diff --git a/cmake/QtAutoDetect.cmake b/cmake/QtAutoDetect.cmake index 128a882b8d..ce87560a85 100644 --- a/cmake/QtAutoDetect.cmake +++ b/cmake/QtAutoDetect.cmake @@ -433,6 +433,12 @@ function(qt_auto_detect_integrity) endif() endfunction() +# Let CMake load our custom platform modules. +# CMake-provided platform modules take precedence. +if(NOT QT_AVOID_CUSTOM_PLATFORM_MODULES) + list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/platforms") +endif() + qt_auto_detect_cmake_generator() qt_auto_detect_cyclic_toolchain() qt_auto_detect_cmake_config() diff --git a/cmake/QtBaseGlobalTargets.cmake b/cmake/QtBaseGlobalTargets.cmake index dd7ceecb35..0c7d73375e 100644 --- a/cmake/QtBaseGlobalTargets.cmake +++ b/cmake/QtBaseGlobalTargets.cmake @@ -265,6 +265,11 @@ qt_copy_or_install(FILES DESTINATION "${__GlobalConfig_install_dir}" ) +# Install our custom platform modules. +qt_copy_or_install(DIRECTORY cmake/platforms + DESTINATION "${__GlobalConfig_install_dir}" +) + # Install public config.tests files. qt_copy_or_install(DIRECTORY "config.tests/static_link_order" diff --git a/cmake/QtFeature.cmake b/cmake/QtFeature.cmake index f7435df9de..3a366f05ae 100644 --- a/cmake/QtFeature.cmake +++ b/cmake/QtFeature.cmake @@ -801,7 +801,14 @@ function(qt_config_compile_test name) # If the repo has its own cmake modules, include those in the module path, so that various # find_package calls work. if(EXISTS "${PROJECT_SOURCE_DIR}/cmake") - list(APPEND flags "-DCMAKE_MODULE_PATH:STRING=${PROJECT_SOURCE_DIR}/cmake") + set(flags_copy "${flags}") + set(flags) + foreach(flag IN LISTS flags_copy) + if(flag MATCHES "^-DCMAKE_MODULE_PATH:STRING=") + set(flag "${flag};${PROJECT_SOURCE_DIR}/cmake") + endif() + list(APPEND flags "${flag}") + endforeach() endif() # Pass which packages need to be found. @@ -907,6 +914,7 @@ function(qt_config_compile_test name) set(_save_CMAKE_C_STANDARD "${CMAKE_C_STANDARD}") set(_save_CMAKE_CXX_STANDARD "${CMAKE_CXX_STANDARD}") set(_save_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") + set(_save_CMAKE_TRY_COMPILE_PLATFORM_VARIABLES "${CMAKE_TRY_COMPILE_PLATFORM_VARIABLES}") if(arg_C_STANDARD) set(CMAKE_C_STANDARD "${arg_C_STANDARD}") @@ -928,6 +936,11 @@ function(qt_config_compile_test name) list(APPEND CMAKE_REQUIRED_FLAGS "-Zc:__cplusplus") endif() + # Let CMake load our custom platform modules. + if(NOT QT_AVOID_CUSTOM_PLATFORM_MODULES) + list(APPEND CMAKE_TRY_COMPILE_PLATFORM_VARIABLES CMAKE_MODULE_PATH) + endif() + set(_save_CMAKE_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}") set(CMAKE_REQUIRED_LIBRARIES "${arg_LIBRARIES}") check_cxx_source_compiles("${arg_UNPARSED_ARGUMENTS} ${arg_CODE}" HAVE_${name}) @@ -936,6 +949,7 @@ function(qt_config_compile_test name) set(CMAKE_C_STANDARD "${_save_CMAKE_C_STANDARD}") set(CMAKE_CXX_STANDARD "${_save_CMAKE_CXX_STANDARD}") set(CMAKE_REQUIRED_FLAGS "${_save_CMAKE_REQUIRED_FLAGS}") + set(CMAKE_TRY_COMPILE_PLATFORM_VARIABLES "${_save_CMAKE_TRY_COMPILE_PLATFORM_VARIABLES}") endif() endif() @@ -980,6 +994,11 @@ function(qt_get_platform_try_compile_vars out_var) endif() endforeach() + # Let CMake load our custom platform modules. + if(NOT QT_AVOID_CUSTOM_PLATFORM_MODULES) + list(APPEND flags_cmd_line "-DCMAKE_MODULE_PATH:STRING=${QT_CMAKE_DIR}/platforms") + endif() + # Pass darwin specific options. # The architectures need to be passed explicitly to project-based try_compile calls even on # macOS, so that arm64 compilation works on Apple silicon. diff --git a/cmake/platforms/Platform/Integrity.cmake b/cmake/platforms/Platform/Integrity.cmake new file mode 100644 index 0000000000..964a01fc2f --- /dev/null +++ b/cmake/platforms/Platform/Integrity.cmake @@ -0,0 +1,8 @@ +# Custom platform module file for INTEGRITY. +# +# UNIX must be set here, because this variable is cleared after the toolchain file is loaded. +# +# Once the lowest CMake version we support ships an Integrity platform module, +# we can remove this file. + +set(UNIX 1) diff --git a/cmake/qt.toolchain.cmake.in b/cmake/qt.toolchain.cmake.in index 38a7431620..79a37fd95a 100644 --- a/cmake/qt.toolchain.cmake.in +++ b/cmake/qt.toolchain.cmake.in @@ -70,6 +70,12 @@ get_filename_component(QT_TOOLCHAIN_RELOCATABLE_CMAKE_DIR "${CMAKE_CURRENT_LIST_ list(PREPEND CMAKE_PREFIX_PATH "${QT_TOOLCHAIN_RELOCATABLE_CMAKE_DIR}") list(PREPEND CMAKE_FIND_ROOT_PATH "${QT_TOOLCHAIN_RELOCATABLE_INSTALL_PREFIX}") +# Let CMake load our custom platform modules. +# CMake-provided platform modules take precedence. +if(NOT QT_AVOID_CUSTOM_PLATFORM_MODULES) + list(PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/platforms") +endif() + # Handle packages located in QT_ADDITIONAL_PACKAGES_PREFIX_PATH when cross-compiling. Needed for # Conan. # We prepend to CMAKE_PREFIX_PATH so that a find_package(Qt6Foo) call works, without having to go |