CMake: Store architecture information about all platforms

...in a multi-architecture build on macOS.

Our "architecture" configure test only retrieved and stored information
about the first architecture, even if CMAKE_OSX_ARCHITECTURES contained
multiple values.

Now, we run that configure test once for every entry in
CMAKE_OSX_ARCHITECTURES, extract the information from the test binary,
and store
- a list of architectures,
- a list of subarchitectures per architecture,
- the build ABI per architecture.

For example, for a build of Qt with CMAKE_OSX_ARCHITECTURES=x86_64;arm64
we now set the following cache variables.

For the first architecture:
    TEST_architecture_arch=x86_64
    TEST_subarch_result=cx16;sse3;ssse3;sse4.1

The list of architectures:
    TEST_architecture_architectures=x86_64;arm64

Sub-architectures and ABI per architecture:
    TEST_arch_arm64_abi=arm64-little_endian-lp64
    TEST_arch_arm64_subarch_crc32=1
    TEST_arch_arm64_subarch_crypto=1
    TEST_arch_arm64_subarch_neon=1
    TEST_arch_x86_64_abi=x86_64-little_endian-lp64
    TEST_arch_x86_64_subarch_cx16=1
    TEST_arch_x86_64_subarch_sse3=1
    TEST_arch_x86_64_subarch_sse4.1=1
    TEST_arch_x86_64_subarch_ssse3=1

This is mainly done to provide all ABIs in our module JSON files but
hopefully comes in handy in other situations as well.

Change-Id: Idacd82fc87523657b8bb6ec0c0424f2361572dce
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Joerg Bornemann 2024-11-07 11:12:46 +01:00
parent b11aaf066e
commit abc888c75b

View File

@ -3,27 +3,41 @@
include(CheckCXXSourceCompiles)
function(qt_run_config_test_architecture)
set(QT_BASE_CONFIGURE_TESTS_VARS_TO_EXPORT
"" CACHE INTERNAL "Test variables that should be exported" FORCE)
# Compile test to find the target architecture and sub-architectures.
set(flags "")
qt_get_platform_try_compile_vars(platform_try_compile_vars)
list(APPEND flags ${platform_try_compile_vars})
function(qt_internal_run_config_test_architecture)
set(no_value_options "")
set(single_value_options
FLAVOR
OUT_VAR_ARCH
OUT_VAR_ABI
OUT_VAR_SUBARCH
)
set(multi_value_options
CMAKE_FLAGS
)
cmake_parse_arguments(PARSE_ARGV 0 arg
"${no_value_options}" "${single_value_options}" "${multi_value_options}"
)
set(flags "${arg_CMAKE_FLAGS}")
list(TRANSFORM flags PREPEND " " OUTPUT_VARIABLE flags_indented)
list(JOIN flags_indented "\n" flags_indented)
set(project_label "")
set(binary_dir_suffix "")
if(DEFINED arg_FLAVOR)
set(project_label " (${arg_FLAVOR})")
set(binary_dir_suffix "-${arg_FLAVOR}")
endif()
message(STATUS
"Building architecture extraction project with the following CMake arguments:")
"Building architecture extraction project${project_label} with the following CMake arguments:")
list(POP_BACK CMAKE_MESSAGE_CONTEXT _context)
message(STATUS ${flags_indented})
list(APPEND CMAKE_MESSAGE_CONTEXT ${_context})
try_compile(
_arch_result
"${CMAKE_CURRENT_BINARY_DIR}/config.tests/arch"
"${CMAKE_CURRENT_BINARY_DIR}/config.tests/arch${binary_dir_suffix}"
"${CMAKE_CURRENT_SOURCE_DIR}/config.tests/arch"
arch
CMAKE_FLAGS ${flags}
@ -43,7 +57,7 @@ function(qt_run_config_test_architecture)
set(_arch_file_suffix ".wasm")
endif()
set(arch_test_location "config.tests/arch")
set(arch_test_location "config.tests/arch${binary_dir_suffix}")
if(QT_MULTI_CONFIG_FIRST_CONFIG)
string(APPEND arch_test_location "/${QT_MULTI_CONFIG_FIRST_CONFIG}")
endif()
@ -70,6 +84,7 @@ function(qt_run_config_test_architecture)
REGEX "==Qt=magic=Qt==")
cmake_policy(POP)
set(architectures "")
foreach (_line ${_arch_lines})
string(LENGTH "${_line}" lineLength)
string(FIND "${_line}" "==Qt=magic=Qt== Architecture:" _pos)
@ -99,16 +114,74 @@ function(qt_run_config_test_architecture)
Here are the first few lines extracted:\n${arch_lines_output}")
endif()
set("${arg_OUT_VAR_ARCH}" "${_architecture}" PARENT_SCOPE)
set("${arg_OUT_VAR_SUBARCH}" "${_sub_architecture}" PARENT_SCOPE)
set("${arg_OUT_VAR_ABI}" "${_build_abi}" PARENT_SCOPE)
endfunction()
function(qt_run_config_test_architecture)
set(QT_BASE_CONFIGURE_TESTS_VARS_TO_EXPORT
"" CACHE INTERNAL "Test variables that should be exported" FORCE)
# Compile test to find the target architecture and sub-architectures.
qt_get_platform_try_compile_vars(platform_try_compile_vars)
list(APPEND flags ${platform_try_compile_vars})
set(first_arch "")
set(architectures "")
if("${CMAKE_OSX_ARCHITECTURES}" STREQUAL "")
qt_internal_run_config_test_architecture(
CMAKE_FLAGS ${flags}
OUT_VAR_ARCH arch
OUT_VAR_SUBARCH subarch
OUT_VAR_ABI abi
)
set(first_arch "${arch}")
set(architectures "${arch}")
set(sub_architecture_${arch} "${subarch}")
set(build_abi_${arch} "${abi}")
else()
list(FILTER flags EXCLUDE REGEX "^-DCMAKE_OSX_ARCHITECTURES[:=]")
foreach(osxarch IN LISTS CMAKE_OSX_ARCHITECTURES)
set(local_flags ${flags})
if(CMAKE_SYSTEM_NAME STREQUAL "iOS")
if(osxarch STREQUAL "x86_64")
list(APPEND local_flags "-DCMAKE_OSX_SYSROOT=iphonesimulator")
endif()
endif()
qt_internal_run_config_test_architecture(
FLAVOR "${osxarch}"
CMAKE_FLAGS ${local_flags} -DCMAKE_OSX_ARCHITECTURES=${osxarch}
OUT_VAR_ARCH arch
OUT_VAR_SUBARCH subarch
OUT_VAR_ABI abi
)
if(first_arch STREQUAL "")
set(first_arch "${arch}")
endif()
list(APPEND architectures "${arch}")
set(sub_architecture_${arch} "${subarch}")
set(build_abi_${arch} "${abi}")
endforeach()
endif()
set(TEST_architecture 1 CACHE INTERNAL "Ran the architecture test")
set(TEST_architecture_arch "${_architecture}" CACHE INTERNAL "Target machine architecture")
list(GET architectures 0 first_arch)
set(TEST_architecture_arch "${first_arch}" CACHE INTERNAL "Target machine architecture")
list(APPEND QT_BASE_CONFIGURE_TESTS_VARS_TO_EXPORT TEST_architecture_arch)
set(TEST_architecture_architectures "${architectures}" CACHE INTERNAL "Target machine architectures")
list(APPEND QT_BASE_CONFIGURE_TESTS_VARS_TO_EXPORT TEST_architecture_architectures)
set(TEST_subarch 1 CACHE INTERNAL "Ran machine subArchitecture test")
set(TEST_subarch_result "${_sub_architecture}" CACHE INTERNAL "Target sub-architectures")
set(TEST_subarch_result "${sub_architecture_${first_arch}}" CACHE INTERNAL "Target sub-architectures")
list(APPEND QT_BASE_CONFIGURE_TESTS_VARS_TO_EXPORT TEST_subarch_result)
foreach(it ${_sub_architecture})
# Equivalent to qmake's QT_CPU_FEATURES.$arch.
set(TEST_arch_${TEST_architecture_arch}_subarch_${it} 1 CACHE INTERNAL "Target sub architecture result")
list(APPEND QT_BASE_CONFIGURE_TESTS_VARS_TO_EXPORT TEST_arch_${TEST_architecture_arch}_subarch_${it})
foreach(arch IN LISTS architectures)
# Extended version of qmake's QT_CPU_FEATURES.$arch.
set(TEST_arch_${arch}_abi "${build_abi_${arch}}" CACHE INTERNAL "Target architecture ABI")
list(APPEND QT_BASE_CONFIGURE_TESTS_VARS_TO_EXPORT TEST_arch_${arch}_abi)
foreach(it IN LISTS sub_architecture_${arch})
set(TEST_arch_${arch}_subarch_${it} 1 CACHE INTERNAL "Target sub architecture result")
list(APPEND QT_BASE_CONFIGURE_TESTS_VARS_TO_EXPORT TEST_arch_${arch}_subarch_${it})
endforeach()
endforeach()
set(TEST_buildAbi "${_build_abi}" CACHE INTERNAL "Target machine buildAbi")
list(APPEND QT_BASE_CONFIGURE_TESTS_VARS_TO_EXPORT TEST_buildAbi)