Skip to content

Commit

Permalink
CMake: Ensure that UNIX is set for INTEGRITY
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
jobor committed Oct 5, 2021
1 parent 719990d commit 165e01d
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 1 deletion.
6 changes: 6 additions & 0 deletions cmake/QtAutoDetect.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions cmake/QtBaseGlobalTargets.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 20 additions & 1 deletion cmake/QtFeature.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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}")
Expand All @@ -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})
Expand All @@ -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()

Expand Down Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions cmake/platforms/Platform/Integrity.cmake
Original file line number Diff line number Diff line change
@@ -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)
6 changes: 6 additions & 0 deletions cmake/qt.toolchain.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 165e01d

Please sign in to comment.