CMake: Rework the module JSON files

The linked issue reports a lack of information about multi-arch builds
of Qt on Apple platforms. In order to add the information we take the
chance to rework the structure of the module JSON files and make the
format future-proof for when we'll create multi-platform
bundles (xcframeworks).

The new module JSON files differ from the old ones in the following
points:

- The 'schema_version' key denotes the version of the module JSON file
schema. It's set to 2.

- The 'built_with' key was removed. The relevant information was moved
to 'platforms' entries.

- The 'cross_compiled' key was removed. It was only used to determine
whether a Qt build contained host tools. Since one needs the actual path
to host tools anyway, it's more useful to query qtpaths for that
information.

- A 'platforms' key was added that holds a list of target platforms.
Currently, only an iOS simulator-and-device build has more than one
platform:
    "name": "iOS",
    "variant": "iphoneos",
and
    "name": "iOS",
    "variant": "iphonesimulator",

- A 'targets' key was added under each 'platforms' entry. This contains
information about the target architecture(s) and other relevant
properties.

- The 'android' key was flattened and moved to the 'targets' entries.

[ChangeLog][CMake] The structure of the module JSON files, e.g.
modules/Core.json has been reworked. Consumers of these files need to be
updated. A 'schema_version' key was added and set to 2 to ease reading
different versions of these files.

Fixes: QTBUG-129996
Change-Id: I5a6ac9746aa19ad0ee9f2d020bf7486bdac28226
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Joerg Bornemann 2024-11-06 14:35:25 +01:00
parent abc888c75b
commit 6f25a583a6
2 changed files with 94 additions and 26 deletions

View File

@ -1,13 +1,8 @@
{
"schema_version": 2,
"name": "${target}",
"repository": "${lower_case_project_name}",
"version": "${PROJECT_VERSION}",${extra_module_information}
"built_with": {${extra_build_information}
"compiler_id": "${CMAKE_CXX_COMPILER_ID}",
"compiler_target": "${CMAKE_CXX_COMPILER_TARGET}",
"compiler_version": "${CMAKE_CXX_COMPILER_VERSION}",
"cross_compiled": ${cross_compilation},
"target_system": "${CMAKE_SYSTEM_NAME}",
"architecture": "${TEST_architecture_arch}"
}
"platforms": [${platforms_information}
]
}

View File

@ -1233,11 +1233,8 @@ function(qt_describe_module target)
set(descfile_in "${QT_CMAKE_DIR}/ModuleDescription.json.in")
set(descfile_out "${build_dir}/${target}.json")
string(TOLOWER "${PROJECT_NAME}" lower_case_project_name)
set(cross_compilation "false")
if(CMAKE_CROSSCOMPILING)
set(cross_compilation "true")
endif()
set(extra_module_information "")
set(platforms_information "")
get_target_property(target_type ${target} TYPE)
if(NOT target_type STREQUAL "INTERFACE_LIBRARY")
@ -1248,27 +1245,103 @@ function(qt_describe_module target)
endif()
endif()
# Generate extra module information
get_target_property(is_internal ${target} _qt_is_internal_module)
if(is_internal)
string(APPEND extra_module_information "\n \"internal\": true,")
endif()
set(extra_build_information "")
if(APPLE)
set(bundle_type "none")
if(QT_FEATURE_framework)
set(bundle_type "framework")
endif()
string(APPEND extra_module_information "\n \"bundle_type\": \"framework\",")
endif()
if(NOT QT_NAMESPACE STREQUAL "")
string(APPEND extra_build_information "
\"namespace\": \"${QT_NAMESPACE}\",")
string(APPEND extra_module_information "\n \"namespace\": \"${QT_NAMESPACE}\",")
endif()
if(ANDROID)
string(APPEND extra_build_information "
\"android\": {
\"api_version\": \"${QT_ANDROID_API_USED_FOR_JAVA}\",
\"ndk\": {
\"version\": \"${ANDROID_NDK_REVISION}\"
}
},")
endif()
configure_file("${descfile_in}" "${descfile_out}")
# Set up indentation helper variables.
set(indent1 " ")
set(k 1)
foreach(i RANGE 2 5)
set(indent${i} "${indent${k}}${indent1}")
set(k ${i})
endforeach()
# Set up the platforms to write.
set(nr_of_platforms 1)
set(platform_0_name "${CMAKE_SYSTEM_NAME}")
set(platform_0_variant "")
set(platform_0_architectures "${TEST_architecture_architectures}")
# Handle iOS builds specially.
if(platform_0_name STREQUAL "iOS")
if(QT_FEATURE_simulator_and_device)
# This must match the setup done in qt_auto_detect_apple.
set(nr_of_platforms 2)
set(platform_0_name "iOS")
set(platform_0_variant "iphoneos")
set(platform_0_architectures "arm64")
set(platform_1_name "iOS")
set(platform_1_variant "iphonesimulator")
set(platform_1_architectures "x86_64")
elseif(NOT "${QT_APPLE_SDK}" STREQUAL "")
# Explicit SDK requested.
set(platform_0_variant "${QT_APPLE_SDK}")
endif()
endif()
# Write platform information. At the moment, we write exactly one platform. With xcframeworks
# for example, we'd support multiple platforms.
math(EXPR last_platform_idx "${nr_of_platforms} - 1")
foreach(i RANGE 0 ${last_platform_idx})
# Write target architecture information.
set(platform_name "${platform_${i}_name}")
set(platform_variant "${platform_${i}_variant}")
set(platform_architectures "${platform_${i}_architectures}")
set(targets_information "")
foreach(architecture IN LISTS platform_architectures)
if(NOT targets_information STREQUAL "")
string(APPEND targets_information ",")
endif()
string(APPEND targets_information "\n${indent4}{\n")
if(NOT QT_FEATURE_shared)
string(APPEND targets_information "${indent5}\"static\": true,\n")
endif()
if(ANDROID)
string(APPEND targets_information
"${indent5}\"api_version\": \"${QT_ANDROID_API_USED_FOR_JAVA}\",
${indent5}\"ndk_version\": \"${ANDROID_NDK_REVISION}\",\n")
endif()
string(APPEND targets_information "${indent5}\"architecture\": \"${architecture}\",\n")
string(APPEND targets_information "${indent5}\"abi\": \"${TEST_arch_${architecture}_abi}\"\n")
string(APPEND targets_information "${indent4}}")
endforeach()
if(i GREATER 0)
string(APPEND platforms_information ",")
endif()
string(APPEND platforms_information "
${indent2}{
${indent3}\"name\": \"${platform_name}\",")
if(NOT platform_variant STREQUAL "")
string(APPEND platforms_information "
${indent3}\"variant\": \"${platform_variant}\",")
endif()
if(NOT "${CMAKE_SYSTEM_VERSION}" STREQUAL "")
string(APPEND platforms_information "
${indent3}\"version\": \"${CMAKE_SYSTEM_VERSION}\",")
endif()
string(APPEND platforms_information "
${indent3}\"compiler_id\": \"${CMAKE_CXX_COMPILER_ID}\",
${indent3}\"compiler_version\": \"${CMAKE_CXX_COMPILER_VERSION}\",
${indent3}\"targets\": [${targets_information}
${indent3}]
${indent2}}")
endforeach()
configure_file("${descfile_in}" "${descfile_out}")
qt_install(FILES "${descfile_out}" DESTINATION "${install_dir}")
endfunction()