2022-07-05 11:26:52 +00:00
|
|
|
# Copyright (C) 2022 The Qt Company Ltd.
|
2022-08-19 13:21:34 +00:00
|
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
2022-07-05 11:26:52 +00:00
|
|
|
|
2020-08-13 15:37:47 +00:00
|
|
|
# This function can be used to add sources/libraries/etc. to the specified CMake target
|
|
|
|
# if the provided CONDITION evaluates to true.
|
2022-10-14 12:38:23 +00:00
|
|
|
# One-value Arguments:
|
|
|
|
# PRECOMPILED_HEADER
|
|
|
|
# Name of the precompiled header that is used for the target.
|
2025-08-12 05:56:45 +00:00
|
|
|
# EXTRA_ELF_LINKER_SCRIPT_CONTENT
|
|
|
|
# Extra content that should be appended to a target linker script. Applicable for ld only.
|
2025-08-07 02:12:26 +00:00
|
|
|
# ELF_LINKER_DYNAMIC_LIST
|
|
|
|
# Pass --dynamic-list to the linker.
|
2022-10-14 12:38:23 +00:00
|
|
|
# Multi-value Arguments:
|
|
|
|
# CONDITION
|
|
|
|
# The condition under which the target will be extended.
|
2022-11-03 15:38:51 +00:00
|
|
|
# CONDITION_INDEPENDENT_SOURCES
|
|
|
|
# Source files that should be added to the target unconditionally. Note that if target is Qt
|
|
|
|
# module, these files will raise a warning at configure time if the condition is not met.
|
2022-10-14 12:38:23 +00:00
|
|
|
# COMPILE_FLAGS
|
|
|
|
# Custom compilation flags.
|
2025-08-12 05:50:55 +00:00
|
|
|
# EXTRA_ELF_LINKER_SCRIPT_EXPORTS
|
2023-10-06 16:53:26 +00:00
|
|
|
# Extra content that should be added to export section of the linker script.
|
2022-10-14 12:38:23 +00:00
|
|
|
# NO_PCH_SOURCES
|
2024-02-07 02:18:54 +00:00
|
|
|
# Exclude the specified source files from PRECOMPILE_HEADERS and UNITY_BUILD builds.
|
2020-09-22 08:02:27 +00:00
|
|
|
function(qt_internal_extend_target target)
|
2022-07-12 16:15:24 +00:00
|
|
|
if(NOT TARGET "${target}")
|
2023-01-02 18:19:44 +00:00
|
|
|
message(FATAL_ERROR "${target} is not a target.")
|
|
|
|
endif()
|
2023-01-03 13:42:33 +00:00
|
|
|
qt_internal_is_skipped_test(skipped ${target})
|
|
|
|
if(skipped)
|
|
|
|
return()
|
|
|
|
endif()
|
2023-01-02 18:19:44 +00:00
|
|
|
qt_internal_is_in_test_batch(in_batch ${target})
|
|
|
|
if(in_batch)
|
2022-08-24 07:28:37 +00:00
|
|
|
_qt_internal_test_batch_target_name(target)
|
2022-07-12 16:15:24 +00:00
|
|
|
endif()
|
|
|
|
|
2020-08-13 15:37:47 +00:00
|
|
|
# Don't try to extend_target when cross compiling an imported host target (like a tool).
|
|
|
|
qt_is_imported_target("${target}" is_imported)
|
|
|
|
if(is_imported)
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
2023-01-31 13:05:16 +00:00
|
|
|
set(option_args
|
|
|
|
NO_UNITY_BUILD
|
2024-06-14 17:07:16 +00:00
|
|
|
${__qt_internal_sbom_optional_args}
|
2023-01-31 13:05:16 +00:00
|
|
|
)
|
2022-10-14 12:38:23 +00:00
|
|
|
set(single_args
|
|
|
|
PRECOMPILED_HEADER
|
2025-08-12 05:50:55 +00:00
|
|
|
EXTRA_ELF_LINKER_SCRIPT_CONTENT
|
2025-08-07 02:12:26 +00:00
|
|
|
ELF_LINKER_DYNAMIC_LIST
|
2024-06-14 17:07:16 +00:00
|
|
|
${__qt_internal_sbom_single_args}
|
2022-10-14 12:38:23 +00:00
|
|
|
)
|
|
|
|
set(multi_args
|
|
|
|
${__default_public_args}
|
|
|
|
${__default_private_args}
|
|
|
|
${__default_private_module_args}
|
|
|
|
CONDITION
|
2022-11-03 15:38:51 +00:00
|
|
|
CONDITION_INDEPENDENT_SOURCES
|
2022-10-14 12:38:23 +00:00
|
|
|
COMPILE_FLAGS
|
2025-08-12 05:50:55 +00:00
|
|
|
EXTRA_ELF_LINKER_SCRIPT_EXPORTS
|
2024-06-14 17:07:16 +00:00
|
|
|
${__qt_internal_sbom_multi_args}
|
2022-10-14 12:38:23 +00:00
|
|
|
)
|
|
|
|
|
2023-01-11 14:36:18 +00:00
|
|
|
cmake_parse_arguments(PARSE_ARGV 1 arg
|
2022-10-14 12:38:23 +00:00
|
|
|
"${option_args}"
|
|
|
|
"${single_args}"
|
|
|
|
"${multi_args}"
|
|
|
|
)
|
2023-01-11 14:36:18 +00:00
|
|
|
_qt_internal_validate_all_args_are_parsed(arg)
|
2022-10-14 12:38:23 +00:00
|
|
|
|
|
|
|
if("x${arg_CONDITION}" STREQUAL "x")
|
2020-08-13 15:37:47 +00:00
|
|
|
set(arg_CONDITION ON)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
qt_evaluate_config_expression(result ${arg_CONDITION})
|
2022-10-14 12:38:23 +00:00
|
|
|
if(${result})
|
2020-08-13 15:37:47 +00:00
|
|
|
if(QT_CMAKE_DEBUG_EXTEND_TARGET)
|
|
|
|
message("qt_extend_target(${target} CONDITION ${arg_CONDITION} ...): Evaluated")
|
|
|
|
endif()
|
|
|
|
set(dbus_sources "")
|
|
|
|
foreach(adaptor ${arg_DBUS_ADAPTOR_SOURCES})
|
2024-11-08 13:26:32 +00:00
|
|
|
_qt_internal_forward_function_args(
|
|
|
|
FORWARD_PREFIX arg_DBUS_ADAPTOR
|
|
|
|
FORWARD_OUT_VAR forwarded_args
|
|
|
|
FORWARD_SINGLE
|
|
|
|
BASENAME
|
|
|
|
FLAGS
|
2022-10-14 12:38:23 +00:00
|
|
|
)
|
2024-11-08 13:26:32 +00:00
|
|
|
qt_create_qdbusxml2cpp_command("${target}" "${adaptor}" ADAPTOR ${forwarded_args})
|
2022-01-17 15:59:05 +00:00
|
|
|
list(APPEND dbus_sources "${adaptor}")
|
2020-08-13 15:37:47 +00:00
|
|
|
endforeach()
|
|
|
|
|
|
|
|
foreach(interface ${arg_DBUS_INTERFACE_SOURCES})
|
2024-11-08 13:26:32 +00:00
|
|
|
_qt_internal_forward_function_args(
|
|
|
|
FORWARD_PREFIX arg_DBUS_INTERFACE
|
|
|
|
FORWARD_OUT_VAR forwarded_args
|
|
|
|
FORWARD_SINGLE
|
|
|
|
BASENAME
|
|
|
|
FLAGS
|
2022-10-14 12:38:23 +00:00
|
|
|
)
|
2024-11-08 13:26:32 +00:00
|
|
|
qt_create_qdbusxml2cpp_command("${target}" "${interface}" INTERFACE ${forwarded_args})
|
2022-01-17 15:59:05 +00:00
|
|
|
list(APPEND dbus_sources "${interface}")
|
2020-08-13 15:37:47 +00:00
|
|
|
endforeach()
|
|
|
|
|
2022-10-14 16:00:24 +00:00
|
|
|
set(all_sources
|
|
|
|
${arg_SOURCES}
|
|
|
|
${dbus_sources}
|
|
|
|
)
|
|
|
|
|
2020-08-13 15:37:47 +00:00
|
|
|
get_target_property(target_type ${target} TYPE)
|
|
|
|
set(is_library FALSE)
|
2022-08-10 13:58:15 +00:00
|
|
|
set(is_interface_lib FALSE)
|
2024-03-27 17:55:40 +00:00
|
|
|
set(is_executable FALSE)
|
2022-10-14 12:38:23 +00:00
|
|
|
if(${target_type} STREQUAL "STATIC_LIBRARY" OR ${target_type} STREQUAL "SHARED_LIBRARY")
|
2020-08-13 15:37:47 +00:00
|
|
|
set(is_library TRUE)
|
2022-08-10 13:58:15 +00:00
|
|
|
elseif(target_type STREQUAL "INTERFACE_LIBRARY")
|
|
|
|
set(is_interface_lib TRUE)
|
2024-03-27 17:55:40 +00:00
|
|
|
elseif(target_type STREQUAL "EXECUTABLE")
|
|
|
|
set(is_executable TRUE)
|
2020-08-13 15:37:47 +00:00
|
|
|
endif()
|
2022-08-10 13:58:15 +00:00
|
|
|
|
2020-08-13 15:37:47 +00:00
|
|
|
foreach(lib ${arg_PUBLIC_LIBRARIES} ${arg_LIBRARIES})
|
2021-08-23 19:12:36 +00:00
|
|
|
# Automatically generate PCH for 'target' using public dependencies.
|
|
|
|
# But only if 'target' is a library/module that does not specify its own PCH file.
|
|
|
|
if(NOT arg_PRECOMPILED_HEADER AND ${is_library})
|
2020-08-13 15:37:47 +00:00
|
|
|
qt_update_precompiled_header_with_library("${target}" "${lib}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
string(REGEX REPLACE "_nolink$" "" base_lib "${lib}")
|
|
|
|
if(NOT base_lib STREQUAL lib)
|
|
|
|
qt_create_nolink_target("${base_lib}" ${target})
|
|
|
|
endif()
|
2023-05-25 17:32:12 +00:00
|
|
|
|
|
|
|
# Collect _sync_headers targets from libraries that the target depends on. This is
|
|
|
|
# heuristic way of building the dependency tree between the _sync_headers targets of
|
|
|
|
# different Qt modules.
|
|
|
|
if(TARGET "${lib}")
|
2024-01-17 06:40:48 +00:00
|
|
|
get_target_property(is_imported ${lib} IMPORTED)
|
|
|
|
if(NOT is_imported)
|
|
|
|
get_target_property(is_private ${lib} _qt_is_private_module)
|
|
|
|
if(is_private)
|
|
|
|
get_target_property(lib ${lib} _qt_public_module_target_name)
|
|
|
|
endif()
|
|
|
|
set(out_genex "$<TARGET_PROPERTY:${lib},_qt_internal_sync_headers_target>")
|
|
|
|
set_property(TARGET ${target}
|
|
|
|
APPEND PROPERTY _qt_internal_sync_headers_deps "${out_genex}")
|
2023-08-02 13:18:15 +00:00
|
|
|
endif()
|
2023-05-25 17:32:12 +00:00
|
|
|
endif()
|
2020-08-13 15:37:47 +00:00
|
|
|
endforeach()
|
|
|
|
|
2024-02-12 08:36:50 +00:00
|
|
|
list(TRANSFORM arg_PUBLIC_LIBRARIES REPLACE "^Qt::" "${QT_CMAKE_EXPORT_NAMESPACE}::")
|
|
|
|
list(TRANSFORM arg_LIBRARIES REPLACE "^Qt::" "${QT_CMAKE_EXPORT_NAMESPACE}::")
|
2025-01-03 16:19:22 +00:00
|
|
|
qt_internal_wrap_private_modules(arg_LIBRARIES ${arg_LIBRARIES})
|
2024-02-12 08:36:50 +00:00
|
|
|
|
2020-08-13 15:37:47 +00:00
|
|
|
# Set-up the target
|
2021-12-21 16:05:07 +00:00
|
|
|
|
|
|
|
# CMake versions less than 3.19 don't support adding the source files to the PRIVATE scope
|
|
|
|
# of the INTERFACE libraries. These PRIVATE sources are only needed by IDEs to display
|
|
|
|
# them in a project tree, so to avoid build issues and appearing the sources in
|
2022-08-10 15:21:18 +00:00
|
|
|
# INTERFACE_SOURCES property of INTERFACE_LIBRARY. Collect them inside the
|
|
|
|
# _qt_internal_target_sources property, since they can be useful in the source processing
|
|
|
|
# functions. The property itself is not exported and should only be used in the Qt internal
|
|
|
|
# build tree.
|
2022-08-10 13:58:15 +00:00
|
|
|
if(NOT is_interface_lib OR CMAKE_VERSION VERSION_GREATER_EQUAL "3.19")
|
2022-10-14 16:00:24 +00:00
|
|
|
target_sources("${target}" PRIVATE ${all_sources})
|
2022-10-14 12:38:23 +00:00
|
|
|
if(arg_COMPILE_FLAGS)
|
2022-10-14 16:00:24 +00:00
|
|
|
set_source_files_properties(${all_sources} PROPERTIES
|
2021-12-21 16:05:07 +00:00
|
|
|
COMPILE_FLAGS "${arg_COMPILE_FLAGS}")
|
|
|
|
endif()
|
2022-08-10 15:21:18 +00:00
|
|
|
else()
|
|
|
|
set_property(TARGET ${target} APPEND PROPERTY
|
2022-10-14 16:00:24 +00:00
|
|
|
_qt_internal_target_sources ${all_sources})
|
2020-08-13 15:37:47 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
set(public_visibility_option "PUBLIC")
|
|
|
|
set(private_visibility_option "PRIVATE")
|
2022-08-10 13:58:15 +00:00
|
|
|
if(is_interface_lib)
|
2020-08-13 15:37:47 +00:00
|
|
|
set(public_visibility_option "INTERFACE")
|
|
|
|
set(private_visibility_option "INTERFACE")
|
|
|
|
endif()
|
|
|
|
target_include_directories("${target}"
|
|
|
|
${public_visibility_option} ${arg_PUBLIC_INCLUDE_DIRECTORIES}
|
|
|
|
${private_visibility_option} ${arg_INCLUDE_DIRECTORIES})
|
2022-11-22 01:55:13 +00:00
|
|
|
target_include_directories("${target}" SYSTEM
|
|
|
|
${private_visibility_option} ${arg_SYSTEM_INCLUDE_DIRECTORIES})
|
2020-08-13 15:37:47 +00:00
|
|
|
target_compile_definitions("${target}"
|
|
|
|
${public_visibility_option} ${arg_PUBLIC_DEFINES}
|
|
|
|
${private_visibility_option} ${arg_DEFINES})
|
|
|
|
target_link_libraries("${target}"
|
|
|
|
${public_visibility_option} ${arg_PUBLIC_LIBRARIES}
|
|
|
|
${private_visibility_option} ${arg_LIBRARIES})
|
|
|
|
target_compile_options("${target}"
|
|
|
|
${public_visibility_option} ${arg_PUBLIC_COMPILE_OPTIONS}
|
|
|
|
${private_visibility_option} ${arg_COMPILE_OPTIONS})
|
|
|
|
target_link_options("${target}"
|
|
|
|
${public_visibility_option} ${arg_PUBLIC_LINK_OPTIONS}
|
|
|
|
${private_visibility_option} ${arg_LINK_OPTIONS})
|
|
|
|
|
2022-08-10 13:58:15 +00:00
|
|
|
if(NOT is_interface_lib)
|
2025-05-27 09:30:37 +00:00
|
|
|
_qt_internal_get_moc_compiler_flavor_flags(flavor_flags)
|
2022-10-14 12:38:23 +00:00
|
|
|
set_property(TARGET "${target}" APPEND PROPERTY
|
2025-05-27 09:30:37 +00:00
|
|
|
AUTOMOC_MOC_OPTIONS "${arg_MOC_OPTIONS}" ${flavor_flags}
|
2020-08-13 15:37:47 +00:00
|
|
|
)
|
2025-05-27 09:30:37 +00:00
|
|
|
|
2022-07-25 13:28:31 +00:00
|
|
|
# Plugin types associated to a module
|
|
|
|
if(NOT "x${arg_PLUGIN_TYPES}" STREQUAL "x")
|
|
|
|
qt_internal_add_plugin_types("${target}" "${arg_PLUGIN_TYPES}")
|
|
|
|
endif()
|
2020-08-13 15:37:47 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
# When computing the private library dependencies, we need to check not only the known
|
|
|
|
# modules added by this repo's qt_build_repo(), but also all module dependencies that
|
|
|
|
# were found via find_package().
|
|
|
|
qt_internal_get_qt_all_known_modules(known_modules)
|
|
|
|
|
|
|
|
# When a public module depends on a private module (Gui on CorePrivate)
|
|
|
|
# make its private module depend on the other private module (GuiPrivate will depend on
|
|
|
|
# CorePrivate).
|
|
|
|
set(qt_libs_private "")
|
|
|
|
foreach(it ${known_modules})
|
|
|
|
list(FIND arg_LIBRARIES "Qt::${it}Private" pos)
|
|
|
|
if(pos GREATER -1)
|
|
|
|
list(APPEND qt_libs_private "Qt::${it}Private")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
CMake: Generate an SPDX v2.3 SBOM file for each built repository
This change adds a new -sbom configure option to allow generating and
installing an SPDX v2.3 SBOM file when building a qt repo.
The -sbom-dir option can be used to configure the location where
each repo sbom file will be installed.
By default it is installed into
$prefix/$archdatadir/sbom/$sbom_lower_project_name.sdpx
which is basically ~/Qt/sbom/qtbase-6.8.0.spdx
The file is installed as part of the default installation rules, but
it can also be installed manually using the "sbom" installation
component, or "sbom_$lower_project_name" in a top-level build. For
example: cmake install . --component sbom_qtbase
CMake 3.19+ is needed to read the qt_attribution.json files for
copyrights, license info, etc. When using an older cmake version,
configuration will error out. It is possible to opt into using an
older cmake version, but the generated sbom will lack all the
attribution file information.
Using an older cmake version is untested and not officially supported.
Implementation notes.
The bulk of the implementation is split into 4 new files:
- QtPublicSbomHelpers.cmake - for Qt-specific collecting, processing
and dispatching the generation of various pieces of the SBOM document
e.g. a SDPX package associated with a target like Core, a SDPX
file entry for each target binary file (per-config shared library,
archive, executable, etc)
- QtPublicSbomGenerationHelpers.cmake - for non-Qt specific
implementation of SPDX generation. This also has some code that was
taken from the cmake-sbom 3rd party project, so it is dual licensed
under the usual Qt build system BSD license, as well as the MIT
license of the 3rd party project
- QtPublicGitHelpers.cmake - for git related features, mainly to embed
queried hashes or tags into version strings, is dual-licensed for
the same reasons as QtPublicSbomGenerationHelpers.cmake
- QtSbomHelpers.cmake - Qt-specific functions that just forward
arguments to the public functions. These are meant to be used in our
Qt CMakeLists.txt instead of the public _qt_internal_add_sbom ones
for naming consistency. These function would mostly be used to
annotate 3rd party libraries with sbom info and to add sbom info
for unusual target setups (like the Bootstrap library), because most
of the handling is already done automatically via
qt_internal_add_module/plugin/etc.
The files are put into Public cmake files, with the future hope of
making this available to user projects in some capacity.
The distinction of Qt-specific and non-Qt specific code might blur a
bit, and thus the separation across files might not always be
consistent, but it was best effort.
The main purpose of the code is to collect various information about
targets and their relationships and generate equivalent SPDX info.
Collection is currently done for the following targets: Qt modules,
plugins, apps, tools, system libraries, bundled 3rd party libraries
and partial 3rd party sources compiled directly as part of Qt targets.
Each target has an equivalent SPDX package generated with information
like version, license, copyright, CPE (common vulnerability
identifier), files that belong to the package, and relationships on
other SPDX packages (associated cmake targets), mostly gathered from
direct linking dependencies.
Each package might also contain files, e.g. libQt6Core.so for the Core
target. Each file also has info like license id, copyrights, but also
the list of source files that were used to generate the file and a
sha1 checksum.
SPDX documents can also refer to packages in other SPDX documents, and
those are referred to via external document references. This is the
case when building qtdeclarative and we refer to Core.
For qt provided targets, we have complete information regarding
licenses, and copyrights.
For bundled 3rd party libraries, we should also have most information,
which is usually parsed from the
src/3rdparty/libfoo/qt_attribution.json files.
If there are multiple attribution files, or if the files have multiple
entries, we create a separate SBOM package for each of those entries,
because each might have a separate copyright or version, and an sbom
package can have only one version (although many copyrights).
For system libraries we usually lack the information because we don't
have attribution files for Find scripts. So the info needs to be
manually annotated via arguments to the sbom function calls, or the
FindFoo.cmake scripts expose that information in some form and we
can query it.
There are also corner cases like 3rdparty sources being directly
included in a Qt library, like the m4dc files for Gui, or PCRE2 for
Bootstrap.
Or QtWebEngine libraries (either Qt bundled or Chromium bundled or
system libraries) which get linked in by GN instead of CMake, so there
are no direct targets for them.
The information for these need to be annotated manually as well.
There is also a distinction to be made for static Qt builds (or any
static Qt library in a shared build), where the system libraries found
during the Qt build might not be the same that are linked into the
final user application or library.
The actual generation of the SBOM is done by file(GENERATE)-ing one
.cmake file for each target, file, external ref, etc, which will be
included in a top-level cmake script.
The top-level cmake script will run through each included file, to
append to a "staging" spdx file, which will then be used in a
configure_file() call to replace some final
variables, like embedding a file checksum.
There are install rules to generate a complete SBOM during
installation, and an optional 'sbom' custom target that allows
building an incomplete SBOM during the build step.
The build target is just for convenience and faster development
iteration time. It is incomplete because it is missing the installed
file SHA1 checksums and the document verification code (the sha1 of
all sha1s). We can't compute those during the build before the files
are actually installed.
A complete SBOM can only be achieved at installation time. The install
script will include all the generated helper files, but also set some
additional variables to ensure checksumming happens, and also handle
multi-config installation, among other small things.
For multi-config builds, CMake doesn't offer a way to run code after
all configs are installed, because they might not always be installed,
someone might choose to install just Release.
To handle that, we rely on ninja installing each config sequentially
(because ninja places the install rules into the 'console' pool which
runs one task at a time).
For each installed config we create a config-specific marker file.
Once all marker files are present, whichever config ends up being
installed as the last one, we run the sbom generation once, and then
delete all marker files.
There are a few internal variables that can be set during
configuration to enable various checks (and other features) on the
generated spdx files:
- QT_INTERNAL_SBOM_VERIFY
- QT_INTERNAL_SBOM_AUDIT
- QT_INTERNAL_SBOM_AUDIT_NO_ERROR
- QT_INTERNAL_SBOM_GENERATE_JSON
- QT_INTERNAL_SBOM_SHOW_TABLE
- QT_INTERNAL_SBOM_DEFAULT_CHECKS
These use 3rd party python tools, so they are not enabled by default.
If enabled, they run at installation time after the sbom is installed.
We will hopefully enable them in CI.
Overall, the code is still a bit messy in a few places, due to time
constraints, but can be improved later.
Some possible TODOs for the future:
- Do we need to handle 3rd party libs linked into a Qt static library
in a Qt shared build, where the Qt static lib is not installed, but
linked into a Qt shared library, somehow specially?
We can record a package for it, but we can't
create a spdx file record for it (and associated source
relationships) because we don't install the file, and spdx requires
the file to be installed and checksummed. Perhaps we can consider
adding some free-form text snippet to the package itself?
- Do we want to add parsing of .cpp source files for Copyrights, to
embed them into the packages? This will likely slow down
configuration quite a bit.
- Currently sbom info attached to WrapFoo packages in one repo is
not exported / available in other repos. E.g. If we annotate
WrapZLIB in qtbase with CPE_VENDOR zlib, this info will not be
available when looking up WrapZLIB in qtimageformats.
This is because they are IMPORTED libraries, and are not
exported. We might want to record this info in the future.
[ChangeLog][Build System] A new -sbom configure option can be used
to generate and install a SPDX SBOM (Software Bill of Materials) file
for each built Qt repository.
Pick-to: 6.8
Task-number: QTBUG-122899
Change-Id: I9c730a6bbc47e02ce1836fccf00a14ec8eb1a5f4
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2024-03-07 17:02:56 +00:00
|
|
|
if(arg_LIBRARIES)
|
|
|
|
_qt_internal_append_to_target_property_without_duplicates(${target}
|
|
|
|
_qt_extend_target_libraries "${arg_LIBRARIES}"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(arg_PUBLIC_LIBRARIES)
|
|
|
|
_qt_internal_append_to_target_property_without_duplicates(${target}
|
|
|
|
_qt_extend_target_public_libraries "${arg_PUBLIC_LIBRARIES}"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2025-02-14 21:11:28 +00:00
|
|
|
set(all_libraries ${arg_LIBRARIES} ${arg_PUBLIC_LIBRARIES})
|
2025-06-27 12:22:00 +00:00
|
|
|
_qt_internal_work_around_autogen_discarded_dependencies(${target} ${all_libraries})
|
2025-02-14 21:11:28 +00:00
|
|
|
|
2024-06-14 17:07:16 +00:00
|
|
|
if(QT_GENERATE_SBOM)
|
|
|
|
set(sbom_args "")
|
|
|
|
_qt_internal_forward_function_args(
|
|
|
|
FORWARD_APPEND
|
|
|
|
FORWARD_PREFIX arg
|
|
|
|
FORWARD_OUT_VAR sbom_args
|
|
|
|
FORWARD_OPTIONS
|
|
|
|
${__qt_internal_sbom_optional_args}
|
|
|
|
FORWARD_SINGLE
|
|
|
|
${__qt_internal_sbom_single_args}
|
|
|
|
FORWARD_MULTI
|
|
|
|
${__qt_internal_sbom_multi_args}
|
CMake: Generate an SPDX v2.3 SBOM file for each built repository
This change adds a new -sbom configure option to allow generating and
installing an SPDX v2.3 SBOM file when building a qt repo.
The -sbom-dir option can be used to configure the location where
each repo sbom file will be installed.
By default it is installed into
$prefix/$archdatadir/sbom/$sbom_lower_project_name.sdpx
which is basically ~/Qt/sbom/qtbase-6.8.0.spdx
The file is installed as part of the default installation rules, but
it can also be installed manually using the "sbom" installation
component, or "sbom_$lower_project_name" in a top-level build. For
example: cmake install . --component sbom_qtbase
CMake 3.19+ is needed to read the qt_attribution.json files for
copyrights, license info, etc. When using an older cmake version,
configuration will error out. It is possible to opt into using an
older cmake version, but the generated sbom will lack all the
attribution file information.
Using an older cmake version is untested and not officially supported.
Implementation notes.
The bulk of the implementation is split into 4 new files:
- QtPublicSbomHelpers.cmake - for Qt-specific collecting, processing
and dispatching the generation of various pieces of the SBOM document
e.g. a SDPX package associated with a target like Core, a SDPX
file entry for each target binary file (per-config shared library,
archive, executable, etc)
- QtPublicSbomGenerationHelpers.cmake - for non-Qt specific
implementation of SPDX generation. This also has some code that was
taken from the cmake-sbom 3rd party project, so it is dual licensed
under the usual Qt build system BSD license, as well as the MIT
license of the 3rd party project
- QtPublicGitHelpers.cmake - for git related features, mainly to embed
queried hashes or tags into version strings, is dual-licensed for
the same reasons as QtPublicSbomGenerationHelpers.cmake
- QtSbomHelpers.cmake - Qt-specific functions that just forward
arguments to the public functions. These are meant to be used in our
Qt CMakeLists.txt instead of the public _qt_internal_add_sbom ones
for naming consistency. These function would mostly be used to
annotate 3rd party libraries with sbom info and to add sbom info
for unusual target setups (like the Bootstrap library), because most
of the handling is already done automatically via
qt_internal_add_module/plugin/etc.
The files are put into Public cmake files, with the future hope of
making this available to user projects in some capacity.
The distinction of Qt-specific and non-Qt specific code might blur a
bit, and thus the separation across files might not always be
consistent, but it was best effort.
The main purpose of the code is to collect various information about
targets and their relationships and generate equivalent SPDX info.
Collection is currently done for the following targets: Qt modules,
plugins, apps, tools, system libraries, bundled 3rd party libraries
and partial 3rd party sources compiled directly as part of Qt targets.
Each target has an equivalent SPDX package generated with information
like version, license, copyright, CPE (common vulnerability
identifier), files that belong to the package, and relationships on
other SPDX packages (associated cmake targets), mostly gathered from
direct linking dependencies.
Each package might also contain files, e.g. libQt6Core.so for the Core
target. Each file also has info like license id, copyrights, but also
the list of source files that were used to generate the file and a
sha1 checksum.
SPDX documents can also refer to packages in other SPDX documents, and
those are referred to via external document references. This is the
case when building qtdeclarative and we refer to Core.
For qt provided targets, we have complete information regarding
licenses, and copyrights.
For bundled 3rd party libraries, we should also have most information,
which is usually parsed from the
src/3rdparty/libfoo/qt_attribution.json files.
If there are multiple attribution files, or if the files have multiple
entries, we create a separate SBOM package for each of those entries,
because each might have a separate copyright or version, and an sbom
package can have only one version (although many copyrights).
For system libraries we usually lack the information because we don't
have attribution files for Find scripts. So the info needs to be
manually annotated via arguments to the sbom function calls, or the
FindFoo.cmake scripts expose that information in some form and we
can query it.
There are also corner cases like 3rdparty sources being directly
included in a Qt library, like the m4dc files for Gui, or PCRE2 for
Bootstrap.
Or QtWebEngine libraries (either Qt bundled or Chromium bundled or
system libraries) which get linked in by GN instead of CMake, so there
are no direct targets for them.
The information for these need to be annotated manually as well.
There is also a distinction to be made for static Qt builds (or any
static Qt library in a shared build), where the system libraries found
during the Qt build might not be the same that are linked into the
final user application or library.
The actual generation of the SBOM is done by file(GENERATE)-ing one
.cmake file for each target, file, external ref, etc, which will be
included in a top-level cmake script.
The top-level cmake script will run through each included file, to
append to a "staging" spdx file, which will then be used in a
configure_file() call to replace some final
variables, like embedding a file checksum.
There are install rules to generate a complete SBOM during
installation, and an optional 'sbom' custom target that allows
building an incomplete SBOM during the build step.
The build target is just for convenience and faster development
iteration time. It is incomplete because it is missing the installed
file SHA1 checksums and the document verification code (the sha1 of
all sha1s). We can't compute those during the build before the files
are actually installed.
A complete SBOM can only be achieved at installation time. The install
script will include all the generated helper files, but also set some
additional variables to ensure checksumming happens, and also handle
multi-config installation, among other small things.
For multi-config builds, CMake doesn't offer a way to run code after
all configs are installed, because they might not always be installed,
someone might choose to install just Release.
To handle that, we rely on ninja installing each config sequentially
(because ninja places the install rules into the 'console' pool which
runs one task at a time).
For each installed config we create a config-specific marker file.
Once all marker files are present, whichever config ends up being
installed as the last one, we run the sbom generation once, and then
delete all marker files.
There are a few internal variables that can be set during
configuration to enable various checks (and other features) on the
generated spdx files:
- QT_INTERNAL_SBOM_VERIFY
- QT_INTERNAL_SBOM_AUDIT
- QT_INTERNAL_SBOM_AUDIT_NO_ERROR
- QT_INTERNAL_SBOM_GENERATE_JSON
- QT_INTERNAL_SBOM_SHOW_TABLE
- QT_INTERNAL_SBOM_DEFAULT_CHECKS
These use 3rd party python tools, so they are not enabled by default.
If enabled, they run at installation time after the sbom is installed.
We will hopefully enable them in CI.
Overall, the code is still a bit messy in a few places, due to time
constraints, but can be improved later.
Some possible TODOs for the future:
- Do we need to handle 3rd party libs linked into a Qt static library
in a Qt shared build, where the Qt static lib is not installed, but
linked into a Qt shared library, somehow specially?
We can record a package for it, but we can't
create a spdx file record for it (and associated source
relationships) because we don't install the file, and spdx requires
the file to be installed and checksummed. Perhaps we can consider
adding some free-form text snippet to the package itself?
- Do we want to add parsing of .cpp source files for Copyrights, to
embed them into the packages? This will likely slow down
configuration quite a bit.
- Currently sbom info attached to WrapFoo packages in one repo is
not exported / available in other repos. E.g. If we annotate
WrapZLIB in qtbase with CPE_VENDOR zlib, this info will not be
available when looking up WrapZLIB in qtimageformats.
This is because they are IMPORTED libraries, and are not
exported. We might want to record this info in the future.
[ChangeLog][Build System] A new -sbom configure option can be used
to generate and install a SPDX SBOM (Software Bill of Materials) file
for each built Qt repository.
Pick-to: 6.8
Task-number: QTBUG-122899
Change-Id: I9c730a6bbc47e02ce1836fccf00a14ec8eb1a5f4
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2024-03-07 17:02:56 +00:00
|
|
|
)
|
2024-06-14 17:07:16 +00:00
|
|
|
_qt_internal_extend_sbom(${target} ${sbom_args})
|
CMake: Generate an SPDX v2.3 SBOM file for each built repository
This change adds a new -sbom configure option to allow generating and
installing an SPDX v2.3 SBOM file when building a qt repo.
The -sbom-dir option can be used to configure the location where
each repo sbom file will be installed.
By default it is installed into
$prefix/$archdatadir/sbom/$sbom_lower_project_name.sdpx
which is basically ~/Qt/sbom/qtbase-6.8.0.spdx
The file is installed as part of the default installation rules, but
it can also be installed manually using the "sbom" installation
component, or "sbom_$lower_project_name" in a top-level build. For
example: cmake install . --component sbom_qtbase
CMake 3.19+ is needed to read the qt_attribution.json files for
copyrights, license info, etc. When using an older cmake version,
configuration will error out. It is possible to opt into using an
older cmake version, but the generated sbom will lack all the
attribution file information.
Using an older cmake version is untested and not officially supported.
Implementation notes.
The bulk of the implementation is split into 4 new files:
- QtPublicSbomHelpers.cmake - for Qt-specific collecting, processing
and dispatching the generation of various pieces of the SBOM document
e.g. a SDPX package associated with a target like Core, a SDPX
file entry for each target binary file (per-config shared library,
archive, executable, etc)
- QtPublicSbomGenerationHelpers.cmake - for non-Qt specific
implementation of SPDX generation. This also has some code that was
taken from the cmake-sbom 3rd party project, so it is dual licensed
under the usual Qt build system BSD license, as well as the MIT
license of the 3rd party project
- QtPublicGitHelpers.cmake - for git related features, mainly to embed
queried hashes or tags into version strings, is dual-licensed for
the same reasons as QtPublicSbomGenerationHelpers.cmake
- QtSbomHelpers.cmake - Qt-specific functions that just forward
arguments to the public functions. These are meant to be used in our
Qt CMakeLists.txt instead of the public _qt_internal_add_sbom ones
for naming consistency. These function would mostly be used to
annotate 3rd party libraries with sbom info and to add sbom info
for unusual target setups (like the Bootstrap library), because most
of the handling is already done automatically via
qt_internal_add_module/plugin/etc.
The files are put into Public cmake files, with the future hope of
making this available to user projects in some capacity.
The distinction of Qt-specific and non-Qt specific code might blur a
bit, and thus the separation across files might not always be
consistent, but it was best effort.
The main purpose of the code is to collect various information about
targets and their relationships and generate equivalent SPDX info.
Collection is currently done for the following targets: Qt modules,
plugins, apps, tools, system libraries, bundled 3rd party libraries
and partial 3rd party sources compiled directly as part of Qt targets.
Each target has an equivalent SPDX package generated with information
like version, license, copyright, CPE (common vulnerability
identifier), files that belong to the package, and relationships on
other SPDX packages (associated cmake targets), mostly gathered from
direct linking dependencies.
Each package might also contain files, e.g. libQt6Core.so for the Core
target. Each file also has info like license id, copyrights, but also
the list of source files that were used to generate the file and a
sha1 checksum.
SPDX documents can also refer to packages in other SPDX documents, and
those are referred to via external document references. This is the
case when building qtdeclarative and we refer to Core.
For qt provided targets, we have complete information regarding
licenses, and copyrights.
For bundled 3rd party libraries, we should also have most information,
which is usually parsed from the
src/3rdparty/libfoo/qt_attribution.json files.
If there are multiple attribution files, or if the files have multiple
entries, we create a separate SBOM package for each of those entries,
because each might have a separate copyright or version, and an sbom
package can have only one version (although many copyrights).
For system libraries we usually lack the information because we don't
have attribution files for Find scripts. So the info needs to be
manually annotated via arguments to the sbom function calls, or the
FindFoo.cmake scripts expose that information in some form and we
can query it.
There are also corner cases like 3rdparty sources being directly
included in a Qt library, like the m4dc files for Gui, or PCRE2 for
Bootstrap.
Or QtWebEngine libraries (either Qt bundled or Chromium bundled or
system libraries) which get linked in by GN instead of CMake, so there
are no direct targets for them.
The information for these need to be annotated manually as well.
There is also a distinction to be made for static Qt builds (or any
static Qt library in a shared build), where the system libraries found
during the Qt build might not be the same that are linked into the
final user application or library.
The actual generation of the SBOM is done by file(GENERATE)-ing one
.cmake file for each target, file, external ref, etc, which will be
included in a top-level cmake script.
The top-level cmake script will run through each included file, to
append to a "staging" spdx file, which will then be used in a
configure_file() call to replace some final
variables, like embedding a file checksum.
There are install rules to generate a complete SBOM during
installation, and an optional 'sbom' custom target that allows
building an incomplete SBOM during the build step.
The build target is just for convenience and faster development
iteration time. It is incomplete because it is missing the installed
file SHA1 checksums and the document verification code (the sha1 of
all sha1s). We can't compute those during the build before the files
are actually installed.
A complete SBOM can only be achieved at installation time. The install
script will include all the generated helper files, but also set some
additional variables to ensure checksumming happens, and also handle
multi-config installation, among other small things.
For multi-config builds, CMake doesn't offer a way to run code after
all configs are installed, because they might not always be installed,
someone might choose to install just Release.
To handle that, we rely on ninja installing each config sequentially
(because ninja places the install rules into the 'console' pool which
runs one task at a time).
For each installed config we create a config-specific marker file.
Once all marker files are present, whichever config ends up being
installed as the last one, we run the sbom generation once, and then
delete all marker files.
There are a few internal variables that can be set during
configuration to enable various checks (and other features) on the
generated spdx files:
- QT_INTERNAL_SBOM_VERIFY
- QT_INTERNAL_SBOM_AUDIT
- QT_INTERNAL_SBOM_AUDIT_NO_ERROR
- QT_INTERNAL_SBOM_GENERATE_JSON
- QT_INTERNAL_SBOM_SHOW_TABLE
- QT_INTERNAL_SBOM_DEFAULT_CHECKS
These use 3rd party python tools, so they are not enabled by default.
If enabled, they run at installation time after the sbom is installed.
We will hopefully enable them in CI.
Overall, the code is still a bit messy in a few places, due to time
constraints, but can be improved later.
Some possible TODOs for the future:
- Do we need to handle 3rd party libs linked into a Qt static library
in a Qt shared build, where the Qt static lib is not installed, but
linked into a Qt shared library, somehow specially?
We can record a package for it, but we can't
create a spdx file record for it (and associated source
relationships) because we don't install the file, and spdx requires
the file to be installed and checksummed. Perhaps we can consider
adding some free-form text snippet to the package itself?
- Do we want to add parsing of .cpp source files for Copyrights, to
embed them into the packages? This will likely slow down
configuration quite a bit.
- Currently sbom info attached to WrapFoo packages in one repo is
not exported / available in other repos. E.g. If we annotate
WrapZLIB in qtbase with CPE_VENDOR zlib, this info will not be
available when looking up WrapZLIB in qtimageformats.
This is because they are IMPORTED libraries, and are not
exported. We might want to record this info in the future.
[ChangeLog][Build System] A new -sbom configure option can be used
to generate and install a SPDX SBOM (Software Bill of Materials) file
for each built Qt repository.
Pick-to: 6.8
Task-number: QTBUG-122899
Change-Id: I9c730a6bbc47e02ce1836fccf00a14ec8eb1a5f4
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2024-03-07 17:02:56 +00:00
|
|
|
endif()
|
|
|
|
|
2020-08-13 15:37:47 +00:00
|
|
|
set(target_private "${target}Private")
|
2021-08-24 11:30:51 +00:00
|
|
|
get_target_property(is_internal_module ${target} _qt_is_internal_module)
|
|
|
|
# Internal modules don't have Private targets but we still need to
|
|
|
|
# propagate their private dependencies.
|
|
|
|
if(is_internal_module)
|
|
|
|
set(target_private "${target}")
|
|
|
|
endif()
|
2020-08-13 15:37:47 +00:00
|
|
|
if(TARGET "${target_private}")
|
2021-08-23 18:47:05 +00:00
|
|
|
target_link_libraries("${target_private}"
|
|
|
|
INTERFACE ${arg_PRIVATE_MODULE_INTERFACE})
|
2025-01-03 16:19:22 +00:00
|
|
|
qt_internal_register_target_dependencies("${target_private}"
|
|
|
|
PUBLIC ${arg_PRIVATE_MODULE_INTERFACE}
|
|
|
|
)
|
2021-08-23 18:47:05 +00:00
|
|
|
elseif(arg_PRIVATE_MODULE_INTERFACE)
|
|
|
|
set(warning_message "")
|
|
|
|
string(APPEND warning_message
|
|
|
|
"The PRIVATE_MODULE_INTERFACE option was provided the values:"
|
|
|
|
"'${arg_PRIVATE_MODULE_INTERFACE}' "
|
|
|
|
"but there is no ${target}Private target to assign them to."
|
|
|
|
"Ensure the target exists or remove the option.")
|
|
|
|
message(AUTHOR_WARNING "${warning_message}")
|
2020-08-13 15:37:47 +00:00
|
|
|
endif()
|
|
|
|
|
2025-01-07 16:51:30 +00:00
|
|
|
set(qt_register_target_dependencies_args "")
|
2025-01-03 16:19:22 +00:00
|
|
|
if(arg_PUBLIC_LIBRARIES)
|
2025-01-07 16:51:30 +00:00
|
|
|
list(APPEND qt_register_target_dependencies_args
|
2025-01-03 16:19:22 +00:00
|
|
|
PUBLIC ${arg_PUBLIC_LIBRARIES})
|
2025-01-07 16:51:30 +00:00
|
|
|
endif()
|
|
|
|
if(qt_libs_private OR arg_LIBRARIES)
|
|
|
|
list(APPEND qt_register_target_dependencies_args
|
|
|
|
PRIVATE ${qt_libs_private} ${arg_LIBRARIES})
|
|
|
|
endif()
|
|
|
|
qt_internal_register_target_dependencies("${target}"
|
|
|
|
${qt_register_target_dependencies_args})
|
2020-08-13 15:37:47 +00:00
|
|
|
|
|
|
|
qt_autogen_tools(${target}
|
|
|
|
ENABLE_AUTOGEN_TOOLS ${arg_ENABLE_AUTOGEN_TOOLS}
|
|
|
|
DISABLE_AUTOGEN_TOOLS ${arg_DISABLE_AUTOGEN_TOOLS})
|
|
|
|
|
|
|
|
qt_update_precompiled_header("${target}" "${arg_PRECOMPILED_HEADER}")
|
2023-03-09 13:53:14 +00:00
|
|
|
## Also exclude them from unity build
|
2020-08-13 15:37:47 +00:00
|
|
|
qt_update_ignore_pch_source("${target}" "${arg_NO_PCH_SOURCES}")
|
|
|
|
## Ignore objective-c files for PCH (not supported atm)
|
|
|
|
qt_ignore_pch_obj_c_sources("${target}" "${arg_SOURCES}")
|
|
|
|
|
2023-03-09 13:53:14 +00:00
|
|
|
if(arg_NO_UNITY_BUILD)
|
|
|
|
set_target_properties("${target}" PROPERTIES UNITY_BUILD OFF)
|
|
|
|
qt_update_ignore_unity_build_sources("${target}" "${arg_SOURCES}")
|
|
|
|
endif()
|
2023-03-15 09:46:22 +00:00
|
|
|
if(arg_NO_UNITY_BUILD_SOURCES)
|
|
|
|
qt_update_ignore_unity_build_sources("${target}" "${arg_NO_UNITY_BUILD_SOURCES}")
|
|
|
|
endif()
|
2020-08-13 15:37:47 +00:00
|
|
|
else()
|
|
|
|
if(QT_CMAKE_DEBUG_EXTEND_TARGET)
|
|
|
|
message("qt_extend_target(${target} CONDITION ${arg_CONDITION} ...): Skipped")
|
|
|
|
endif()
|
|
|
|
endif()
|
2022-11-03 15:38:51 +00:00
|
|
|
|
|
|
|
if(arg_CONDITION_INDEPENDENT_SOURCES)
|
|
|
|
set_source_files_properties(${arg_CONDITION_INDEPENDENT_SOURCES} PROPERTIES
|
|
|
|
_qt_extend_target_condition "${arg_CONDITION}"
|
|
|
|
SKIP_AUTOGEN TRUE
|
|
|
|
)
|
|
|
|
|
|
|
|
qt_internal_get_target_sources_property(sources_property)
|
|
|
|
set_property(TARGET ${target} APPEND PROPERTY
|
|
|
|
${sources_property} "${arg_CONDITION_INDEPENDENT_SOURCES}")
|
|
|
|
endif()
|
2023-01-31 13:05:16 +00:00
|
|
|
|
2025-08-12 05:50:55 +00:00
|
|
|
if(arg_EXTRA_ELF_LINKER_SCRIPT_CONTENT)
|
2023-02-25 18:10:06 +00:00
|
|
|
set_target_properties(${target} PROPERTIES
|
2025-08-12 05:50:55 +00:00
|
|
|
_qt_extra_elf_linker_script_content "${arg_EXTRA_ELF_LINKER_SCRIPT_CONTENT}")
|
2023-02-25 18:10:06 +00:00
|
|
|
endif()
|
2025-08-12 05:50:55 +00:00
|
|
|
if(arg_EXTRA_ELF_LINKER_SCRIPT_EXPORTS)
|
2023-10-06 16:53:26 +00:00
|
|
|
set_target_properties(${target} PROPERTIES
|
2025-08-12 05:50:55 +00:00
|
|
|
_qt_extra_elf_linker_script_exports "${arg_EXTRA_ELF_LINKER_SCRIPT_EXPORTS}")
|
2023-10-06 16:53:26 +00:00
|
|
|
endif()
|
2025-08-07 02:12:26 +00:00
|
|
|
if(arg_ELF_LINKER_DYNAMIC_LIST)
|
|
|
|
qt_internal_apply_dynamic_list_linker_flags(${target} "${arg_ELF_LINKER_DYNAMIC_LIST}")
|
|
|
|
endif()
|
2024-03-27 17:55:40 +00:00
|
|
|
|
|
|
|
if(is_executable)
|
2024-03-28 10:03:25 +00:00
|
|
|
# If linking against Gui, make sure to also build the default QPA plugin.
|
|
|
|
# This makes the experience of an initial Qt configuration to build and run one single
|
|
|
|
# test / executable nicer.
|
|
|
|
set(linked_libs ${arg_PUBLIC_LIBRARIES} ${arg_LIBRARIES})
|
|
|
|
if(linked_libs MATCHES "(^|;)(${QT_CMAKE_EXPORT_NAMESPACE}::|Qt::)?Gui($|;)" AND
|
|
|
|
TARGET qpa_default_plugins)
|
|
|
|
add_dependencies("${target}" qpa_default_plugins)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# For executables collect static plugins that these targets depend on.
|
|
|
|
qt_internal_import_plugins(${target} ${linked_libs})
|
2024-03-27 17:55:40 +00:00
|
|
|
endif()
|
2020-08-13 15:37:47 +00:00
|
|
|
endfunction()
|
|
|
|
|
2025-01-03 16:19:22 +00:00
|
|
|
# Takes an output variable and a list of libraries.
|
|
|
|
#
|
|
|
|
# Every library that is a private module is wrapped in $<BUILD_INTERFACE> or
|
|
|
|
# $<BUILD_LOCAL_INTERFACE> if CMake is new enough.
|
|
|
|
#
|
|
|
|
# This is necessary for static builds, because if Qt6Foo links to Qt6BarPrivate, this link
|
|
|
|
# dependency is purely internal. If we don't do this, CMake adds a target check for Qt6BarPrivate
|
|
|
|
# in Qt6FooTargets.cmake. This breaks if Qt6BarPrivate is not find_package'ed before.
|
|
|
|
function(qt_internal_wrap_private_modules out_var)
|
|
|
|
set(result "")
|
|
|
|
|
|
|
|
if(CMAKE_VERSION VERSION_LESS "3.26")
|
|
|
|
set(wrapper_genex "BUILD_INTERFACE")
|
|
|
|
else()
|
|
|
|
set(wrapper_genex "BUILD_LOCAL_INTERFACE")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
foreach(lib IN LISTS ARGN)
|
|
|
|
if(TARGET "${lib}")
|
|
|
|
get_target_property(lib_is_private_module ${lib} _qt_is_private_module)
|
|
|
|
if(lib_is_private_module)
|
|
|
|
# Add the public module as non-wrapped link dependency. This is necessary for
|
|
|
|
# targets that link only to the private module. Consumers of this target would then
|
|
|
|
# get a linker error about missing symbols from that Qt module.
|
|
|
|
get_target_property(lib_public_module_target ${lib} _qt_public_module_target_name)
|
|
|
|
list(APPEND result "${INSTALL_CMAKE_NAMESPACE}::${lib_public_module_target}")
|
|
|
|
|
|
|
|
# Wrap the private module in BUILD_LOCAL_INTERFACE.
|
|
|
|
set(lib "$<${wrapper_genex}:${lib}>")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
list(APPEND result "${lib}")
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
set("${out_var}" "${result}" PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
2023-11-15 17:08:15 +00:00
|
|
|
# Given CMAKE_CONFIG and ALL_CMAKE_CONFIGS, determines if a directory suffix needs to be appended
|
|
|
|
# to each destination, and sets the computed install target destination arguments in OUT_VAR.
|
|
|
|
# Defaults used for each of the destination types, and can be configured per destination type.
|
|
|
|
function(qt_get_install_target_default_args)
|
|
|
|
cmake_parse_arguments(PARSE_ARGV 0 arg
|
|
|
|
""
|
CMake: Generate an SPDX v2.3 SBOM file for each built repository
This change adds a new -sbom configure option to allow generating and
installing an SPDX v2.3 SBOM file when building a qt repo.
The -sbom-dir option can be used to configure the location where
each repo sbom file will be installed.
By default it is installed into
$prefix/$archdatadir/sbom/$sbom_lower_project_name.sdpx
which is basically ~/Qt/sbom/qtbase-6.8.0.spdx
The file is installed as part of the default installation rules, but
it can also be installed manually using the "sbom" installation
component, or "sbom_$lower_project_name" in a top-level build. For
example: cmake install . --component sbom_qtbase
CMake 3.19+ is needed to read the qt_attribution.json files for
copyrights, license info, etc. When using an older cmake version,
configuration will error out. It is possible to opt into using an
older cmake version, but the generated sbom will lack all the
attribution file information.
Using an older cmake version is untested and not officially supported.
Implementation notes.
The bulk of the implementation is split into 4 new files:
- QtPublicSbomHelpers.cmake - for Qt-specific collecting, processing
and dispatching the generation of various pieces of the SBOM document
e.g. a SDPX package associated with a target like Core, a SDPX
file entry for each target binary file (per-config shared library,
archive, executable, etc)
- QtPublicSbomGenerationHelpers.cmake - for non-Qt specific
implementation of SPDX generation. This also has some code that was
taken from the cmake-sbom 3rd party project, so it is dual licensed
under the usual Qt build system BSD license, as well as the MIT
license of the 3rd party project
- QtPublicGitHelpers.cmake - for git related features, mainly to embed
queried hashes or tags into version strings, is dual-licensed for
the same reasons as QtPublicSbomGenerationHelpers.cmake
- QtSbomHelpers.cmake - Qt-specific functions that just forward
arguments to the public functions. These are meant to be used in our
Qt CMakeLists.txt instead of the public _qt_internal_add_sbom ones
for naming consistency. These function would mostly be used to
annotate 3rd party libraries with sbom info and to add sbom info
for unusual target setups (like the Bootstrap library), because most
of the handling is already done automatically via
qt_internal_add_module/plugin/etc.
The files are put into Public cmake files, with the future hope of
making this available to user projects in some capacity.
The distinction of Qt-specific and non-Qt specific code might blur a
bit, and thus the separation across files might not always be
consistent, but it was best effort.
The main purpose of the code is to collect various information about
targets and their relationships and generate equivalent SPDX info.
Collection is currently done for the following targets: Qt modules,
plugins, apps, tools, system libraries, bundled 3rd party libraries
and partial 3rd party sources compiled directly as part of Qt targets.
Each target has an equivalent SPDX package generated with information
like version, license, copyright, CPE (common vulnerability
identifier), files that belong to the package, and relationships on
other SPDX packages (associated cmake targets), mostly gathered from
direct linking dependencies.
Each package might also contain files, e.g. libQt6Core.so for the Core
target. Each file also has info like license id, copyrights, but also
the list of source files that were used to generate the file and a
sha1 checksum.
SPDX documents can also refer to packages in other SPDX documents, and
those are referred to via external document references. This is the
case when building qtdeclarative and we refer to Core.
For qt provided targets, we have complete information regarding
licenses, and copyrights.
For bundled 3rd party libraries, we should also have most information,
which is usually parsed from the
src/3rdparty/libfoo/qt_attribution.json files.
If there are multiple attribution files, or if the files have multiple
entries, we create a separate SBOM package for each of those entries,
because each might have a separate copyright or version, and an sbom
package can have only one version (although many copyrights).
For system libraries we usually lack the information because we don't
have attribution files for Find scripts. So the info needs to be
manually annotated via arguments to the sbom function calls, or the
FindFoo.cmake scripts expose that information in some form and we
can query it.
There are also corner cases like 3rdparty sources being directly
included in a Qt library, like the m4dc files for Gui, or PCRE2 for
Bootstrap.
Or QtWebEngine libraries (either Qt bundled or Chromium bundled or
system libraries) which get linked in by GN instead of CMake, so there
are no direct targets for them.
The information for these need to be annotated manually as well.
There is also a distinction to be made for static Qt builds (or any
static Qt library in a shared build), where the system libraries found
during the Qt build might not be the same that are linked into the
final user application or library.
The actual generation of the SBOM is done by file(GENERATE)-ing one
.cmake file for each target, file, external ref, etc, which will be
included in a top-level cmake script.
The top-level cmake script will run through each included file, to
append to a "staging" spdx file, which will then be used in a
configure_file() call to replace some final
variables, like embedding a file checksum.
There are install rules to generate a complete SBOM during
installation, and an optional 'sbom' custom target that allows
building an incomplete SBOM during the build step.
The build target is just for convenience and faster development
iteration time. It is incomplete because it is missing the installed
file SHA1 checksums and the document verification code (the sha1 of
all sha1s). We can't compute those during the build before the files
are actually installed.
A complete SBOM can only be achieved at installation time. The install
script will include all the generated helper files, but also set some
additional variables to ensure checksumming happens, and also handle
multi-config installation, among other small things.
For multi-config builds, CMake doesn't offer a way to run code after
all configs are installed, because they might not always be installed,
someone might choose to install just Release.
To handle that, we rely on ninja installing each config sequentially
(because ninja places the install rules into the 'console' pool which
runs one task at a time).
For each installed config we create a config-specific marker file.
Once all marker files are present, whichever config ends up being
installed as the last one, we run the sbom generation once, and then
delete all marker files.
There are a few internal variables that can be set during
configuration to enable various checks (and other features) on the
generated spdx files:
- QT_INTERNAL_SBOM_VERIFY
- QT_INTERNAL_SBOM_AUDIT
- QT_INTERNAL_SBOM_AUDIT_NO_ERROR
- QT_INTERNAL_SBOM_GENERATE_JSON
- QT_INTERNAL_SBOM_SHOW_TABLE
- QT_INTERNAL_SBOM_DEFAULT_CHECKS
These use 3rd party python tools, so they are not enabled by default.
If enabled, they run at installation time after the sbom is installed.
We will hopefully enable them in CI.
Overall, the code is still a bit messy in a few places, due to time
constraints, but can be improved later.
Some possible TODOs for the future:
- Do we need to handle 3rd party libs linked into a Qt static library
in a Qt shared build, where the Qt static lib is not installed, but
linked into a Qt shared library, somehow specially?
We can record a package for it, but we can't
create a spdx file record for it (and associated source
relationships) because we don't install the file, and spdx requires
the file to be installed and checksummed. Perhaps we can consider
adding some free-form text snippet to the package itself?
- Do we want to add parsing of .cpp source files for Copyrights, to
embed them into the packages? This will likely slow down
configuration quite a bit.
- Currently sbom info attached to WrapFoo packages in one repo is
not exported / available in other repos. E.g. If we annotate
WrapZLIB in qtbase with CPE_VENDOR zlib, this info will not be
available when looking up WrapZLIB in qtimageformats.
This is because they are IMPORTED libraries, and are not
exported. We might want to record this info in the future.
[ChangeLog][Build System] A new -sbom configure option can be used
to generate and install a SPDX SBOM (Software Bill of Materials) file
for each built Qt repository.
Pick-to: 6.8
Task-number: QTBUG-122899
Change-Id: I9c730a6bbc47e02ce1836fccf00a14ec8eb1a5f4
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2024-03-07 17:02:56 +00:00
|
|
|
"OUT_VAR;OUT_VAR_RUNTIME;CMAKE_CONFIG;RUNTIME;LIBRARY;ARCHIVE;INCLUDES;BUNDLE"
|
2023-11-15 17:08:15 +00:00
|
|
|
"ALL_CMAKE_CONFIGS")
|
|
|
|
_qt_internal_validate_all_args_are_parsed(arg)
|
|
|
|
|
|
|
|
if(NOT arg_CMAKE_CONFIG)
|
|
|
|
message(FATAL_ERROR "No value given for CMAKE_CONFIG.")
|
|
|
|
endif()
|
|
|
|
if(NOT arg_ALL_CMAKE_CONFIGS)
|
|
|
|
message(FATAL_ERROR "No value given for ALL_CMAKE_CONFIGS.")
|
|
|
|
endif()
|
|
|
|
list(LENGTH arg_ALL_CMAKE_CONFIGS all_configs_count)
|
|
|
|
list(GET arg_ALL_CMAKE_CONFIGS 0 first_config)
|
|
|
|
|
|
|
|
set(suffix "")
|
|
|
|
if(all_configs_count GREATER 1 AND NOT arg_CMAKE_CONFIG STREQUAL first_config)
|
|
|
|
set(suffix "/${arg_CMAKE_CONFIG}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(runtime "${INSTALL_BINDIR}")
|
|
|
|
if(arg_RUNTIME)
|
|
|
|
set(runtime "${arg_RUNTIME}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(library "${INSTALL_LIBDIR}")
|
|
|
|
if(arg_LIBRARY)
|
|
|
|
set(library "${arg_LIBRARY}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(archive "${INSTALL_LIBDIR}")
|
|
|
|
if(arg_ARCHIVE)
|
|
|
|
set(archive "${arg_ARCHIVE}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(includes "${INSTALL_INCLUDEDIR}")
|
|
|
|
if(arg_INCLUDES)
|
|
|
|
set(includes "${arg_INCLUDES}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(bundle "${INSTALL_BINDIR}")
|
|
|
|
if(arg_BUNDLE)
|
|
|
|
set(bundle "${arg_BUNDLE}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(args
|
|
|
|
RUNTIME DESTINATION "${runtime}${suffix}"
|
|
|
|
LIBRARY DESTINATION "${library}${suffix}"
|
|
|
|
ARCHIVE DESTINATION "${archive}${suffix}" COMPONENT Devel
|
|
|
|
BUNDLE DESTINATION "${bundle}${suffix}"
|
|
|
|
INCLUDES DESTINATION "${includes}${suffix}")
|
|
|
|
set(${arg_OUT_VAR} "${args}" PARENT_SCOPE)
|
CMake: Generate an SPDX v2.3 SBOM file for each built repository
This change adds a new -sbom configure option to allow generating and
installing an SPDX v2.3 SBOM file when building a qt repo.
The -sbom-dir option can be used to configure the location where
each repo sbom file will be installed.
By default it is installed into
$prefix/$archdatadir/sbom/$sbom_lower_project_name.sdpx
which is basically ~/Qt/sbom/qtbase-6.8.0.spdx
The file is installed as part of the default installation rules, but
it can also be installed manually using the "sbom" installation
component, or "sbom_$lower_project_name" in a top-level build. For
example: cmake install . --component sbom_qtbase
CMake 3.19+ is needed to read the qt_attribution.json files for
copyrights, license info, etc. When using an older cmake version,
configuration will error out. It is possible to opt into using an
older cmake version, but the generated sbom will lack all the
attribution file information.
Using an older cmake version is untested and not officially supported.
Implementation notes.
The bulk of the implementation is split into 4 new files:
- QtPublicSbomHelpers.cmake - for Qt-specific collecting, processing
and dispatching the generation of various pieces of the SBOM document
e.g. a SDPX package associated with a target like Core, a SDPX
file entry for each target binary file (per-config shared library,
archive, executable, etc)
- QtPublicSbomGenerationHelpers.cmake - for non-Qt specific
implementation of SPDX generation. This also has some code that was
taken from the cmake-sbom 3rd party project, so it is dual licensed
under the usual Qt build system BSD license, as well as the MIT
license of the 3rd party project
- QtPublicGitHelpers.cmake - for git related features, mainly to embed
queried hashes or tags into version strings, is dual-licensed for
the same reasons as QtPublicSbomGenerationHelpers.cmake
- QtSbomHelpers.cmake - Qt-specific functions that just forward
arguments to the public functions. These are meant to be used in our
Qt CMakeLists.txt instead of the public _qt_internal_add_sbom ones
for naming consistency. These function would mostly be used to
annotate 3rd party libraries with sbom info and to add sbom info
for unusual target setups (like the Bootstrap library), because most
of the handling is already done automatically via
qt_internal_add_module/plugin/etc.
The files are put into Public cmake files, with the future hope of
making this available to user projects in some capacity.
The distinction of Qt-specific and non-Qt specific code might blur a
bit, and thus the separation across files might not always be
consistent, but it was best effort.
The main purpose of the code is to collect various information about
targets and their relationships and generate equivalent SPDX info.
Collection is currently done for the following targets: Qt modules,
plugins, apps, tools, system libraries, bundled 3rd party libraries
and partial 3rd party sources compiled directly as part of Qt targets.
Each target has an equivalent SPDX package generated with information
like version, license, copyright, CPE (common vulnerability
identifier), files that belong to the package, and relationships on
other SPDX packages (associated cmake targets), mostly gathered from
direct linking dependencies.
Each package might also contain files, e.g. libQt6Core.so for the Core
target. Each file also has info like license id, copyrights, but also
the list of source files that were used to generate the file and a
sha1 checksum.
SPDX documents can also refer to packages in other SPDX documents, and
those are referred to via external document references. This is the
case when building qtdeclarative and we refer to Core.
For qt provided targets, we have complete information regarding
licenses, and copyrights.
For bundled 3rd party libraries, we should also have most information,
which is usually parsed from the
src/3rdparty/libfoo/qt_attribution.json files.
If there are multiple attribution files, or if the files have multiple
entries, we create a separate SBOM package for each of those entries,
because each might have a separate copyright or version, and an sbom
package can have only one version (although many copyrights).
For system libraries we usually lack the information because we don't
have attribution files for Find scripts. So the info needs to be
manually annotated via arguments to the sbom function calls, or the
FindFoo.cmake scripts expose that information in some form and we
can query it.
There are also corner cases like 3rdparty sources being directly
included in a Qt library, like the m4dc files for Gui, or PCRE2 for
Bootstrap.
Or QtWebEngine libraries (either Qt bundled or Chromium bundled or
system libraries) which get linked in by GN instead of CMake, so there
are no direct targets for them.
The information for these need to be annotated manually as well.
There is also a distinction to be made for static Qt builds (or any
static Qt library in a shared build), where the system libraries found
during the Qt build might not be the same that are linked into the
final user application or library.
The actual generation of the SBOM is done by file(GENERATE)-ing one
.cmake file for each target, file, external ref, etc, which will be
included in a top-level cmake script.
The top-level cmake script will run through each included file, to
append to a "staging" spdx file, which will then be used in a
configure_file() call to replace some final
variables, like embedding a file checksum.
There are install rules to generate a complete SBOM during
installation, and an optional 'sbom' custom target that allows
building an incomplete SBOM during the build step.
The build target is just for convenience and faster development
iteration time. It is incomplete because it is missing the installed
file SHA1 checksums and the document verification code (the sha1 of
all sha1s). We can't compute those during the build before the files
are actually installed.
A complete SBOM can only be achieved at installation time. The install
script will include all the generated helper files, but also set some
additional variables to ensure checksumming happens, and also handle
multi-config installation, among other small things.
For multi-config builds, CMake doesn't offer a way to run code after
all configs are installed, because they might not always be installed,
someone might choose to install just Release.
To handle that, we rely on ninja installing each config sequentially
(because ninja places the install rules into the 'console' pool which
runs one task at a time).
For each installed config we create a config-specific marker file.
Once all marker files are present, whichever config ends up being
installed as the last one, we run the sbom generation once, and then
delete all marker files.
There are a few internal variables that can be set during
configuration to enable various checks (and other features) on the
generated spdx files:
- QT_INTERNAL_SBOM_VERIFY
- QT_INTERNAL_SBOM_AUDIT
- QT_INTERNAL_SBOM_AUDIT_NO_ERROR
- QT_INTERNAL_SBOM_GENERATE_JSON
- QT_INTERNAL_SBOM_SHOW_TABLE
- QT_INTERNAL_SBOM_DEFAULT_CHECKS
These use 3rd party python tools, so they are not enabled by default.
If enabled, they run at installation time after the sbom is installed.
We will hopefully enable them in CI.
Overall, the code is still a bit messy in a few places, due to time
constraints, but can be improved later.
Some possible TODOs for the future:
- Do we need to handle 3rd party libs linked into a Qt static library
in a Qt shared build, where the Qt static lib is not installed, but
linked into a Qt shared library, somehow specially?
We can record a package for it, but we can't
create a spdx file record for it (and associated source
relationships) because we don't install the file, and spdx requires
the file to be installed and checksummed. Perhaps we can consider
adding some free-form text snippet to the package itself?
- Do we want to add parsing of .cpp source files for Copyrights, to
embed them into the packages? This will likely slow down
configuration quite a bit.
- Currently sbom info attached to WrapFoo packages in one repo is
not exported / available in other repos. E.g. If we annotate
WrapZLIB in qtbase with CPE_VENDOR zlib, this info will not be
available when looking up WrapZLIB in qtimageformats.
This is because they are IMPORTED libraries, and are not
exported. We might want to record this info in the future.
[ChangeLog][Build System] A new -sbom configure option can be used
to generate and install a SPDX SBOM (Software Bill of Materials) file
for each built Qt repository.
Pick-to: 6.8
Task-number: QTBUG-122899
Change-Id: I9c730a6bbc47e02ce1836fccf00a14ec8eb1a5f4
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2024-03-07 17:02:56 +00:00
|
|
|
|
|
|
|
if(arg_OUT_VAR_RUNTIME)
|
|
|
|
set(args
|
|
|
|
"${runtime}${suffix}"
|
|
|
|
)
|
|
|
|
set(${arg_OUT_VAR_RUNTIME} "${args}" PARENT_SCOPE)
|
|
|
|
endif()
|
2023-11-15 17:08:15 +00:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
macro(qt_internal_setup_default_target_function_options)
|
|
|
|
set(__default_private_args
|
|
|
|
SOURCES
|
|
|
|
LIBRARIES
|
|
|
|
INCLUDE_DIRECTORIES
|
|
|
|
SYSTEM_INCLUDE_DIRECTORIES
|
|
|
|
DEFINES
|
|
|
|
DBUS_ADAPTOR_BASENAME
|
|
|
|
DBUS_ADAPTOR_FLAGS
|
|
|
|
DBUS_ADAPTOR_SOURCES
|
|
|
|
DBUS_INTERFACE_BASENAME
|
|
|
|
DBUS_INTERFACE_FLAGS
|
|
|
|
DBUS_INTERFACE_SOURCES
|
|
|
|
FEATURE_DEPENDENCIES
|
|
|
|
COMPILE_OPTIONS
|
|
|
|
LINK_OPTIONS
|
|
|
|
MOC_OPTIONS
|
|
|
|
DISABLE_AUTOGEN_TOOLS
|
|
|
|
ENABLE_AUTOGEN_TOOLS
|
|
|
|
PLUGIN_TYPES
|
|
|
|
NO_PCH_SOURCES
|
|
|
|
NO_UNITY_BUILD_SOURCES
|
|
|
|
)
|
|
|
|
set(__default_public_args
|
|
|
|
PUBLIC_LIBRARIES
|
|
|
|
PUBLIC_INCLUDE_DIRECTORIES
|
|
|
|
PUBLIC_DEFINES
|
|
|
|
PUBLIC_COMPILE_OPTIONS
|
|
|
|
PUBLIC_LINK_OPTIONS
|
|
|
|
)
|
|
|
|
set(__default_private_module_args
|
|
|
|
PRIVATE_MODULE_INTERFACE
|
|
|
|
)
|
|
|
|
set(__default_target_info_args
|
|
|
|
TARGET_VERSION
|
|
|
|
TARGET_PRODUCT
|
|
|
|
TARGET_DESCRIPTION
|
|
|
|
TARGET_COMPANY
|
|
|
|
TARGET_COPYRIGHT
|
|
|
|
)
|
|
|
|
|
2024-06-14 17:07:16 +00:00
|
|
|
_qt_internal_get_sbom_add_target_common_options(
|
|
|
|
__qt_internal_sbom_optional_args
|
|
|
|
__qt_internal_sbom_single_args
|
|
|
|
__qt_internal_sbom_multi_args
|
CMake: Generate an SPDX v2.3 SBOM file for each built repository
This change adds a new -sbom configure option to allow generating and
installing an SPDX v2.3 SBOM file when building a qt repo.
The -sbom-dir option can be used to configure the location where
each repo sbom file will be installed.
By default it is installed into
$prefix/$archdatadir/sbom/$sbom_lower_project_name.sdpx
which is basically ~/Qt/sbom/qtbase-6.8.0.spdx
The file is installed as part of the default installation rules, but
it can also be installed manually using the "sbom" installation
component, or "sbom_$lower_project_name" in a top-level build. For
example: cmake install . --component sbom_qtbase
CMake 3.19+ is needed to read the qt_attribution.json files for
copyrights, license info, etc. When using an older cmake version,
configuration will error out. It is possible to opt into using an
older cmake version, but the generated sbom will lack all the
attribution file information.
Using an older cmake version is untested and not officially supported.
Implementation notes.
The bulk of the implementation is split into 4 new files:
- QtPublicSbomHelpers.cmake - for Qt-specific collecting, processing
and dispatching the generation of various pieces of the SBOM document
e.g. a SDPX package associated with a target like Core, a SDPX
file entry for each target binary file (per-config shared library,
archive, executable, etc)
- QtPublicSbomGenerationHelpers.cmake - for non-Qt specific
implementation of SPDX generation. This also has some code that was
taken from the cmake-sbom 3rd party project, so it is dual licensed
under the usual Qt build system BSD license, as well as the MIT
license of the 3rd party project
- QtPublicGitHelpers.cmake - for git related features, mainly to embed
queried hashes or tags into version strings, is dual-licensed for
the same reasons as QtPublicSbomGenerationHelpers.cmake
- QtSbomHelpers.cmake - Qt-specific functions that just forward
arguments to the public functions. These are meant to be used in our
Qt CMakeLists.txt instead of the public _qt_internal_add_sbom ones
for naming consistency. These function would mostly be used to
annotate 3rd party libraries with sbom info and to add sbom info
for unusual target setups (like the Bootstrap library), because most
of the handling is already done automatically via
qt_internal_add_module/plugin/etc.
The files are put into Public cmake files, with the future hope of
making this available to user projects in some capacity.
The distinction of Qt-specific and non-Qt specific code might blur a
bit, and thus the separation across files might not always be
consistent, but it was best effort.
The main purpose of the code is to collect various information about
targets and their relationships and generate equivalent SPDX info.
Collection is currently done for the following targets: Qt modules,
plugins, apps, tools, system libraries, bundled 3rd party libraries
and partial 3rd party sources compiled directly as part of Qt targets.
Each target has an equivalent SPDX package generated with information
like version, license, copyright, CPE (common vulnerability
identifier), files that belong to the package, and relationships on
other SPDX packages (associated cmake targets), mostly gathered from
direct linking dependencies.
Each package might also contain files, e.g. libQt6Core.so for the Core
target. Each file also has info like license id, copyrights, but also
the list of source files that were used to generate the file and a
sha1 checksum.
SPDX documents can also refer to packages in other SPDX documents, and
those are referred to via external document references. This is the
case when building qtdeclarative and we refer to Core.
For qt provided targets, we have complete information regarding
licenses, and copyrights.
For bundled 3rd party libraries, we should also have most information,
which is usually parsed from the
src/3rdparty/libfoo/qt_attribution.json files.
If there are multiple attribution files, or if the files have multiple
entries, we create a separate SBOM package for each of those entries,
because each might have a separate copyright or version, and an sbom
package can have only one version (although many copyrights).
For system libraries we usually lack the information because we don't
have attribution files for Find scripts. So the info needs to be
manually annotated via arguments to the sbom function calls, or the
FindFoo.cmake scripts expose that information in some form and we
can query it.
There are also corner cases like 3rdparty sources being directly
included in a Qt library, like the m4dc files for Gui, or PCRE2 for
Bootstrap.
Or QtWebEngine libraries (either Qt bundled or Chromium bundled or
system libraries) which get linked in by GN instead of CMake, so there
are no direct targets for them.
The information for these need to be annotated manually as well.
There is also a distinction to be made for static Qt builds (or any
static Qt library in a shared build), where the system libraries found
during the Qt build might not be the same that are linked into the
final user application or library.
The actual generation of the SBOM is done by file(GENERATE)-ing one
.cmake file for each target, file, external ref, etc, which will be
included in a top-level cmake script.
The top-level cmake script will run through each included file, to
append to a "staging" spdx file, which will then be used in a
configure_file() call to replace some final
variables, like embedding a file checksum.
There are install rules to generate a complete SBOM during
installation, and an optional 'sbom' custom target that allows
building an incomplete SBOM during the build step.
The build target is just for convenience and faster development
iteration time. It is incomplete because it is missing the installed
file SHA1 checksums and the document verification code (the sha1 of
all sha1s). We can't compute those during the build before the files
are actually installed.
A complete SBOM can only be achieved at installation time. The install
script will include all the generated helper files, but also set some
additional variables to ensure checksumming happens, and also handle
multi-config installation, among other small things.
For multi-config builds, CMake doesn't offer a way to run code after
all configs are installed, because they might not always be installed,
someone might choose to install just Release.
To handle that, we rely on ninja installing each config sequentially
(because ninja places the install rules into the 'console' pool which
runs one task at a time).
For each installed config we create a config-specific marker file.
Once all marker files are present, whichever config ends up being
installed as the last one, we run the sbom generation once, and then
delete all marker files.
There are a few internal variables that can be set during
configuration to enable various checks (and other features) on the
generated spdx files:
- QT_INTERNAL_SBOM_VERIFY
- QT_INTERNAL_SBOM_AUDIT
- QT_INTERNAL_SBOM_AUDIT_NO_ERROR
- QT_INTERNAL_SBOM_GENERATE_JSON
- QT_INTERNAL_SBOM_SHOW_TABLE
- QT_INTERNAL_SBOM_DEFAULT_CHECKS
These use 3rd party python tools, so they are not enabled by default.
If enabled, they run at installation time after the sbom is installed.
We will hopefully enable them in CI.
Overall, the code is still a bit messy in a few places, due to time
constraints, but can be improved later.
Some possible TODOs for the future:
- Do we need to handle 3rd party libs linked into a Qt static library
in a Qt shared build, where the Qt static lib is not installed, but
linked into a Qt shared library, somehow specially?
We can record a package for it, but we can't
create a spdx file record for it (and associated source
relationships) because we don't install the file, and spdx requires
the file to be installed and checksummed. Perhaps we can consider
adding some free-form text snippet to the package itself?
- Do we want to add parsing of .cpp source files for Copyrights, to
embed them into the packages? This will likely slow down
configuration quite a bit.
- Currently sbom info attached to WrapFoo packages in one repo is
not exported / available in other repos. E.g. If we annotate
WrapZLIB in qtbase with CPE_VENDOR zlib, this info will not be
available when looking up WrapZLIB in qtimageformats.
This is because they are IMPORTED libraries, and are not
exported. We might want to record this info in the future.
[ChangeLog][Build System] A new -sbom configure option can be used
to generate and install a SPDX SBOM (Software Bill of Materials) file
for each built Qt repository.
Pick-to: 6.8
Task-number: QTBUG-122899
Change-Id: I9c730a6bbc47e02ce1836fccf00a14ec8eb1a5f4
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2024-03-07 17:02:56 +00:00
|
|
|
)
|
|
|
|
|
2023-11-15 17:08:15 +00:00
|
|
|
# Collection of arguments so they can be shared across qt_internal_add_executable
|
|
|
|
# and qt_internal_add_test_helper.
|
|
|
|
set(__qt_internal_add_executable_optional_args
|
|
|
|
GUI
|
|
|
|
NO_INSTALL
|
|
|
|
EXCEPTIONS
|
|
|
|
DELAY_RC
|
|
|
|
DELAY_TARGET_INFO
|
|
|
|
QT_APP
|
CMake:Android: add wrapper scripts to easily run apps
Create a script that allows running an app or a test easily similar
to running on host. This improves development workflow and time by
allowing quick runs without having to manually call the various adb
commands to launch, get a pid of the app and then print the logcat,
let alone passing parameters or environment variables.
For normal apps, the app package name is retrieved by the script, run
and live logcat is printed as long as the app is still running.
For tests, the script calls androidtestrunner, allowing test parameters
to be passed to the test.
For CI debugging, this would save quite a lot of hussle and frustration
trying to run or debug a test app.
One other benefit for this is enabling running Android tests from Qt
Creator's testlib plugin without big changes to Qt Creator to support
androidtestrunner explicitly.
Because file(GENERATE) would fail if called twice for the same file,
I use file(WRITE). This is used because at the time of calling the
target executable finalizer, we don't know if the target is a test
or not, so we rely on writing the script first as a normal target,
then call it if the target is a test where it overrides the script.
For this also, parameters passed to the runner or androidtestrunner
can't handle generator expressions.
[ChangeLog][CMake][Android] Add wrapper scripts to run Android apps and
tests with ease from the host.
Task-number: QTBUG-129889
Change-Id: I84e85ce2bbf6944c8aa20bdc2c2b6d7b956bc748
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2024-10-07 14:43:31 +00:00
|
|
|
QT_TEST
|
|
|
|
QT_MANUAL_TEST
|
2024-10-23 15:19:00 +00:00
|
|
|
QT_BENCHMARK_TEST
|
2023-11-15 17:08:15 +00:00
|
|
|
NO_UNITY_BUILD
|
2024-06-14 17:07:16 +00:00
|
|
|
${__qt_internal_sbom_optional_args}
|
2023-11-15 17:08:15 +00:00
|
|
|
)
|
|
|
|
set(__qt_internal_add_executable_single_args
|
|
|
|
CORE_LIBRARY
|
|
|
|
OUTPUT_DIRECTORY
|
|
|
|
INSTALL_DIRECTORY
|
|
|
|
VERSION
|
|
|
|
${__default_target_info_args}
|
CMake: Generate an SPDX v2.3 SBOM file for each built repository
This change adds a new -sbom configure option to allow generating and
installing an SPDX v2.3 SBOM file when building a qt repo.
The -sbom-dir option can be used to configure the location where
each repo sbom file will be installed.
By default it is installed into
$prefix/$archdatadir/sbom/$sbom_lower_project_name.sdpx
which is basically ~/Qt/sbom/qtbase-6.8.0.spdx
The file is installed as part of the default installation rules, but
it can also be installed manually using the "sbom" installation
component, or "sbom_$lower_project_name" in a top-level build. For
example: cmake install . --component sbom_qtbase
CMake 3.19+ is needed to read the qt_attribution.json files for
copyrights, license info, etc. When using an older cmake version,
configuration will error out. It is possible to opt into using an
older cmake version, but the generated sbom will lack all the
attribution file information.
Using an older cmake version is untested and not officially supported.
Implementation notes.
The bulk of the implementation is split into 4 new files:
- QtPublicSbomHelpers.cmake - for Qt-specific collecting, processing
and dispatching the generation of various pieces of the SBOM document
e.g. a SDPX package associated with a target like Core, a SDPX
file entry for each target binary file (per-config shared library,
archive, executable, etc)
- QtPublicSbomGenerationHelpers.cmake - for non-Qt specific
implementation of SPDX generation. This also has some code that was
taken from the cmake-sbom 3rd party project, so it is dual licensed
under the usual Qt build system BSD license, as well as the MIT
license of the 3rd party project
- QtPublicGitHelpers.cmake - for git related features, mainly to embed
queried hashes or tags into version strings, is dual-licensed for
the same reasons as QtPublicSbomGenerationHelpers.cmake
- QtSbomHelpers.cmake - Qt-specific functions that just forward
arguments to the public functions. These are meant to be used in our
Qt CMakeLists.txt instead of the public _qt_internal_add_sbom ones
for naming consistency. These function would mostly be used to
annotate 3rd party libraries with sbom info and to add sbom info
for unusual target setups (like the Bootstrap library), because most
of the handling is already done automatically via
qt_internal_add_module/plugin/etc.
The files are put into Public cmake files, with the future hope of
making this available to user projects in some capacity.
The distinction of Qt-specific and non-Qt specific code might blur a
bit, and thus the separation across files might not always be
consistent, but it was best effort.
The main purpose of the code is to collect various information about
targets and their relationships and generate equivalent SPDX info.
Collection is currently done for the following targets: Qt modules,
plugins, apps, tools, system libraries, bundled 3rd party libraries
and partial 3rd party sources compiled directly as part of Qt targets.
Each target has an equivalent SPDX package generated with information
like version, license, copyright, CPE (common vulnerability
identifier), files that belong to the package, and relationships on
other SPDX packages (associated cmake targets), mostly gathered from
direct linking dependencies.
Each package might also contain files, e.g. libQt6Core.so for the Core
target. Each file also has info like license id, copyrights, but also
the list of source files that were used to generate the file and a
sha1 checksum.
SPDX documents can also refer to packages in other SPDX documents, and
those are referred to via external document references. This is the
case when building qtdeclarative and we refer to Core.
For qt provided targets, we have complete information regarding
licenses, and copyrights.
For bundled 3rd party libraries, we should also have most information,
which is usually parsed from the
src/3rdparty/libfoo/qt_attribution.json files.
If there are multiple attribution files, or if the files have multiple
entries, we create a separate SBOM package for each of those entries,
because each might have a separate copyright or version, and an sbom
package can have only one version (although many copyrights).
For system libraries we usually lack the information because we don't
have attribution files for Find scripts. So the info needs to be
manually annotated via arguments to the sbom function calls, or the
FindFoo.cmake scripts expose that information in some form and we
can query it.
There are also corner cases like 3rdparty sources being directly
included in a Qt library, like the m4dc files for Gui, or PCRE2 for
Bootstrap.
Or QtWebEngine libraries (either Qt bundled or Chromium bundled or
system libraries) which get linked in by GN instead of CMake, so there
are no direct targets for them.
The information for these need to be annotated manually as well.
There is also a distinction to be made for static Qt builds (or any
static Qt library in a shared build), where the system libraries found
during the Qt build might not be the same that are linked into the
final user application or library.
The actual generation of the SBOM is done by file(GENERATE)-ing one
.cmake file for each target, file, external ref, etc, which will be
included in a top-level cmake script.
The top-level cmake script will run through each included file, to
append to a "staging" spdx file, which will then be used in a
configure_file() call to replace some final
variables, like embedding a file checksum.
There are install rules to generate a complete SBOM during
installation, and an optional 'sbom' custom target that allows
building an incomplete SBOM during the build step.
The build target is just for convenience and faster development
iteration time. It is incomplete because it is missing the installed
file SHA1 checksums and the document verification code (the sha1 of
all sha1s). We can't compute those during the build before the files
are actually installed.
A complete SBOM can only be achieved at installation time. The install
script will include all the generated helper files, but also set some
additional variables to ensure checksumming happens, and also handle
multi-config installation, among other small things.
For multi-config builds, CMake doesn't offer a way to run code after
all configs are installed, because they might not always be installed,
someone might choose to install just Release.
To handle that, we rely on ninja installing each config sequentially
(because ninja places the install rules into the 'console' pool which
runs one task at a time).
For each installed config we create a config-specific marker file.
Once all marker files are present, whichever config ends up being
installed as the last one, we run the sbom generation once, and then
delete all marker files.
There are a few internal variables that can be set during
configuration to enable various checks (and other features) on the
generated spdx files:
- QT_INTERNAL_SBOM_VERIFY
- QT_INTERNAL_SBOM_AUDIT
- QT_INTERNAL_SBOM_AUDIT_NO_ERROR
- QT_INTERNAL_SBOM_GENERATE_JSON
- QT_INTERNAL_SBOM_SHOW_TABLE
- QT_INTERNAL_SBOM_DEFAULT_CHECKS
These use 3rd party python tools, so they are not enabled by default.
If enabled, they run at installation time after the sbom is installed.
We will hopefully enable them in CI.
Overall, the code is still a bit messy in a few places, due to time
constraints, but can be improved later.
Some possible TODOs for the future:
- Do we need to handle 3rd party libs linked into a Qt static library
in a Qt shared build, where the Qt static lib is not installed, but
linked into a Qt shared library, somehow specially?
We can record a package for it, but we can't
create a spdx file record for it (and associated source
relationships) because we don't install the file, and spdx requires
the file to be installed and checksummed. Perhaps we can consider
adding some free-form text snippet to the package itself?
- Do we want to add parsing of .cpp source files for Copyrights, to
embed them into the packages? This will likely slow down
configuration quite a bit.
- Currently sbom info attached to WrapFoo packages in one repo is
not exported / available in other repos. E.g. If we annotate
WrapZLIB in qtbase with CPE_VENDOR zlib, this info will not be
available when looking up WrapZLIB in qtimageformats.
This is because they are IMPORTED libraries, and are not
exported. We might want to record this info in the future.
[ChangeLog][Build System] A new -sbom configure option can be used
to generate and install a SPDX SBOM (Software Bill of Materials) file
for each built Qt repository.
Pick-to: 6.8
Task-number: QTBUG-122899
Change-Id: I9c730a6bbc47e02ce1836fccf00a14ec8eb1a5f4
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2024-03-07 17:02:56 +00:00
|
|
|
${__qt_internal_sbom_single_args}
|
2023-11-15 17:08:15 +00:00
|
|
|
)
|
|
|
|
set(__qt_internal_add_executable_multi_args
|
|
|
|
${__default_private_args}
|
|
|
|
${__default_public_args}
|
CMake: Generate an SPDX v2.3 SBOM file for each built repository
This change adds a new -sbom configure option to allow generating and
installing an SPDX v2.3 SBOM file when building a qt repo.
The -sbom-dir option can be used to configure the location where
each repo sbom file will be installed.
By default it is installed into
$prefix/$archdatadir/sbom/$sbom_lower_project_name.sdpx
which is basically ~/Qt/sbom/qtbase-6.8.0.spdx
The file is installed as part of the default installation rules, but
it can also be installed manually using the "sbom" installation
component, or "sbom_$lower_project_name" in a top-level build. For
example: cmake install . --component sbom_qtbase
CMake 3.19+ is needed to read the qt_attribution.json files for
copyrights, license info, etc. When using an older cmake version,
configuration will error out. It is possible to opt into using an
older cmake version, but the generated sbom will lack all the
attribution file information.
Using an older cmake version is untested and not officially supported.
Implementation notes.
The bulk of the implementation is split into 4 new files:
- QtPublicSbomHelpers.cmake - for Qt-specific collecting, processing
and dispatching the generation of various pieces of the SBOM document
e.g. a SDPX package associated with a target like Core, a SDPX
file entry for each target binary file (per-config shared library,
archive, executable, etc)
- QtPublicSbomGenerationHelpers.cmake - for non-Qt specific
implementation of SPDX generation. This also has some code that was
taken from the cmake-sbom 3rd party project, so it is dual licensed
under the usual Qt build system BSD license, as well as the MIT
license of the 3rd party project
- QtPublicGitHelpers.cmake - for git related features, mainly to embed
queried hashes or tags into version strings, is dual-licensed for
the same reasons as QtPublicSbomGenerationHelpers.cmake
- QtSbomHelpers.cmake - Qt-specific functions that just forward
arguments to the public functions. These are meant to be used in our
Qt CMakeLists.txt instead of the public _qt_internal_add_sbom ones
for naming consistency. These function would mostly be used to
annotate 3rd party libraries with sbom info and to add sbom info
for unusual target setups (like the Bootstrap library), because most
of the handling is already done automatically via
qt_internal_add_module/plugin/etc.
The files are put into Public cmake files, with the future hope of
making this available to user projects in some capacity.
The distinction of Qt-specific and non-Qt specific code might blur a
bit, and thus the separation across files might not always be
consistent, but it was best effort.
The main purpose of the code is to collect various information about
targets and their relationships and generate equivalent SPDX info.
Collection is currently done for the following targets: Qt modules,
plugins, apps, tools, system libraries, bundled 3rd party libraries
and partial 3rd party sources compiled directly as part of Qt targets.
Each target has an equivalent SPDX package generated with information
like version, license, copyright, CPE (common vulnerability
identifier), files that belong to the package, and relationships on
other SPDX packages (associated cmake targets), mostly gathered from
direct linking dependencies.
Each package might also contain files, e.g. libQt6Core.so for the Core
target. Each file also has info like license id, copyrights, but also
the list of source files that were used to generate the file and a
sha1 checksum.
SPDX documents can also refer to packages in other SPDX documents, and
those are referred to via external document references. This is the
case when building qtdeclarative and we refer to Core.
For qt provided targets, we have complete information regarding
licenses, and copyrights.
For bundled 3rd party libraries, we should also have most information,
which is usually parsed from the
src/3rdparty/libfoo/qt_attribution.json files.
If there are multiple attribution files, or if the files have multiple
entries, we create a separate SBOM package for each of those entries,
because each might have a separate copyright or version, and an sbom
package can have only one version (although many copyrights).
For system libraries we usually lack the information because we don't
have attribution files for Find scripts. So the info needs to be
manually annotated via arguments to the sbom function calls, or the
FindFoo.cmake scripts expose that information in some form and we
can query it.
There are also corner cases like 3rdparty sources being directly
included in a Qt library, like the m4dc files for Gui, or PCRE2 for
Bootstrap.
Or QtWebEngine libraries (either Qt bundled or Chromium bundled or
system libraries) which get linked in by GN instead of CMake, so there
are no direct targets for them.
The information for these need to be annotated manually as well.
There is also a distinction to be made for static Qt builds (or any
static Qt library in a shared build), where the system libraries found
during the Qt build might not be the same that are linked into the
final user application or library.
The actual generation of the SBOM is done by file(GENERATE)-ing one
.cmake file for each target, file, external ref, etc, which will be
included in a top-level cmake script.
The top-level cmake script will run through each included file, to
append to a "staging" spdx file, which will then be used in a
configure_file() call to replace some final
variables, like embedding a file checksum.
There are install rules to generate a complete SBOM during
installation, and an optional 'sbom' custom target that allows
building an incomplete SBOM during the build step.
The build target is just for convenience and faster development
iteration time. It is incomplete because it is missing the installed
file SHA1 checksums and the document verification code (the sha1 of
all sha1s). We can't compute those during the build before the files
are actually installed.
A complete SBOM can only be achieved at installation time. The install
script will include all the generated helper files, but also set some
additional variables to ensure checksumming happens, and also handle
multi-config installation, among other small things.
For multi-config builds, CMake doesn't offer a way to run code after
all configs are installed, because they might not always be installed,
someone might choose to install just Release.
To handle that, we rely on ninja installing each config sequentially
(because ninja places the install rules into the 'console' pool which
runs one task at a time).
For each installed config we create a config-specific marker file.
Once all marker files are present, whichever config ends up being
installed as the last one, we run the sbom generation once, and then
delete all marker files.
There are a few internal variables that can be set during
configuration to enable various checks (and other features) on the
generated spdx files:
- QT_INTERNAL_SBOM_VERIFY
- QT_INTERNAL_SBOM_AUDIT
- QT_INTERNAL_SBOM_AUDIT_NO_ERROR
- QT_INTERNAL_SBOM_GENERATE_JSON
- QT_INTERNAL_SBOM_SHOW_TABLE
- QT_INTERNAL_SBOM_DEFAULT_CHECKS
These use 3rd party python tools, so they are not enabled by default.
If enabled, they run at installation time after the sbom is installed.
We will hopefully enable them in CI.
Overall, the code is still a bit messy in a few places, due to time
constraints, but can be improved later.
Some possible TODOs for the future:
- Do we need to handle 3rd party libs linked into a Qt static library
in a Qt shared build, where the Qt static lib is not installed, but
linked into a Qt shared library, somehow specially?
We can record a package for it, but we can't
create a spdx file record for it (and associated source
relationships) because we don't install the file, and spdx requires
the file to be installed and checksummed. Perhaps we can consider
adding some free-form text snippet to the package itself?
- Do we want to add parsing of .cpp source files for Copyrights, to
embed them into the packages? This will likely slow down
configuration quite a bit.
- Currently sbom info attached to WrapFoo packages in one repo is
not exported / available in other repos. E.g. If we annotate
WrapZLIB in qtbase with CPE_VENDOR zlib, this info will not be
available when looking up WrapZLIB in qtimageformats.
This is because they are IMPORTED libraries, and are not
exported. We might want to record this info in the future.
[ChangeLog][Build System] A new -sbom configure option can be used
to generate and install a SPDX SBOM (Software Bill of Materials) file
for each built Qt repository.
Pick-to: 6.8
Task-number: QTBUG-122899
Change-Id: I9c730a6bbc47e02ce1836fccf00a14ec8eb1a5f4
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2024-03-07 17:02:56 +00:00
|
|
|
${__qt_internal_sbom_multi_args}
|
2023-11-15 17:08:15 +00:00
|
|
|
)
|
|
|
|
endmacro()
|
|
|
|
|
2023-11-16 16:10:01 +00:00
|
|
|
# Append a config-specific postfix to library names to ensure distinct names
|
|
|
|
# in a multi-config build.
|
|
|
|
# e.g. lib/libQt6DBus_relwithdebinfo.6.3.0.dylib
|
|
|
|
# Don't apply the postfix to the first encountered release-like config, so we have at least one
|
|
|
|
# config without a postifx.
|
|
|
|
# If postfixes are set by user warn about potential issues.
|
|
|
|
function(qt_internal_setup_cmake_config_postfix)
|
|
|
|
# Collect configuration that require postfix in Qt library names.
|
|
|
|
if(QT_GENERATOR_IS_MULTI_CONFIG)
|
|
|
|
set(postfix_configurations ${CMAKE_CONFIGURATION_TYPES})
|
|
|
|
else()
|
|
|
|
set(postfix_configurations ${CMAKE_BUILD_TYPE})
|
|
|
|
|
|
|
|
# Set the default postfix to empty by default for single-config builds.
|
|
|
|
string(TOLOWER "${CMAKE_BUILD_TYPE}" build_type_lower)
|
|
|
|
set(default_cmake_${build_type_lower}_postfix "")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Override the generic debug postfixes above with custom debug postfixes (even in a single
|
|
|
|
# config build) to follow the conventions we had since Qt 5.
|
|
|
|
# e.g. lib/libQt6DBus_debug.6.3.0.dylib
|
|
|
|
if(WIN32)
|
|
|
|
if(MINGW)
|
|
|
|
# On MinGW we don't have "d" suffix for debug libraries like on Linux,
|
|
|
|
# unless we're building debug and release libraries in one go.
|
|
|
|
if(QT_GENERATOR_IS_MULTI_CONFIG)
|
|
|
|
set(default_cmake_debug_postfix "d")
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
set(default_cmake_debug_postfix "d")
|
|
|
|
endif()
|
|
|
|
elseif(APPLE)
|
2024-06-20 10:48:26 +00:00
|
|
|
# Only add a suffix for explicit no-framework builds.
|
|
|
|
# For framework builds the library inside the framework
|
|
|
|
# is always unsuffixed, and we want to match that for
|
|
|
|
# plugins and other non-framework (static) libraries.
|
|
|
|
if(NOT (QT_FEATURE_framework OR FEATURE_framework
|
|
|
|
# Account for default in configure.json being ON
|
|
|
|
OR (NOT DEFINED QT_FEATURE_framework AND NOT DEFINED FEATURE_framework)))
|
|
|
|
set(default_cmake_debug_postfix "_debug")
|
|
|
|
endif()
|
2023-11-16 16:10:01 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
set(custom_postfix_vars "")
|
|
|
|
set(release_configs Release RelWithDebInfo MinSizeRel)
|
|
|
|
set(found_first_release_config FALSE)
|
|
|
|
foreach(config_type IN LISTS postfix_configurations)
|
|
|
|
string(TOLOWER "${config_type}" config_type_lower)
|
|
|
|
string(TOUPPER "${config_type}" config_type_upper)
|
|
|
|
set(postfix_var CMAKE_${config_type_upper}_POSTFIX)
|
|
|
|
|
|
|
|
# Skip assigning postfix for the first release-like config.
|
|
|
|
if(NOT found_first_release_config
|
|
|
|
AND config_type IN_LIST release_configs)
|
|
|
|
set(found_first_release_config TRUE)
|
|
|
|
if(NOT "${${postfix_var}}" STREQUAL "")
|
|
|
|
list(APPEND custom_postfix_vars ${postfix_var})
|
|
|
|
endif()
|
|
|
|
continue()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Check if the default postfix is set, use '_<config_type_lower>' otherwise.
|
|
|
|
set(default_postfix_var
|
|
|
|
default_cmake_${config_type_lower}_postfix)
|
|
|
|
if(NOT DEFINED ${default_postfix_var})
|
|
|
|
set(${default_postfix_var}
|
|
|
|
"_${config_type_lower}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# If postfix is set by user avoid changing it, but save postfix variable that has
|
|
|
|
# a non-default value for further warning.
|
|
|
|
if("${${postfix_var}}" STREQUAL "")
|
2024-05-21 15:15:04 +00:00
|
|
|
set(${postfix_var} "${${default_postfix_var}}")
|
2023-11-16 16:10:01 +00:00
|
|
|
set(${postfix_var} "${${default_postfix_var}}" PARENT_SCOPE)
|
|
|
|
elseif(NOT "${${postfix_var}}" STREQUAL "${${default_postfix_var}}")
|
|
|
|
list(APPEND custom_postfix_vars ${postfix_var})
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# Adjust framework postfixes accordingly
|
|
|
|
if(APPLE)
|
|
|
|
set(CMAKE_FRAMEWORK_MULTI_CONFIG_POSTFIX_${config_type_upper}
|
|
|
|
"${${postfix_var}}" PARENT_SCOPE)
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
if(custom_postfix_vars)
|
|
|
|
list(REMOVE_DUPLICATES custom_postfix_vars)
|
|
|
|
list(JOIN custom_postfix_vars ", " postfix_vars_string)
|
|
|
|
|
|
|
|
message(WARNING "You are using custom library postfixes: '${postfix_vars_string}' which are"
|
|
|
|
" considered experimental and are not officially supported by Qt."
|
|
|
|
" Expect unforeseen issues and user projects built with qmake to be broken."
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2020-08-13 15:37:47 +00:00
|
|
|
function(qt_is_imported_target target out_var)
|
|
|
|
if(NOT TARGET "${target}")
|
|
|
|
set(target "${QT_CMAKE_EXPORT_NAMESPACE}::${target}")
|
|
|
|
endif()
|
|
|
|
if(NOT TARGET "${target}")
|
|
|
|
message(FATAL_ERROR "Invalid target given to qt_is_imported_target: ${target}")
|
|
|
|
endif()
|
|
|
|
get_target_property(is_imported "${target}" IMPORTED)
|
|
|
|
set(${out_var} "${is_imported}" PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# Add Qt::target and Qt6::target as aliases for the target
|
|
|
|
function(qt_internal_add_target_aliases target)
|
2020-11-16 15:53:15 +00:00
|
|
|
set(versionless_alias "Qt::${target}")
|
|
|
|
set(versionfull_alias "Qt${PROJECT_VERSION_MAJOR}::${target}")
|
|
|
|
set_target_properties("${target}" PROPERTIES _qt_versionless_alias "${versionless_alias}")
|
|
|
|
set_target_properties("${target}" PROPERTIES _qt_versionfull_alias "${versionfull_alias}")
|
|
|
|
|
2020-08-13 15:37:47 +00:00
|
|
|
get_target_property(type "${target}" TYPE)
|
|
|
|
if (type STREQUAL EXECUTABLE)
|
2020-11-16 15:53:15 +00:00
|
|
|
add_executable("${versionless_alias}" ALIAS "${target}")
|
|
|
|
add_executable("${versionfull_alias}" ALIAS "${target}")
|
2020-08-13 15:37:47 +00:00
|
|
|
else()
|
2020-11-16 15:53:15 +00:00
|
|
|
add_library("${versionless_alias}" ALIAS "${target}")
|
|
|
|
add_library("${versionfull_alias}" ALIAS "${target}")
|
2020-08-13 15:37:47 +00:00
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(qt_get_cmake_configurations out_var)
|
|
|
|
set(possible_configs "${CMAKE_BUILD_TYPE}")
|
|
|
|
if(CMAKE_CONFIGURATION_TYPES)
|
|
|
|
set(possible_configs "${CMAKE_CONFIGURATION_TYPES}")
|
|
|
|
endif()
|
|
|
|
set(${out_var} "${possible_configs}" PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(qt_clone_property_for_configs target property configs)
|
|
|
|
get_target_property(value "${target}" "${property}")
|
|
|
|
foreach(config ${configs})
|
|
|
|
string(TOUPPER "${config}" upper_config)
|
|
|
|
set_property(TARGET "${target}" PROPERTY "${property}_${upper_config}" "${value}")
|
|
|
|
endforeach()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(qt_handle_multi_config_output_dirs target)
|
|
|
|
qt_get_cmake_configurations(possible_configs)
|
|
|
|
qt_clone_property_for_configs(${target} LIBRARY_OUTPUT_DIRECTORY "${possible_configs}")
|
|
|
|
qt_clone_property_for_configs(${target} RUNTIME_OUTPUT_DIRECTORY "${possible_configs}")
|
|
|
|
qt_clone_property_for_configs(${target} ARCHIVE_OUTPUT_DIRECTORY "${possible_configs}")
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# Set target properties that are the same for all modules, plugins, executables
|
|
|
|
# and 3rdparty libraries.
|
|
|
|
function(qt_set_common_target_properties target)
|
2020-08-25 06:17:23 +00:00
|
|
|
if(QT_FEATURE_reduce_exports)
|
|
|
|
set_target_properties(${target} PROPERTIES
|
|
|
|
C_VISIBILITY_PRESET hidden
|
|
|
|
CXX_VISIBILITY_PRESET hidden
|
|
|
|
OBJC_VISIBILITY_PRESET hidden
|
|
|
|
OBJCXX_VISIBILITY_PRESET hidden
|
|
|
|
VISIBILITY_INLINES_HIDDEN 1)
|
|
|
|
endif()
|
2020-12-16 05:32:04 +00:00
|
|
|
qt_internal_set_compile_pdb_names("${target}")
|
2020-08-13 15:37:47 +00:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# Set common, informational target properties.
|
|
|
|
#
|
|
|
|
# On Windows, these properties are used to generate the version information resource.
|
|
|
|
function(qt_set_target_info_properties target)
|
|
|
|
cmake_parse_arguments(arg "" "${__default_target_info_args}" "" ${ARGN})
|
2023-03-29 09:40:49 +00:00
|
|
|
if(NOT arg_TARGET_VERSION)
|
2020-08-13 15:37:47 +00:00
|
|
|
set(arg_TARGET_VERSION "${PROJECT_VERSION}.0")
|
|
|
|
endif()
|
2023-03-29 09:40:49 +00:00
|
|
|
if(NOT arg_TARGET_PRODUCT)
|
2020-08-13 15:37:47 +00:00
|
|
|
set(arg_TARGET_PRODUCT "Qt6")
|
|
|
|
endif()
|
2023-03-29 09:40:49 +00:00
|
|
|
if(NOT arg_TARGET_DESCRIPTION)
|
2020-08-13 15:37:47 +00:00
|
|
|
set(arg_TARGET_DESCRIPTION "C++ Application Development Framework")
|
|
|
|
endif()
|
2023-03-29 09:40:49 +00:00
|
|
|
if(NOT arg_TARGET_COMPANY)
|
2020-08-13 15:37:47 +00:00
|
|
|
set(arg_TARGET_COMPANY "The Qt Company Ltd.")
|
|
|
|
endif()
|
2023-03-29 09:40:49 +00:00
|
|
|
if(NOT arg_TARGET_COPYRIGHT)
|
2023-03-14 12:31:39 +00:00
|
|
|
set(arg_TARGET_COPYRIGHT "${QT_COPYRIGHT}")
|
2020-08-13 15:37:47 +00:00
|
|
|
endif()
|
|
|
|
set_target_properties(${target} PROPERTIES
|
|
|
|
QT_TARGET_VERSION "${arg_TARGET_VERSION}"
|
|
|
|
QT_TARGET_COMPANY_NAME "${arg_TARGET_COMPANY}"
|
|
|
|
QT_TARGET_DESCRIPTION "${arg_TARGET_DESCRIPTION}"
|
|
|
|
QT_TARGET_COPYRIGHT "${arg_TARGET_COPYRIGHT}"
|
|
|
|
QT_TARGET_PRODUCT_NAME "${arg_TARGET_PRODUCT}")
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# Uses the QT_DELAYED_TARGET_* property values to set the final QT_TARGET_* properties.
|
|
|
|
# Needed when doing executable finalization at the end of a subdirectory scope
|
|
|
|
# (aka scope finalization).
|
|
|
|
function(qt_internal_set_target_info_properties_from_delayed_properties target)
|
|
|
|
set(args "")
|
|
|
|
foreach(prop ${__default_target_info_args})
|
|
|
|
get_target_property(prop_value "${target}" "QT_DELAYED_${prop}")
|
|
|
|
list(APPEND args "${prop}" "${prop_value}")
|
|
|
|
endforeach()
|
|
|
|
qt_set_target_info_properties(${target} ${args})
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# Updates the QT_DELAYED_ properties with values from the QT_ variants, in case if they were
|
|
|
|
# set in-between a qt_add_* call and before scope finalization.
|
|
|
|
function(qt_internal_update_delayed_target_info_properties target)
|
|
|
|
foreach(prop ${__default_target_info_args})
|
|
|
|
get_target_property(prop_value "${target}" "QT_${prop}")
|
|
|
|
get_target_property(delayed_prop_value ${target} "QT_DELAYED_${prop}")
|
|
|
|
set(final_value "${delayed_prop_value}")
|
|
|
|
if(prop_value)
|
|
|
|
set(final_value "${prop_value}")
|
|
|
|
endif()
|
|
|
|
set_target_properties(${target} PROPERTIES "QT_DELAYED_${prop}" "${final_value}")
|
|
|
|
endforeach()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(qt_internal_check_directory_or_type name dir type default result_var)
|
|
|
|
if ("x${dir}" STREQUAL x)
|
|
|
|
if("x${type}" STREQUAL x)
|
2021-08-04 14:18:44 +00:00
|
|
|
message(FATAL_ERROR
|
|
|
|
"qt_internal_add_plugin called without setting either PLUGIN_TYPE or ${name}.")
|
2020-08-13 15:37:47 +00:00
|
|
|
endif()
|
|
|
|
set(${result_var} "${default}" PARENT_SCOPE)
|
|
|
|
else()
|
|
|
|
set(${result_var} "${dir}" PARENT_SCOPE)
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
2021-05-20 11:38:30 +00:00
|
|
|
macro(qt_internal_get_export_additional_targets_keywords option_args single_args multi_args)
|
|
|
|
set(${option_args}
|
|
|
|
)
|
|
|
|
set(${single_args}
|
|
|
|
EXPORT_NAME_PREFIX
|
|
|
|
)
|
|
|
|
set(${multi_args}
|
|
|
|
TARGETS
|
|
|
|
TARGET_EXPORT_NAMES
|
|
|
|
)
|
|
|
|
endmacro()
|
|
|
|
|
2020-10-15 15:11:16 +00:00
|
|
|
# Create a Qt*AdditionalTargetInfo.cmake file that is included by Qt*Config.cmake
|
|
|
|
# and sets IMPORTED_*_<CONFIG> properties on the exported targets.
|
|
|
|
#
|
2021-05-20 11:38:30 +00:00
|
|
|
# The file also makes the targets global if the QT_PROMOTE_TO_GLOBAL_TARGETS property is set in the
|
|
|
|
# consuming project.
|
2021-06-11 07:54:47 +00:00
|
|
|
# When using a CMake version lower than 3.21, only the specified TARGETS are made global.
|
|
|
|
# E.g. transitive non-Qt 3rd party targets of the specified targets are not made global.
|
2021-05-20 11:38:30 +00:00
|
|
|
#
|
2020-10-15 15:11:16 +00:00
|
|
|
# EXPORT_NAME_PREFIX:
|
|
|
|
# The portion of the file name before AdditionalTargetInfo.cmake
|
|
|
|
# CONFIG_INSTALL_DIR:
|
|
|
|
# Installation location for the target info file
|
|
|
|
# TARGETS:
|
|
|
|
# The internal target names. Those must be actual targets.
|
|
|
|
# TARGET_EXPORT_NAMES:
|
|
|
|
# The target names how they appear in the QtXXXTargets.cmake files.
|
|
|
|
# The names get prefixed by ${QT_CMAKE_EXPORT_NAMESPACE}:: unless they already are.
|
|
|
|
# This argument may be empty, then the target export names are the same as the internal ones.
|
|
|
|
#
|
|
|
|
# TARGETS and TARGET_EXPORT_NAMES must contain exactly the same number of elements.
|
|
|
|
# Example: TARGETS = qmljs_native
|
|
|
|
# TARGET_EXPORT_NAMES = Qt6::qmljs
|
|
|
|
#
|
2020-09-22 20:16:20 +00:00
|
|
|
function(qt_internal_export_additional_targets_file)
|
2021-05-20 11:38:30 +00:00
|
|
|
qt_internal_get_export_additional_targets_keywords(option_args single_args multi_args)
|
|
|
|
cmake_parse_arguments(arg
|
|
|
|
"${option_args}"
|
|
|
|
"${single_args};CONFIG_INSTALL_DIR"
|
|
|
|
"${multi_args}"
|
|
|
|
${ARGN})
|
|
|
|
|
|
|
|
qt_internal_append_export_additional_targets()
|
|
|
|
|
|
|
|
set_property(GLOBAL APPEND PROPERTY _qt_export_additional_targets_ids "${id}")
|
|
|
|
set_property(GLOBAL APPEND
|
|
|
|
PROPERTY _qt_export_additional_targets_export_name_prefix_${id} "${arg_EXPORT_NAME_PREFIX}")
|
|
|
|
set_property(GLOBAL APPEND
|
|
|
|
PROPERTY _qt_export_additional_targets_config_install_dir_${id} "${arg_CONFIG_INSTALL_DIR}")
|
|
|
|
|
|
|
|
qt_add_list_file_finalizer(qt_internal_export_additional_targets_file_finalizer)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(qt_internal_get_export_additional_targets_id export_name out_var)
|
|
|
|
string(MAKE_C_IDENTIFIER "${export_name}" id)
|
|
|
|
set(${out_var} "${id}" PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# Uses outer-scope variables to keep the implementation less verbose.
|
|
|
|
macro(qt_internal_append_export_additional_targets)
|
|
|
|
qt_internal_validate_export_additional_targets(
|
|
|
|
EXPORT_NAME_PREFIX "${arg_EXPORT_NAME_PREFIX}"
|
|
|
|
TARGETS ${arg_TARGETS}
|
|
|
|
TARGET_EXPORT_NAMES ${arg_TARGET_EXPORT_NAMES})
|
|
|
|
|
|
|
|
qt_internal_get_export_additional_targets_id("${arg_EXPORT_NAME_PREFIX}" id)
|
|
|
|
|
|
|
|
set_property(GLOBAL APPEND
|
|
|
|
PROPERTY _qt_export_additional_targets_${id} "${arg_TARGETS}")
|
|
|
|
set_property(GLOBAL APPEND
|
|
|
|
PROPERTY _qt_export_additional_target_export_names_${id} "${arg_TARGET_EXPORT_NAMES}")
|
|
|
|
endmacro()
|
|
|
|
|
|
|
|
# Can be called to add additional targets to the file after the initial setup call.
|
|
|
|
# Used for resources.
|
|
|
|
function(qt_internal_add_targets_to_additional_targets_export_file)
|
|
|
|
qt_internal_get_export_additional_targets_keywords(option_args single_args multi_args)
|
|
|
|
cmake_parse_arguments(arg
|
|
|
|
"${option_args}"
|
|
|
|
"${single_args}"
|
|
|
|
"${multi_args}"
|
|
|
|
${ARGN})
|
|
|
|
|
|
|
|
qt_internal_append_export_additional_targets()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(qt_internal_validate_export_additional_targets)
|
|
|
|
qt_internal_get_export_additional_targets_keywords(option_args single_args multi_args)
|
|
|
|
cmake_parse_arguments(arg
|
|
|
|
"${option_args}"
|
|
|
|
"${single_args}"
|
|
|
|
"${multi_args}"
|
|
|
|
${ARGN})
|
|
|
|
|
|
|
|
if(NOT arg_EXPORT_NAME_PREFIX)
|
|
|
|
message(FATAL_ERROR "qt_internal_validate_export_additional_targets: "
|
|
|
|
"Missing EXPORT_NAME_PREFIX argument.")
|
|
|
|
endif()
|
2020-10-15 15:11:16 +00:00
|
|
|
|
|
|
|
list(LENGTH arg_TARGETS num_TARGETS)
|
|
|
|
list(LENGTH arg_TARGET_EXPORT_NAMES num_TARGET_EXPORT_NAMES)
|
|
|
|
if(num_TARGET_EXPORT_NAMES GREATER 0)
|
|
|
|
if(NOT num_TARGETS EQUAL num_TARGET_EXPORT_NAMES)
|
2021-05-20 11:38:30 +00:00
|
|
|
message(FATAL_ERROR "qt_internal_validate_export_additional_targets: "
|
2020-10-15 15:11:16 +00:00
|
|
|
"TARGET_EXPORT_NAMES is set but has ${num_TARGET_EXPORT_NAMES} elements while "
|
|
|
|
"TARGETS has ${num_TARGETS} elements. "
|
|
|
|
"They must contain the same number of elements.")
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
set(arg_TARGET_EXPORT_NAMES ${arg_TARGETS})
|
|
|
|
endif()
|
2020-09-22 20:16:20 +00:00
|
|
|
|
2021-05-20 11:38:30 +00:00
|
|
|
set(arg_TARGETS "${arg_TARGETS}" PARENT_SCOPE)
|
|
|
|
set(arg_TARGET_EXPORT_NAMES "${arg_TARGET_EXPORT_NAMES}" PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# The finalizer might be called multiple times in the same scope, but only the first one will
|
|
|
|
# process all the ids.
|
|
|
|
function(qt_internal_export_additional_targets_file_finalizer)
|
|
|
|
get_property(ids GLOBAL PROPERTY _qt_export_additional_targets_ids)
|
|
|
|
|
|
|
|
foreach(id ${ids})
|
|
|
|
qt_internal_export_additional_targets_file_handler("${id}")
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
set_property(GLOBAL PROPERTY _qt_export_additional_targets_ids "")
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(qt_internal_export_additional_targets_file_handler id)
|
|
|
|
get_property(arg_EXPORT_NAME_PREFIX GLOBAL PROPERTY
|
|
|
|
_qt_export_additional_targets_export_name_prefix_${id})
|
|
|
|
get_property(arg_CONFIG_INSTALL_DIR GLOBAL PROPERTY
|
|
|
|
_qt_export_additional_targets_config_install_dir_${id})
|
|
|
|
get_property(arg_TARGETS GLOBAL PROPERTY
|
|
|
|
_qt_export_additional_targets_${id})
|
|
|
|
get_property(arg_TARGET_EXPORT_NAMES GLOBAL PROPERTY
|
|
|
|
_qt_export_additional_target_export_names_${id})
|
|
|
|
|
|
|
|
list(LENGTH arg_TARGETS num_TARGETS)
|
|
|
|
|
2020-09-22 20:16:20 +00:00
|
|
|
# Determine the release configurations we're currently building
|
|
|
|
if(QT_GENERATOR_IS_MULTI_CONFIG)
|
|
|
|
set(active_configurations ${CMAKE_CONFIGURATION_TYPES})
|
|
|
|
else()
|
|
|
|
set(active_configurations ${CMAKE_BUILD_TYPE})
|
|
|
|
endif()
|
|
|
|
unset(active_release_configurations)
|
|
|
|
foreach(config ${active_configurations})
|
|
|
|
string(TOUPPER ${config} ucconfig)
|
|
|
|
if(NOT ucconfig STREQUAL "DEBUG")
|
|
|
|
list(APPEND active_release_configurations ${config})
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
|
2020-09-25 12:08:46 +00:00
|
|
|
if(active_release_configurations)
|
|
|
|
# Use the first active release configuration as *the* release config for imported targets
|
|
|
|
# and for QT_DEFAULT_IMPORT_CONFIGURATION.
|
|
|
|
list(GET active_release_configurations 0 release_cfg)
|
|
|
|
string(TOUPPER ${release_cfg} uc_release_cfg)
|
|
|
|
set(uc_default_cfg ${uc_release_cfg})
|
|
|
|
|
|
|
|
# Determine the release configurations we do *not* build currently
|
|
|
|
set(configurations_to_export Release;RelWithDebInfo;MinSizeRel)
|
|
|
|
list(REMOVE_ITEM configurations_to_export ${active_configurations})
|
|
|
|
else()
|
|
|
|
# There are no active release configurations.
|
|
|
|
# Use the first active configuration for QT_DEFAULT_IMPORT_CONFIGURATION.
|
|
|
|
unset(uc_release_cfg)
|
|
|
|
list(GET active_configurations 0 default_cfg)
|
|
|
|
string(TOUPPER ${default_cfg} uc_default_cfg)
|
|
|
|
unset(configurations_to_export)
|
2020-09-22 20:16:20 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
set(content "# Additional target information for ${arg_EXPORT_NAME_PREFIX}
|
|
|
|
if(NOT DEFINED QT_DEFAULT_IMPORT_CONFIGURATION)
|
2020-09-25 12:08:46 +00:00
|
|
|
set(QT_DEFAULT_IMPORT_CONFIGURATION ${uc_default_cfg})
|
2020-09-22 20:16:20 +00:00
|
|
|
endif()
|
|
|
|
")
|
2021-05-20 11:38:30 +00:00
|
|
|
|
2020-10-15 15:11:16 +00:00
|
|
|
math(EXPR n "${num_TARGETS} - 1")
|
|
|
|
foreach(i RANGE ${n})
|
|
|
|
list(GET arg_TARGETS ${i} target)
|
|
|
|
list(GET arg_TARGET_EXPORT_NAMES ${i} target_export_name)
|
2021-05-20 11:38:30 +00:00
|
|
|
|
2020-10-15 15:11:16 +00:00
|
|
|
set(full_target ${target_export_name})
|
2020-09-25 10:18:58 +00:00
|
|
|
if(NOT full_target MATCHES "^${QT_CMAKE_EXPORT_NAMESPACE}::")
|
|
|
|
string(PREPEND full_target "${QT_CMAKE_EXPORT_NAMESPACE}::")
|
|
|
|
endif()
|
2021-05-20 11:38:30 +00:00
|
|
|
|
|
|
|
# Tools are already made global unconditionally in QtFooToolsConfig.cmake.
|
|
|
|
# And the
|
|
|
|
get_target_property(target_type ${target} TYPE)
|
|
|
|
if(NOT target_type STREQUAL "EXECUTABLE")
|
|
|
|
string(APPEND content
|
|
|
|
"__qt_internal_promote_target_to_global_checked(${full_target})\n")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
# INTERFACE libraries don't have IMPORTED_LOCATION-like properties.
|
2022-06-10 14:41:59 +00:00
|
|
|
# Skip the rest of the processing for those.
|
2023-12-14 14:59:21 +00:00
|
|
|
if(target_type STREQUAL "INTERFACE_LIBRARY")
|
2021-05-20 11:38:30 +00:00
|
|
|
continue()
|
|
|
|
endif()
|
|
|
|
|
2020-09-22 20:16:20 +00:00
|
|
|
set(properties_retrieved TRUE)
|
2021-07-08 07:59:05 +00:00
|
|
|
|
2022-08-03 15:46:15 +00:00
|
|
|
get_target_property(is_configure_time_target ${target} _qt_internal_configure_time_target)
|
|
|
|
if(is_configure_time_target)
|
2023-01-06 09:23:51 +00:00
|
|
|
# For Multi-config developer builds we should simply reuse IMPORTED_LOCATION of the
|
|
|
|
# target.
|
|
|
|
if(NOT QT_WILL_INSTALL AND QT_FEATURE_debug_and_release)
|
2024-03-05 13:21:25 +00:00
|
|
|
set(configure_time_target_build_location "")
|
2023-01-06 09:23:51 +00:00
|
|
|
get_target_property(configure_time_target_install_location ${target}
|
|
|
|
IMPORTED_LOCATION)
|
|
|
|
else()
|
2024-04-08 12:49:39 +00:00
|
|
|
if(IS_ABSOLUTE "${arg_CONFIG_INSTALL_DIR}")
|
|
|
|
file(RELATIVE_PATH reverse_relative_prefix_path
|
|
|
|
"${arg_CONFIG_INSTALL_DIR}" "${CMAKE_INSTALL_PREFIX}")
|
|
|
|
else()
|
|
|
|
file(RELATIVE_PATH reverse_relative_prefix_path
|
|
|
|
"${CMAKE_INSTALL_PREFIX}/${arg_CONFIG_INSTALL_DIR}"
|
|
|
|
"${CMAKE_INSTALL_PREFIX}")
|
|
|
|
endif()
|
|
|
|
|
2024-03-05 13:21:25 +00:00
|
|
|
get_target_property(configure_time_target_build_location ${target}
|
|
|
|
_qt_internal_configure_time_target_build_location)
|
2024-04-08 12:49:39 +00:00
|
|
|
string(TOUPPER "${QT_CMAKE_EXPORT_NAMESPACE}_INSTALL_PREFIX" install_prefix_var)
|
|
|
|
string(JOIN "" configure_time_target_build_location
|
|
|
|
"$\{CMAKE_CURRENT_LIST_DIR}/"
|
|
|
|
"${reverse_relative_prefix_path}"
|
|
|
|
"${configure_time_target_build_location}")
|
2024-03-05 13:21:25 +00:00
|
|
|
|
2023-01-06 09:23:51 +00:00
|
|
|
get_target_property(configure_time_target_install_location ${target}
|
|
|
|
_qt_internal_configure_time_target_install_location)
|
2024-03-05 13:21:25 +00:00
|
|
|
|
2024-04-08 12:49:39 +00:00
|
|
|
string(JOIN "" configure_time_target_install_location
|
|
|
|
"$\{CMAKE_CURRENT_LIST_DIR}/"
|
|
|
|
"${reverse_relative_prefix_path}"
|
|
|
|
"${configure_time_target_install_location}")
|
2023-01-06 09:23:51 +00:00
|
|
|
endif()
|
2022-08-03 15:46:15 +00:00
|
|
|
if(configure_time_target_install_location)
|
|
|
|
string(APPEND content "
|
|
|
|
# Import configure-time executable ${full_target}
|
|
|
|
if(NOT TARGET ${full_target})
|
2024-03-05 13:21:25 +00:00
|
|
|
set(_qt_imported_build_location \"${configure_time_target_build_location}\")
|
|
|
|
set(_qt_imported_install_location \"${configure_time_target_install_location}\")
|
|
|
|
set(_qt_imported_location \"\${_qt_imported_install_location}\")
|
|
|
|
if(NOT EXISTS \"$\{_qt_imported_location}\"
|
|
|
|
AND NOT \"$\{_qt_imported_build_location}\" STREQUAL \"\")
|
|
|
|
set(_qt_imported_location \"\${_qt_imported_build_location}\")
|
|
|
|
endif()
|
2023-01-06 09:23:51 +00:00
|
|
|
if(NOT EXISTS \"$\{_qt_imported_location}\")
|
|
|
|
message(FATAL_ERROR \"Unable to add configure time executable ${full_target}\"
|
|
|
|
\" $\{_qt_imported_location} doesn't exists\")
|
|
|
|
endif()
|
2022-08-03 15:46:15 +00:00
|
|
|
add_executable(${full_target} IMPORTED)
|
|
|
|
set_property(TARGET ${full_target} APPEND PROPERTY IMPORTED_CONFIGURATIONS ${default_cfg})
|
|
|
|
set_target_properties(${full_target} PROPERTIES IMPORTED_LOCATION_${uc_default_cfg}
|
2023-01-06 09:23:51 +00:00
|
|
|
\"$\{_qt_imported_location}\")
|
2022-08-03 15:46:15 +00:00
|
|
|
set_property(TARGET ${full_target} PROPERTY IMPORTED_GLOBAL TRUE)
|
2023-01-06 09:23:51 +00:00
|
|
|
unset(_qt_imported_location)
|
2024-03-05 13:21:25 +00:00
|
|
|
unset(_qt_imported_build_location)
|
|
|
|
unset(_qt_imported_install_location)
|
2022-08-03 15:46:15 +00:00
|
|
|
endif()
|
|
|
|
\n")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2021-07-08 07:59:05 +00:00
|
|
|
# Non-prefix debug-and-release builds: add check for the existence of the debug binary of
|
|
|
|
# the target. It is not built by default.
|
|
|
|
if(NOT QT_WILL_INSTALL AND QT_FEATURE_debug_and_release)
|
|
|
|
get_target_property(excluded_genex ${target} EXCLUDE_FROM_ALL)
|
2023-12-14 15:11:24 +00:00
|
|
|
if(excluded_genex)
|
2021-07-08 07:59:05 +00:00
|
|
|
string(APPEND content "
|
|
|
|
# ${full_target} is not built by default in the Debug configuration. Check existence.
|
|
|
|
get_target_property(_qt_imported_location ${full_target} IMPORTED_LOCATION_DEBUG)
|
2023-01-11 13:02:13 +00:00
|
|
|
if(NOT EXISTS \"$\{_qt_imported_location}\")
|
2021-07-08 07:59:05 +00:00
|
|
|
get_target_property(_qt_imported_configs ${full_target} IMPORTED_CONFIGURATIONS)
|
|
|
|
list(REMOVE_ITEM _qt_imported_configs DEBUG)
|
2023-01-11 13:02:13 +00:00
|
|
|
set_property(TARGET ${full_target} PROPERTY IMPORTED_CONFIGURATIONS $\{_qt_imported_configs})
|
2021-07-08 07:59:05 +00:00
|
|
|
set_property(TARGET ${full_target} PROPERTY IMPORTED_LOCATION_DEBUG)
|
2022-08-03 15:46:15 +00:00
|
|
|
endif()\n")
|
2021-07-08 07:59:05 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2021-07-08 08:41:59 +00:00
|
|
|
set(write_implib FALSE)
|
|
|
|
set(write_soname FALSE)
|
2023-12-14 14:59:21 +00:00
|
|
|
set(write_objects FALSE)
|
2024-07-01 14:00:46 +00:00
|
|
|
set(write_link_dependencies FALSE)
|
2023-12-14 14:59:21 +00:00
|
|
|
set(write_location TRUE)
|
|
|
|
|
2021-07-08 08:41:59 +00:00
|
|
|
if(target_type STREQUAL "SHARED_LIBRARY")
|
2021-07-14 09:14:51 +00:00
|
|
|
if(WIN32)
|
2021-07-08 08:41:59 +00:00
|
|
|
set(write_implib TRUE)
|
2022-08-19 12:25:49 +00:00
|
|
|
elseif(WASM)
|
|
|
|
# Keep write_soname at FALSE
|
2021-07-08 08:41:59 +00:00
|
|
|
else()
|
|
|
|
set(write_soname TRUE)
|
|
|
|
endif()
|
2024-07-01 14:00:46 +00:00
|
|
|
set(write_link_dependencies TRUE)
|
2023-12-14 14:59:21 +00:00
|
|
|
elseif(target_type STREQUAL "OBJECT_LIBRARY")
|
|
|
|
set(write_objects TRUE)
|
|
|
|
set(write_location FALSE)
|
2021-07-08 08:41:59 +00:00
|
|
|
endif()
|
|
|
|
|
2020-09-25 12:08:46 +00:00
|
|
|
if(NOT "${uc_release_cfg}" STREQUAL "")
|
2023-12-14 14:59:21 +00:00
|
|
|
if(write_location)
|
|
|
|
string(APPEND content "get_target_property(_qt_imported_location ${full_target} IMPORTED_LOCATION_${uc_release_cfg})\n")
|
|
|
|
endif()
|
2021-07-08 08:41:59 +00:00
|
|
|
if(write_implib)
|
|
|
|
string(APPEND content "get_target_property(_qt_imported_implib ${full_target} IMPORTED_IMPLIB_${uc_release_cfg})\n")
|
|
|
|
endif()
|
|
|
|
if(write_soname)
|
|
|
|
string(APPEND content "get_target_property(_qt_imported_soname ${full_target} IMPORTED_SONAME_${uc_release_cfg})\n")
|
|
|
|
endif()
|
2024-07-01 14:00:46 +00:00
|
|
|
if(write_link_dependencies)
|
|
|
|
string(APPEND content "get_target_property(_qt_imported_link_dependencies ${full_target} IMPORTED_LINK_DEPENDENT_LIBRARIES_${uc_release_cfg})\n")
|
|
|
|
endif()
|
2023-12-14 14:59:21 +00:00
|
|
|
if(write_objects)
|
|
|
|
string(APPEND content "get_target_property(_qt_imported_objects ${full_target} IMPORTED_OBJECTS_${uc_release_cfg})\n")
|
|
|
|
# We generate CLR props as well, because that's what CMake generates for object
|
|
|
|
# libraries with CMake 3.27. They are usually empty strings though, aka "".
|
|
|
|
string(APPEND content "get_target_property(_qt_imported_clr ${full_target} IMPORTED_COMMON_LANGUAGE_RUNTIME_${uc_release_cfg})\n")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
if(write_location)
|
|
|
|
string(APPEND content "get_target_property(_qt_imported_location_default ${full_target} IMPORTED_LOCATION_$\{QT_DEFAULT_IMPORT_CONFIGURATION})\n")
|
2020-09-25 12:08:46 +00:00
|
|
|
endif()
|
2021-07-08 08:41:59 +00:00
|
|
|
if(write_implib)
|
2023-01-11 13:02:13 +00:00
|
|
|
string(APPEND content "get_target_property(_qt_imported_implib_default ${full_target} IMPORTED_IMPLIB_$\{QT_DEFAULT_IMPORT_CONFIGURATION})\n")
|
2021-07-08 08:41:59 +00:00
|
|
|
endif()
|
|
|
|
if(write_soname)
|
2023-01-11 13:02:13 +00:00
|
|
|
string(APPEND content "get_target_property(_qt_imported_soname_default ${full_target} IMPORTED_SONAME_$\{QT_DEFAULT_IMPORT_CONFIGURATION})\n")
|
2021-07-08 08:41:59 +00:00
|
|
|
endif()
|
2024-07-01 14:00:46 +00:00
|
|
|
if(write_link_dependencies)
|
|
|
|
string(APPEND content "get_target_property(_qt_imported_link_dependencies_default ${full_target} IMPORTED_LINK_DEPENDENT_LIBRARIES_$\{QT_DEFAULT_IMPORT_CONFIGURATION})\n")
|
|
|
|
endif()
|
2023-12-14 14:59:21 +00:00
|
|
|
if(write_objects)
|
|
|
|
string(APPEND content "get_target_property(_qt_imported_objects_default ${full_target} IMPORTED_OBJECTS_$\{QT_DEFAULT_IMPORT_CONFIGURATION})\n")
|
|
|
|
string(APPEND content "get_target_property(_qt_imported_clr_default ${full_target} IMPORTED_COMMON_LANGUAGE_RUNTIME_$\{QT_DEFAULT_IMPORT_CONFIGURATION})\n")
|
|
|
|
endif()
|
2020-09-25 12:08:46 +00:00
|
|
|
foreach(config ${configurations_to_export} "")
|
2020-09-22 20:16:20 +00:00
|
|
|
string(TOUPPER "${config}" ucconfig)
|
|
|
|
if("${config}" STREQUAL "")
|
|
|
|
set(property_suffix "")
|
|
|
|
set(var_suffix "_default")
|
|
|
|
string(APPEND content "\n# Default configuration")
|
|
|
|
else()
|
|
|
|
set(property_suffix "_${ucconfig}")
|
|
|
|
set(var_suffix "")
|
|
|
|
string(APPEND content "
|
|
|
|
# Import target \"${full_target}\" for configuration \"${config}\"
|
|
|
|
set_property(TARGET ${full_target} APPEND PROPERTY IMPORTED_CONFIGURATIONS ${ucconfig})
|
|
|
|
")
|
|
|
|
endif()
|
2023-12-14 14:59:21 +00:00
|
|
|
if(write_location)
|
|
|
|
string(APPEND content "
|
2020-09-22 20:16:20 +00:00
|
|
|
if(_qt_imported_location${var_suffix})
|
2023-01-11 13:02:13 +00:00
|
|
|
set_property(TARGET ${full_target} PROPERTY IMPORTED_LOCATION${property_suffix} \"$\{_qt_imported_location${var_suffix}}\")
|
2021-07-08 08:41:59 +00:00
|
|
|
endif()")
|
2023-12-14 14:59:21 +00:00
|
|
|
endif()
|
2021-07-08 08:41:59 +00:00
|
|
|
if(write_implib)
|
|
|
|
string(APPEND content "
|
2020-09-22 20:16:20 +00:00
|
|
|
if(_qt_imported_implib${var_suffix})
|
2023-01-11 13:02:13 +00:00
|
|
|
set_property(TARGET ${full_target} PROPERTY IMPORTED_IMPLIB${property_suffix} \"$\{_qt_imported_implib${var_suffix}}\")
|
2021-07-08 08:41:59 +00:00
|
|
|
endif()")
|
|
|
|
endif()
|
|
|
|
if(write_soname)
|
|
|
|
string(APPEND content "
|
2020-09-22 20:16:20 +00:00
|
|
|
if(_qt_imported_soname${var_suffix})
|
2023-01-11 13:02:13 +00:00
|
|
|
set_property(TARGET ${full_target} PROPERTY IMPORTED_SONAME${property_suffix} \"$\{_qt_imported_soname${var_suffix}}\")
|
2024-07-01 14:00:46 +00:00
|
|
|
endif()")
|
|
|
|
endif()
|
|
|
|
if(write_link_dependencies)
|
|
|
|
string(APPEND content "
|
|
|
|
if(_qt_imported_link_dependencies${var_suffix})
|
|
|
|
set_property(TARGET ${full_target} PROPERTY IMPORTED_LINK_DEPENDENT_LIBRARIES${property_suffix} \"$\{_qt_imported_link_dependencies${var_suffix}}\")
|
2023-12-14 14:59:21 +00:00
|
|
|
endif()")
|
|
|
|
endif()
|
|
|
|
if(write_objects)
|
|
|
|
string(APPEND content "
|
|
|
|
if(_qt_imported_objects${var_suffix})
|
|
|
|
set_property(TARGET ${full_target} PROPERTY IMPORTED_OBJECTS${property_suffix} \"$\{_qt_imported_objects${var_suffix}}\")
|
|
|
|
endif()")
|
|
|
|
string(APPEND content "
|
|
|
|
if(_qt_imported_clr${var_suffix})
|
|
|
|
set_property(TARGET ${full_target} PROPERTY IMPORTED_COMMON_LANGUAGE_RUNTIME${property_suffix} \"$\{_qt_imported_clr${var_suffix}}\")
|
2021-07-08 08:41:59 +00:00
|
|
|
endif()")
|
|
|
|
endif()
|
|
|
|
string(APPEND content "\n")
|
2020-09-22 20:16:20 +00:00
|
|
|
endforeach()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
if(properties_retrieved)
|
|
|
|
string(APPEND content "
|
|
|
|
unset(_qt_imported_location)
|
|
|
|
unset(_qt_imported_location_default)
|
|
|
|
unset(_qt_imported_soname)
|
2021-07-08 07:59:05 +00:00
|
|
|
unset(_qt_imported_soname_default)
|
2024-07-01 14:00:46 +00:00
|
|
|
unset(_qt_imported_link_dependencies)
|
|
|
|
unset(_qt_imported_link_dependencies_default)
|
2023-12-14 14:59:21 +00:00
|
|
|
unset(_qt_imported_objects)
|
|
|
|
unset(_qt_imported_objects_default)
|
|
|
|
unset(_qt_imported_clr)
|
|
|
|
unset(_qt_imported_clr_default)
|
2021-07-08 07:59:05 +00:00
|
|
|
unset(_qt_imported_configs)")
|
2020-09-22 20:16:20 +00:00
|
|
|
endif()
|
|
|
|
|
2020-09-25 12:08:46 +00:00
|
|
|
qt_path_join(output_file "${arg_CONFIG_INSTALL_DIR}"
|
|
|
|
"${arg_EXPORT_NAME_PREFIX}AdditionalTargetInfo.cmake")
|
|
|
|
if(NOT IS_ABSOLUTE "${output_file}")
|
|
|
|
qt_path_join(output_file "${QT_BUILD_DIR}" "${output_file}")
|
|
|
|
endif()
|
2020-09-22 20:16:20 +00:00
|
|
|
qt_configure_file(OUTPUT "${output_file}" CONTENT "${content}")
|
|
|
|
qt_install(FILES "${output_file}" DESTINATION "${arg_CONFIG_INSTALL_DIR}")
|
|
|
|
endfunction()
|
|
|
|
|
2020-08-13 15:37:47 +00:00
|
|
|
function(qt_internal_export_modern_cmake_config_targets_file)
|
2024-01-24 15:12:19 +00:00
|
|
|
cmake_parse_arguments(arg
|
|
|
|
""
|
|
|
|
"EXPORT_NAME_PREFIX;CONFIG_BUILD_DIR;CONFIG_INSTALL_DIR"
|
|
|
|
"TARGETS"
|
|
|
|
${ARGN}
|
|
|
|
)
|
2020-08-13 15:37:47 +00:00
|
|
|
|
2024-01-24 15:12:19 +00:00
|
|
|
if("${arg_TARGETS}" STREQUAL "")
|
|
|
|
message(FATAL_ERROR "Target list is empty")
|
|
|
|
endif()
|
2020-08-13 15:37:47 +00:00
|
|
|
|
2024-01-24 15:12:19 +00:00
|
|
|
if("${arg_CONFIG_BUILD_DIR}" STREQUAL "")
|
|
|
|
message(FATAL_ERROR "CONFIG_BUILD_DIR is not specified")
|
|
|
|
endif()
|
2020-08-13 15:37:47 +00:00
|
|
|
|
2024-01-24 15:12:19 +00:00
|
|
|
if("${arg_CONFIG_INSTALL_DIR}" STREQUAL "")
|
|
|
|
message(FATAL_ERROR "CONFIG_INSTALL_DIR is not specified")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if("${arg_EXPORT_NAME_PREFIX}" STREQUAL "")
|
|
|
|
message(FATAL_ERROR "EXPORT_NAME_PREFIX is not specified")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(versionless_targets ${arg_TARGETS})
|
|
|
|
|
|
|
|
# CMake versions < 3.18 compatibility code. Creates the mimics of the versioned libraries.
|
|
|
|
set(versionless_targets_export "${arg_CONFIG_BUILD_DIR}/${arg_EXPORT_NAME_PREFIX}VersionlessTargets.cmake")
|
|
|
|
configure_file("${QT_CMAKE_DIR}/QtVersionlessTargets.cmake.in"
|
|
|
|
"${versionless_targets_export}"
|
|
|
|
@ONLY
|
|
|
|
)
|
|
|
|
|
|
|
|
# CMake versions >= 3.18 code. Create the versionless ALIAS targets.
|
|
|
|
set(alias_export "${arg_CONFIG_BUILD_DIR}/${arg_EXPORT_NAME_PREFIX}VersionlessAliasTargets.cmake")
|
|
|
|
configure_file("${QT_CMAKE_DIR}/QtVersionlessAliasTargets.cmake.in"
|
|
|
|
"${alias_export}"
|
|
|
|
@ONLY
|
|
|
|
)
|
|
|
|
|
|
|
|
qt_install(FILES
|
|
|
|
"${alias_export}"
|
|
|
|
"${versionless_targets_export}"
|
|
|
|
DESTINATION "${arg_CONFIG_INSTALL_DIR}"
|
|
|
|
COMPONENT Devel
|
|
|
|
)
|
2020-08-13 15:37:47 +00:00
|
|
|
endfunction()
|
|
|
|
|
2020-09-22 08:02:27 +00:00
|
|
|
function(qt_internal_create_tracepoints name tracepoints_file)
|
2020-08-24 19:05:05 +00:00
|
|
|
string(TOLOWER "${name}" provider_name)
|
|
|
|
string(PREPEND provider_name "qt")
|
|
|
|
set(header_filename "${provider_name}_tracepoints_p.h")
|
|
|
|
set(header_path "${CMAKE_CURRENT_BINARY_DIR}/${header_filename}")
|
|
|
|
|
2022-10-24 08:30:56 +00:00
|
|
|
if(QT_FEATURE_lttng OR QT_FEATURE_etw OR QT_FEATURE_ctf)
|
2020-08-24 19:05:05 +00:00
|
|
|
set(source_path "${CMAKE_CURRENT_BINARY_DIR}/${provider_name}_tracepoints.cpp")
|
|
|
|
qt_configure_file(OUTPUT "${source_path}"
|
|
|
|
CONTENT "#define TRACEPOINT_CREATE_PROBES
|
|
|
|
#define TRACEPOINT_DEFINE
|
2020-09-10 14:17:16 +00:00
|
|
|
#include \"${header_filename}\"")
|
2020-08-24 19:05:05 +00:00
|
|
|
target_sources(${name} PRIVATE "${source_path}")
|
2023-03-08 08:38:47 +00:00
|
|
|
target_compile_definitions(${name} PUBLIC Q_TRACEPOINT)
|
2020-08-24 19:05:05 +00:00
|
|
|
|
|
|
|
if(QT_FEATURE_lttng)
|
|
|
|
set(tracegen_arg "lttng")
|
|
|
|
target_link_libraries(${name} PRIVATE LTTng::UST)
|
|
|
|
elseif(QT_FEATURE_etw)
|
|
|
|
set(tracegen_arg "etw")
|
2022-10-24 08:30:56 +00:00
|
|
|
elseif(QT_FEATURE_ctf)
|
|
|
|
set(tracegen_arg "ctf")
|
2020-08-24 19:05:05 +00:00
|
|
|
endif()
|
2020-08-13 15:37:47 +00:00
|
|
|
|
2020-12-15 17:09:32 +00:00
|
|
|
if(NOT "${QT_HOST_PATH}" STREQUAL "")
|
2025-03-17 17:55:27 +00:00
|
|
|
qt_internal_get_host_info_var_prefix(host_info_var_prefix)
|
2020-09-03 10:04:54 +00:00
|
|
|
qt_path_join(tracegen
|
|
|
|
"${QT_HOST_PATH}"
|
2025-03-17 17:55:27 +00:00
|
|
|
"${${host_info_var_prefix}_LIBEXECDIR}"
|
2020-09-03 10:04:54 +00:00
|
|
|
"tracegen")
|
|
|
|
else()
|
|
|
|
set(tracegen "${QT_CMAKE_EXPORT_NAMESPACE}::tracegen")
|
|
|
|
endif()
|
|
|
|
|
2020-08-24 19:05:05 +00:00
|
|
|
get_filename_component(tracepoints_filepath "${tracepoints_file}" ABSOLUTE)
|
|
|
|
add_custom_command(OUTPUT "${header_path}"
|
2020-09-03 10:04:54 +00:00
|
|
|
COMMAND ${tracegen} ${tracegen_arg} "${tracepoints_filepath}" "${header_path}"
|
2020-08-24 19:05:05 +00:00
|
|
|
VERBATIM)
|
|
|
|
add_custom_target(${name}_tracepoints_header DEPENDS "${header_path}")
|
|
|
|
add_dependencies(${name} ${name}_tracepoints_header)
|
2022-09-19 05:23:13 +00:00
|
|
|
else()
|
|
|
|
qt_configure_file(OUTPUT "${header_path}" CONTENT "#include <private/qtrace_p.h>\n")
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(qt_internal_generate_tracepoints name provider)
|
|
|
|
cmake_parse_arguments(arg "" "" "SOURCES" ${ARGN} )
|
|
|
|
set(provider_name ${provider})
|
|
|
|
string(PREPEND provider_name "qt")
|
|
|
|
set(tracepoint_filename "${provider_name}.tracepoints")
|
|
|
|
set(tracepoints_path "${CMAKE_CURRENT_BINARY_DIR}/${tracepoint_filename}")
|
|
|
|
set(header_filename "${provider_name}_tracepoints_p.h")
|
|
|
|
set(header_path "${CMAKE_CURRENT_BINARY_DIR}/${header_filename}")
|
|
|
|
|
2022-10-24 08:30:56 +00:00
|
|
|
if(QT_FEATURE_lttng OR QT_FEATURE_etw OR QT_FEATURE_ctf)
|
2022-09-19 05:23:13 +00:00
|
|
|
|
|
|
|
set(absolute_file_paths "")
|
|
|
|
foreach(file IN LISTS arg_SOURCES)
|
|
|
|
get_filename_component(absolute_file ${file} ABSOLUTE)
|
|
|
|
list(APPEND absolute_file_paths ${absolute_file})
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
if(NOT "${QT_HOST_PATH}" STREQUAL "")
|
2025-03-17 17:55:27 +00:00
|
|
|
qt_internal_get_host_info_var_prefix(host_info_var_prefix)
|
2022-09-19 05:23:13 +00:00
|
|
|
qt_path_join(tracepointgen
|
|
|
|
"${QT_HOST_PATH}"
|
2025-03-17 17:55:27 +00:00
|
|
|
"${${host_info_var_prefix}_LIBEXECDIR}"
|
2022-09-19 05:23:13 +00:00
|
|
|
"tracepointgen")
|
|
|
|
else()
|
|
|
|
set(tracepointgen "${QT_CMAKE_EXPORT_NAMESPACE}::tracepointgen")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
add_custom_command(OUTPUT "${tracepoints_path}"
|
2023-01-27 06:06:54 +00:00
|
|
|
COMMAND ${tracepointgen} ${provider_name} "${tracepoints_path}" "I$<JOIN:$<TARGET_PROPERTY:${name},INCLUDE_DIRECTORIES>,;>" ${absolute_file_paths}
|
2022-09-19 05:23:13 +00:00
|
|
|
DEPENDS ${absolute_file_paths}
|
|
|
|
VERBATIM)
|
|
|
|
add_custom_target(${name}_${provider_name}_tracepoints_file DEPENDS "${tracepoints_path}")
|
|
|
|
add_dependencies(${name} ${name}_${provider_name}_tracepoints_file)
|
|
|
|
|
|
|
|
set(source_path "${CMAKE_CURRENT_BINARY_DIR}/${provider_name}_tracepoints.cpp")
|
|
|
|
qt_configure_file(OUTPUT "${source_path}"
|
|
|
|
CONTENT "#define TRACEPOINT_CREATE_PROBES
|
|
|
|
#define TRACEPOINT_DEFINE
|
|
|
|
#include \"${header_filename}\"")
|
|
|
|
target_sources(${name} PRIVATE "${source_path}")
|
2023-03-08 08:38:47 +00:00
|
|
|
target_compile_definitions(${name} PUBLIC Q_TRACEPOINT)
|
2022-09-19 05:23:13 +00:00
|
|
|
|
|
|
|
if(QT_FEATURE_lttng)
|
|
|
|
set(tracegen_arg "lttng")
|
|
|
|
target_link_libraries(${name} PRIVATE LTTng::UST)
|
|
|
|
elseif(QT_FEATURE_etw)
|
|
|
|
set(tracegen_arg "etw")
|
2022-10-24 08:30:56 +00:00
|
|
|
elseif(QT_FEATURE_ctf)
|
|
|
|
set(tracegen_arg "ctf")
|
2022-09-19 05:23:13 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT "${QT_HOST_PATH}" STREQUAL "")
|
2025-03-17 17:55:27 +00:00
|
|
|
qt_internal_get_host_info_var_prefix(host_info_var_prefix)
|
2022-09-19 05:23:13 +00:00
|
|
|
qt_path_join(tracegen
|
|
|
|
"${QT_HOST_PATH}"
|
2025-03-17 17:55:27 +00:00
|
|
|
"${${host_info_var_prefix}_LIBEXECDIR}"
|
2022-09-19 05:23:13 +00:00
|
|
|
"tracegen")
|
|
|
|
else()
|
|
|
|
set(tracegen "${QT_CMAKE_EXPORT_NAMESPACE}::tracegen")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
get_filename_component(tracepoints_filepath "${tracepoints_path}" ABSOLUTE)
|
|
|
|
add_custom_command(OUTPUT "${header_path}"
|
|
|
|
COMMAND ${tracegen} ${tracegen_arg} "${tracepoints_filepath}" "${header_path}"
|
|
|
|
DEPENDS "${tracepoints_path}"
|
|
|
|
VERBATIM)
|
|
|
|
add_custom_target(${name}_${provider_name}_tracepoints_header DEPENDS "${header_path}")
|
|
|
|
add_dependencies(${name} ${name}_${provider_name}_tracepoints_header)
|
2020-08-24 19:05:05 +00:00
|
|
|
else()
|
|
|
|
qt_configure_file(OUTPUT "${header_path}" CONTENT "#include <private/qtrace_p.h>\n")
|
|
|
|
endif()
|
2020-08-13 15:37:47 +00:00
|
|
|
endfunction()
|
2020-09-29 20:07:33 +00:00
|
|
|
|
|
|
|
function(qt_internal_set_compile_pdb_names target)
|
|
|
|
if(MSVC)
|
|
|
|
get_target_property(target_type ${target} TYPE)
|
2021-11-29 20:18:43 +00:00
|
|
|
if(target_type STREQUAL "STATIC_LIBRARY" OR target_type STREQUAL "OBJECT_LIBRARY")
|
2022-04-30 15:38:02 +00:00
|
|
|
get_target_property(output_name ${target} OUTPUT_NAME)
|
|
|
|
if(NOT output_name)
|
|
|
|
set(output_name "${INSTALL_CMAKE_NAMESPACE}${target}")
|
|
|
|
endif()
|
|
|
|
set_target_properties(${target} PROPERTIES COMPILE_PDB_NAME "${output_name}")
|
|
|
|
set_target_properties(${target} PROPERTIES COMPILE_PDB_NAME_DEBUG "${output_name}d")
|
2020-09-29 20:07:33 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# Installs pdb files for given target into the specified install dir.
|
|
|
|
#
|
|
|
|
# MSVC generates 2 types of pdb files:
|
|
|
|
# - compile-time generated pdb files (compile flag /Zi + /Fd<pdb_name>)
|
2022-06-10 14:41:59 +00:00
|
|
|
# - link-time generated pdb files (link flag /debug + /PDB:<pdb_name>)
|
2020-09-29 20:07:33 +00:00
|
|
|
#
|
|
|
|
# CMake allows changing the names of each of those pdb file types by setting
|
|
|
|
# the COMPILE_PDB_NAME_<CONFIG> and PDB_NAME_<CONFIG> properties. If they are
|
|
|
|
# left empty, CMake will compute the default names itself (or rather in certain cases
|
2022-06-10 14:41:59 +00:00
|
|
|
# leave it up to the compiler), without actually setting the property values.
|
2020-09-29 20:07:33 +00:00
|
|
|
#
|
|
|
|
# For installation purposes, CMake only provides a generator expression to the
|
|
|
|
# link time pdb file path, not the compile path one, which means we have to compute the
|
|
|
|
# path to the compile path pdb files ourselves.
|
|
|
|
# See https://gitlab.kitware.com/cmake/cmake/-/issues/18393 for details.
|
|
|
|
#
|
|
|
|
# For shared libraries and executables, we install the linker provided pdb file via the
|
|
|
|
# TARGET_PDB_FILE generator expression.
|
|
|
|
#
|
|
|
|
# For static libraries there is no linker invocation, so we need to install the compile
|
|
|
|
# time pdb file. We query the ARCHIVE_OUTPUT_DIRECTORY property of the target to get the
|
|
|
|
# path to the pdb file, and reconstruct the file name. We use a generator expression
|
|
|
|
# to append a possible debug suffix, in order to allow installation of all Release and
|
|
|
|
# Debug pdb files when using Ninja Multi-Config.
|
|
|
|
function(qt_internal_install_pdb_files target install_dir_path)
|
|
|
|
if(MSVC)
|
|
|
|
get_target_property(target_type ${target} TYPE)
|
|
|
|
|
2020-11-13 09:27:12 +00:00
|
|
|
if(target_type STREQUAL "EXECUTABLE")
|
|
|
|
qt_get_cmake_configurations(cmake_configs)
|
|
|
|
list(LENGTH cmake_configs all_configs_count)
|
|
|
|
list(GET cmake_configs 0 first_config)
|
|
|
|
foreach(cmake_config ${cmake_configs})
|
|
|
|
set(suffix "")
|
|
|
|
if(all_configs_count GREATER 1 AND NOT cmake_config STREQUAL first_config)
|
|
|
|
set(suffix "/${cmake_config}")
|
|
|
|
endif()
|
|
|
|
qt_install(FILES "$<TARGET_PDB_FILE:${target}>"
|
|
|
|
CONFIGURATIONS ${cmake_config}
|
|
|
|
DESTINATION "${install_dir_path}${suffix}"
|
|
|
|
OPTIONAL)
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
elseif(target_type STREQUAL "SHARED_LIBRARY"
|
2020-09-29 20:07:33 +00:00
|
|
|
OR target_type STREQUAL "MODULE_LIBRARY")
|
|
|
|
qt_install(FILES "$<TARGET_PDB_FILE:${target}>"
|
|
|
|
DESTINATION "${install_dir_path}"
|
|
|
|
OPTIONAL)
|
|
|
|
|
|
|
|
elseif(target_type STREQUAL "STATIC_LIBRARY")
|
|
|
|
get_target_property(lib_dir "${target}" ARCHIVE_OUTPUT_DIRECTORY)
|
|
|
|
if(NOT lib_dir)
|
|
|
|
message(FATAL_ERROR
|
|
|
|
"Can't install pdb file for static library ${target}. "
|
|
|
|
"The ARCHIVE_OUTPUT_DIRECTORY path is not known.")
|
|
|
|
endif()
|
2022-04-30 15:38:02 +00:00
|
|
|
get_target_property(pdb_name "${target}" COMPILE_PDB_NAME)
|
|
|
|
qt_path_join(compile_time_pdb_file_path
|
|
|
|
"${lib_dir}" "${pdb_name}$<$<CONFIG:Debug>:d>.pdb")
|
2020-09-29 20:07:33 +00:00
|
|
|
|
|
|
|
qt_install(FILES "${compile_time_pdb_file_path}"
|
|
|
|
DESTINATION "${install_dir_path}" OPTIONAL)
|
2021-11-29 20:18:43 +00:00
|
|
|
elseif(target_type STREQUAL "OBJECT_LIBRARY")
|
|
|
|
get_target_property(pdb_dir "${target}" COMPILE_PDB_OUTPUT_DIRECTORY)
|
|
|
|
if(NOT pdb_dir)
|
|
|
|
get_target_property(pdb_dir "${target}" BINARY_DIR)
|
|
|
|
if(QT_GENERATOR_IS_MULTI_CONFIG)
|
|
|
|
qt_path_join(pdb_dir "${pdb_dir}" "$<CONFIG>")
|
|
|
|
endif()
|
|
|
|
endif()
|
2022-04-30 15:38:02 +00:00
|
|
|
get_target_property(pdb_name "${target}" COMPILE_PDB_NAME)
|
|
|
|
qt_path_join(compile_time_pdb_file_path
|
|
|
|
"${pdb_dir}" "${pdb_name}$<$<CONFIG:Debug>:d>.pdb")
|
2021-11-29 20:18:43 +00:00
|
|
|
|
|
|
|
qt_install(FILES "${compile_time_pdb_file_path}"
|
|
|
|
DESTINATION "${install_dir_path}" OPTIONAL)
|
2020-09-29 20:07:33 +00:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endfunction()
|
CMake: Fix building multi-arch universal macOS Qt
Use the same approach we use for iOS, which is to set multiple
CMAKE_OSX_ARCHITECTURES values and let the clang front end
deal with lipo-ing the final libraries.
For now, Qt can be configured to build universal macOS libraries by
passing 2 architectures to CMake, either via:
-DCMAKE_OSX_ARCHITECTURES="x86_64;arm64"
or
-DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"
Currently we recommend specifying the intel x86_64 arch as the first
one, to get an intel slice configuration that is comparable to a
non-universal intel build.
Specifying the arm64 slice first could pessimize optimizations and
reduce the feature set for the intel slice due to the limitation
that we run configure tests only once.
The first specified architecture is the one used to do all the
configure tests.
It 'mostly' defines the common feature set of both architecture
slices, with the excepion of some special handling for sse2 and
neon instructions.
In the future we might want to run at least the Qt architecture config
test for all specified architectures, so that we can extract all the
supported sub-arches and instruction sets in a reliable way.
For now, we use the same sse2 hack as for iOS simulator_and_device
builds, otherwise QtGui fails to link due to missing
qt_memfill32_sse2 and other symbols.
The hack is somewhat augmented to ensure that reconfiguration
still succeeds (same issue happened with iOS). Previously the sse2
feature condition was broken due to force setting the feature
to be ON. Now the condition also checks for a special
QT_FORCE_FEATURE_sse2 variable which we set internally.
Note that we shouldn't build for arm64e, because the binaries
get killed when running on AS with the following message:
kernel: exec_mach_imgact: not running binary built against
preview arm64e ABI.
Aslo, by default, we disable the arm64 slice for qt sql plugins,
mostly because the CI provisioned sql libraries that we depend on only
contain x86_64 slices, and trying to build the sql plugins for both
slices will fail with linker errors.
This behavior can be disabled for all targets marked by
qt_internal_force_macos_intel_arch, by setting the
QT_FORCE_MACOS_ALL_ARCHES CMake option to ON.
To disble it per-target one can set
QT_FORCE_MACOS_ALL_ARCHES_${target} to ON.
Task-number: QTBUG-85447
Change-Id: Iccb5dfcc1a21a8a8292bd3817df0ea46c3445f75
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2021-03-24 15:03:35 +00:00
|
|
|
|
|
|
|
# Certain targets might have dependencies on libraries that don't have an Apple Silicon arm64
|
|
|
|
# slice. When doing a universal macOS build, force those targets to be built only for the
|
|
|
|
# Intel x86_64 arch.
|
|
|
|
# This behavior can be disabled for all targets by setting the QT_FORCE_MACOS_ALL_ARCHES cache
|
|
|
|
# variable to TRUE or by setting the target specific cache variable
|
|
|
|
# QT_FORCE_MACOS_ALL_ARCHES_${target} to TRUE.
|
|
|
|
#
|
|
|
|
# TODO: Ideally we'd use something like _apple_resolve_supported_archs_for_sdk_from_system_lib
|
|
|
|
# from CMake's codebase to parse which architectures are available in a library, but it's
|
|
|
|
# not straightforward to extract the library absolute file path from a CMake target. Furthermore
|
|
|
|
# Apple started using a built-in dynamic linker cache of all system-provided libraries as per
|
|
|
|
# https://gitlab.kitware.com/cmake/cmake/-/issues/20863
|
|
|
|
# so if the target is a library in the dynamic cache, that might further complicate how to get
|
|
|
|
# the list of arches in it.
|
|
|
|
function(qt_internal_force_macos_intel_arch target)
|
|
|
|
if(MACOS AND QT_IS_MACOS_UNIVERSAL AND NOT QT_FORCE_MACOS_ALL_ARCHES
|
|
|
|
AND NOT QT_FORCE_MACOS_ALL_ARCHES_${target})
|
|
|
|
set(arches "x86_64")
|
|
|
|
set_target_properties(${target} PROPERTIES OSX_ARCHITECTURES "${arches}")
|
|
|
|
endif()
|
|
|
|
endfunction()
|
2021-04-22 07:55:55 +00:00
|
|
|
|
|
|
|
function(qt_disable_apple_app_extension_api_only target)
|
|
|
|
set_target_properties("${target}" PROPERTIES QT_NO_APP_EXTENSION_ONLY_API TRUE)
|
|
|
|
endfunction()
|
2021-04-28 15:24:30 +00:00
|
|
|
|
|
|
|
# Common function to add Qt prefixes to the target name
|
|
|
|
function(qt_internal_qtfy_target out_var target)
|
|
|
|
set(${out_var} "Qt${target}" PARENT_SCOPE)
|
|
|
|
set(${out_var}_versioned "Qt${PROJECT_VERSION_MAJOR}${target}" PARENT_SCOPE)
|
|
|
|
endfunction()
|
2021-07-07 14:04:17 +00:00
|
|
|
|
|
|
|
function(qt_internal_get_main_cmake_configuration out_var)
|
|
|
|
if(CMAKE_BUILD_TYPE)
|
|
|
|
set(config "${CMAKE_BUILD_TYPE}")
|
|
|
|
elseif(QT_MULTI_CONFIG_FIRST_CONFIG)
|
|
|
|
set(config "${QT_MULTI_CONFIG_FIRST_CONFIG}")
|
|
|
|
endif()
|
|
|
|
set("${out_var}" "${config}" PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(qt_internal_get_upper_case_main_cmake_configuration out_var)
|
|
|
|
qt_internal_get_main_cmake_configuration("${out_var}")
|
|
|
|
string(TOUPPER "${${out_var}}" upper_config)
|
|
|
|
set("${out_var}" "${upper_config}" PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(qt_internal_adjust_main_config_runtime_output_dir target output_dir)
|
|
|
|
# When building Qt with multiple configurations, place the main configuration executable
|
|
|
|
# directly in ${output_dir}, rather than a ${output_dir}/<CONFIG> subdirectory.
|
|
|
|
qt_internal_get_upper_case_main_cmake_configuration(main_cmake_configuration)
|
|
|
|
set_target_properties("${target}" PROPERTIES
|
|
|
|
RUNTIME_OUTPUT_DIRECTORY_${main_cmake_configuration} "${output_dir}"
|
|
|
|
)
|
|
|
|
endfunction()
|
2021-07-15 11:04:15 +00:00
|
|
|
|
|
|
|
# Marks a target with a property that it is a library (shared or static) which was built using the
|
|
|
|
# internal Qt API (qt_internal_add_module, qt_internal_add_plugin, etc) as opposed to it being
|
|
|
|
# a user project library (qt_add_library, qt_add_plugin, etc).
|
|
|
|
#
|
|
|
|
# Needed to allow selectively applying certain flags via PlatformXInternal targets.
|
|
|
|
function(qt_internal_mark_as_internal_library target)
|
|
|
|
set_target_properties(${target} PROPERTIES _qt_is_internal_library TRUE)
|
2024-07-02 13:44:02 +00:00
|
|
|
set_property(TARGET "${target}" APPEND PROPERTY EXPORT_PROPERTIES "_qt_is_internal_library")
|
2023-05-22 14:02:44 +00:00
|
|
|
qt_internal_mark_as_internal_target(${target})
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# Marks a target with a property that it was built using the internal Qt API (qt_internal_*) as
|
|
|
|
# opposed to it being a user project library or executable(qt_add_*, etc).
|
|
|
|
#
|
|
|
|
# Needed to allow selectively applying certain flags via PlatformXInternal targets.
|
|
|
|
function(qt_internal_mark_as_internal_target target)
|
|
|
|
set_target_properties(${target} PROPERTIES _qt_is_internal_target TRUE)
|
2024-07-02 13:44:02 +00:00
|
|
|
set_property(TARGET "${target}" APPEND PROPERTY EXPORT_PROPERTIES "_qt_is_internal_target")
|
2021-07-15 11:04:15 +00:00
|
|
|
endfunction()
|
2021-07-15 11:41:15 +00:00
|
|
|
|
2023-01-19 17:55:58 +00:00
|
|
|
# Marks a target with a property to skip it adding it as a dependency when building examples as
|
|
|
|
# ExternalProjects.
|
|
|
|
# Needed to create a ${repo}_src global target that examples can depend on in multi-config builds
|
|
|
|
# due to a bug in AUTOUIC.
|
|
|
|
#
|
|
|
|
# See QTBUG-110369.
|
|
|
|
function(qt_internal_skip_dependency_for_examples target)
|
|
|
|
set_target_properties(${target} PROPERTIES _qt_skip_dependency_for_examples TRUE)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(qt_internal_is_target_skipped_for_examples target out_var)
|
|
|
|
get_property(is_skipped TARGET ${target} PROPERTY _qt_skip_dependency_for_examples)
|
|
|
|
if(NOT is_skipped)
|
|
|
|
set(is_skipped FALSE)
|
|
|
|
endif()
|
|
|
|
set(${out_var} "${is_skipped}" PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
2021-07-15 11:41:15 +00:00
|
|
|
function(qt_internal_link_internal_platform_for_object_library target)
|
2024-09-10 16:20:51 +00:00
|
|
|
cmake_parse_arguments(arg "" "PARENT_TARGET" "" ${ARGN})
|
2021-07-15 11:41:15 +00:00
|
|
|
# We need to apply iOS bitcode flags to object libraries that are associated with internal
|
|
|
|
# modules or plugins (e.g. object libraries added by qt_internal_add_resource,
|
|
|
|
# qt_internal_add_plugin, etc.)
|
|
|
|
# The flags are needed when building iOS apps because Xcode expects bitcode to be
|
|
|
|
# present by default.
|
|
|
|
# Achieve this by compiling the cpp files with the PlatformModuleInternal compile flags.
|
|
|
|
target_link_libraries("${target}" PRIVATE Qt::PlatformModuleInternal)
|
2024-09-10 16:20:51 +00:00
|
|
|
|
|
|
|
if(arg_PARENT_TARGET AND TARGET "${arg_PARENT_TARGET}")
|
|
|
|
foreach(property QT_SKIP_WARNINGS_ARE_ERRORS _qt_internal_use_exceptions)
|
|
|
|
set_property(TARGET "${target}" PROPERTY
|
|
|
|
${property} "$<BOOL:$<TARGET_PROPERTY:${arg_PARENT_TARGET},${property}>>")
|
|
|
|
endforeach()
|
|
|
|
endif()
|
2021-07-15 11:41:15 +00:00
|
|
|
endfunction()
|
2021-07-27 11:54:56 +00:00
|
|
|
|
2021-10-01 07:48:42 +00:00
|
|
|
# Use ${dep_target}'s include dirs when building ${target}.
|
|
|
|
#
|
|
|
|
# Assumes ${dep_target} is an INTERFACE_LIBRARY that only propagates include dirs and ${target}
|
|
|
|
# is a Qt module / plugin.
|
|
|
|
#
|
|
|
|
# Building ${target} requires ${dep_target}'s include dirs.
|
|
|
|
# Using ${target} does not require ${dep_target}'s include dirs.
|
|
|
|
#
|
|
|
|
# The main use case is adding the private header-only dependency PkgConfig::ATSPI2.
|
|
|
|
function(qt_internal_add_target_include_dirs target dep_target)
|
|
|
|
if(NOT TARGET "${target}")
|
|
|
|
message(FATAL_ERROR "${target} is not a valid target.")
|
|
|
|
endif()
|
|
|
|
if(NOT TARGET "${dep_target}")
|
|
|
|
message(FATAL_ERROR "${dep_target} is not a valid target.")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
target_include_directories("${target}" PRIVATE
|
|
|
|
"$<TARGET_PROPERTY:${dep_target},INTERFACE_INCLUDE_DIRECTORIES>")
|
|
|
|
endfunction()
|
2021-07-27 11:54:56 +00:00
|
|
|
|
|
|
|
# Use ${dep_target}'s include dirs when building ${target} and optionally propagate the include
|
|
|
|
# dirs to consumers of ${target}.
|
|
|
|
|
|
|
|
# Assumes ${dep_target} is an INTERFACE_LIBRARY that only propagates include dirs and ${target}
|
|
|
|
# is a Qt module / plugin.
|
|
|
|
#
|
|
|
|
# Building ${target} requires ${dep_target}'s include dirs.
|
|
|
|
#
|
|
|
|
# User projects that don't have ${dep_target}'s headers installed in their system should still
|
|
|
|
# configure successfully.
|
|
|
|
#
|
|
|
|
# To achieve that, consumers of ${target} will only get the include directories of ${dep_target}
|
|
|
|
# if the latter package and target exists.
|
|
|
|
#
|
2022-07-08 15:11:59 +00:00
|
|
|
# A find_package(dep_target) dependency is added to ${target}'s *Dependencies.cmake file.
|
2021-07-27 11:54:56 +00:00
|
|
|
#
|
|
|
|
# We use target_include_directories(PRIVATE) instead of target_link_libraries(PRIVATE) because the
|
|
|
|
# latter would propagate a mandatory LINK_ONLY dependency on the ${dep_target} in a static Qt build.
|
|
|
|
#
|
|
|
|
# The main use case is for propagating WrapVulkanHeaders::WrapVulkanHeaders.
|
|
|
|
function(qt_internal_add_target_include_dirs_and_optionally_propagate target dep_target)
|
2021-10-01 07:48:42 +00:00
|
|
|
qt_internal_add_target_include_dirs(${target} ${dep_target})
|
2021-07-27 11:54:56 +00:00
|
|
|
|
|
|
|
target_link_libraries("${target}" INTERFACE "$<TARGET_NAME_IF_EXISTS:${dep_target}>")
|
|
|
|
|
|
|
|
qt_record_extra_third_party_dependency("${target}" "${dep_target}")
|
|
|
|
endfunction()
|
2022-01-31 17:53:57 +00:00
|
|
|
|
|
|
|
# The function disables one or multiple internal global definitions that are defined by the
|
|
|
|
# qt_internal_add_global_definition function for a specific 'target'.
|
|
|
|
function(qt_internal_undefine_global_definition target)
|
2023-01-02 18:19:44 +00:00
|
|
|
if(NOT TARGET "${target}")
|
|
|
|
message(FATAL_ERROR "${target} is not a target.")
|
|
|
|
endif()
|
2023-01-03 13:42:33 +00:00
|
|
|
qt_internal_is_skipped_test(skipped ${target})
|
|
|
|
if(skipped)
|
|
|
|
return()
|
|
|
|
endif()
|
2023-01-02 18:19:44 +00:00
|
|
|
qt_internal_is_in_test_batch(in_batch ${target})
|
|
|
|
if(in_batch)
|
2022-08-24 07:28:37 +00:00
|
|
|
_qt_internal_test_batch_target_name(target)
|
2022-01-31 17:53:57 +00:00
|
|
|
endif()
|
|
|
|
|
|
|
|
if("${ARGN}" STREQUAL "")
|
|
|
|
message(FATAL_ERROR "The function expects at least one definition as an argument.")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
foreach(definition IN LISTS ARGN)
|
|
|
|
set(undef_property_name "QT_INTERNAL_UNDEF_${definition}")
|
|
|
|
set_target_properties(${target} PROPERTIES "${undef_property_name}" TRUE)
|
|
|
|
endforeach()
|
|
|
|
endfunction()
|
2022-03-11 11:41:36 +00:00
|
|
|
|
|
|
|
# This function adds any defines which are local to the current repository (e.g. qtbase,
|
|
|
|
# qtmultimedia). Those can be defined in the corresponding .cmake.conf file via
|
|
|
|
# QT_EXTRA_INTERNAL_TARGET_DEFINES. QT_EXTRA_INTERNAL_TARGET_DEFINES accepts a list of definitions.
|
|
|
|
# The definitions are passed to target_compile_definitions, which means that values can be provided
|
|
|
|
# via the FOO=Bar syntax
|
|
|
|
# This does nothing for interface targets
|
|
|
|
function(qt_internal_add_repo_local_defines target)
|
|
|
|
get_target_property(type "${target}" TYPE)
|
|
|
|
if (${type} STREQUAL "INTERFACE_LIBRARY")
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
if(DEFINED QT_EXTRA_INTERNAL_TARGET_DEFINES)
|
|
|
|
target_compile_definitions("${target}" PRIVATE ${QT_EXTRA_INTERNAL_TARGET_DEFINES})
|
|
|
|
endif()
|
|
|
|
endfunction()
|
2022-08-10 15:21:18 +00:00
|
|
|
|
|
|
|
# The function returns the value of the target's SOURCES property. The function takes into account
|
|
|
|
# the limitation of the CMake version less than 3.19, that restricts to add non-interface sources
|
|
|
|
# to an interface target.
|
|
|
|
# Note: The function works correctly only if qt_internal_extend_target is used when adding source
|
|
|
|
# files.
|
|
|
|
function(qt_internal_get_target_sources out_var target)
|
|
|
|
qt_internal_get_target_sources_property(sources_property)
|
|
|
|
get_target_property(${out_var} ${target} ${sources_property})
|
|
|
|
set(${out_var} "${${out_var}}" PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# The function distinguishes what property supposed to store target sources, based on target TYPE
|
|
|
|
# and the CMake version.
|
|
|
|
function(qt_internal_get_target_sources_property out_var)
|
|
|
|
set(${out_var} "SOURCES")
|
|
|
|
get_target_property(target_type ${target} TYPE)
|
|
|
|
if(CMAKE_VERSION VERSION_LESS "3.19" AND target_type STREQUAL "INTERFACE_LIBRARY")
|
|
|
|
set(${out_var} "_qt_internal_target_sources")
|
|
|
|
endif()
|
|
|
|
set(${out_var} "${${out_var}}" PARENT_SCOPE)
|
|
|
|
endfunction()
|
2022-05-13 16:24:22 +00:00
|
|
|
|
|
|
|
# This function collects target properties that contain generator expressions and needs to be
|
|
|
|
# exported. This function is needed since the CMake EXPORT_PROPERTIES property doesn't support
|
|
|
|
# properties that contain generator expressions.
|
|
|
|
# Usage: qt_internal_add_genex_properties_export(target properties...)
|
|
|
|
function(qt_internal_add_genex_properties_export target)
|
|
|
|
get_cmake_property(is_multi_config GENERATOR_IS_MULTI_CONFIG)
|
|
|
|
|
|
|
|
set(config_check_begin "")
|
|
|
|
set(config_check_end "")
|
|
|
|
if(is_multi_config)
|
|
|
|
list(GET CMAKE_CONFIGURATION_TYPES 0 first_config_type)
|
|
|
|
|
|
|
|
# The genex snippet is evaluated to '$<NOT:$<BOOL:$<CONFIG>>>' in the generated cmake file.
|
|
|
|
# The check is only applicable to the 'main' configuration. If user project doesn't use
|
|
|
|
# multi-config generator, then the check supposed to return true and the value from the
|
|
|
|
# 'main' configuration supposed to be used.
|
|
|
|
string(JOIN "" check_if_config_empty
|
|
|
|
"$<1:$><NOT:"
|
|
|
|
"$<1:$><BOOL:"
|
|
|
|
"$<1:$><CONFIG$<ANGLE-R>"
|
|
|
|
"$<ANGLE-R>"
|
|
|
|
"$<ANGLE-R>"
|
|
|
|
)
|
|
|
|
|
|
|
|
# The genex snippet is evaluated to '$<CONFIG:'Qt config type'>' in the generated cmake
|
|
|
|
# file and checks if the config that user uses matches the generated cmake file config.
|
|
|
|
string(JOIN "" check_user_config
|
|
|
|
"$<1:$><CONFIG:$<CONFIG>$<ANGLE-R>"
|
|
|
|
)
|
|
|
|
|
|
|
|
# The genex snippet is evaluated to '$<$<OR:$<CONFIG:'Qt config type'>>:'Property content'>
|
|
|
|
# for non-main Qt configs and to
|
|
|
|
# $<$<OR:$<CONFIG:'Qt config type'>,$<NOT:$<BOOL:$<CONFIG>>>>:'Property content'> for the
|
|
|
|
# main Qt config. This guard is required to choose the correct value of the property for the
|
|
|
|
# user project according to the user config type.
|
|
|
|
# All genexes need to be escaped properly to protect them from evaluation by the
|
|
|
|
# file(GENERATE call in the qt_internal_export_genex_properties function.
|
|
|
|
string(JOIN "" config_check_begin
|
|
|
|
"$<1:$><"
|
|
|
|
"$<1:$><OR:"
|
|
|
|
"${check_user_config}"
|
|
|
|
"$<$<CONFIG:${first_config_type}>:$<COMMA>${check_if_config_empty}>"
|
|
|
|
"$<ANGLE-R>:"
|
|
|
|
)
|
|
|
|
set(config_check_end "$<ANGLE-R>")
|
|
|
|
endif()
|
|
|
|
set(target_name "${QT_CMAKE_EXPORT_NAMESPACE}::${target}")
|
|
|
|
foreach(property IN LISTS ARGN)
|
|
|
|
set(target_property_genex "$<TARGET_PROPERTY:${target_name},${property}>")
|
|
|
|
# All properties that contain lists need to be protected of processing by JOIN genex calls.
|
|
|
|
# So this escapes the semicolons for these list.
|
|
|
|
set(target_property_list_escape
|
|
|
|
"$<JOIN:$<GENEX_EVAL:${target_property_genex}>,\;>")
|
|
|
|
set(property_value
|
|
|
|
"\"${config_check_begin}${target_property_list_escape}${config_check_end}\"")
|
|
|
|
set_property(TARGET ${target} APPEND PROPERTY _qt_export_genex_properties_content
|
|
|
|
"${property} ${property_value}")
|
|
|
|
endforeach()
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# This function executes generator expressions for the properties that are added by the
|
|
|
|
# qt_internal_add_genex_properties_export function and sets the calculated values to the
|
|
|
|
# corresponding properties in the generated ExtraProperties.cmake file. The file then needs to be
|
|
|
|
# included after the target creation routines in Config.cmake files. It also supports Multi-Config
|
|
|
|
# builds.
|
|
|
|
# Arguments:
|
|
|
|
# EXPORT_NAME_PREFIX:
|
|
|
|
# The portion of the file name before ExtraProperties.cmake
|
|
|
|
# CONFIG_INSTALL_DIR:
|
|
|
|
# Installation location for the file.
|
|
|
|
# TARGETS:
|
|
|
|
# The internal target names.
|
|
|
|
function(qt_internal_export_genex_properties)
|
|
|
|
set(option_args "")
|
|
|
|
set(single_args
|
|
|
|
EXPORT_NAME_PREFIX
|
|
|
|
CONFIG_INSTALL_DIR
|
|
|
|
)
|
|
|
|
set(multi_args TARGETS)
|
|
|
|
cmake_parse_arguments(arg "${option_args}" "${single_args}" "${multi_args}" ${ARGN})
|
|
|
|
|
|
|
|
if(NOT arg_EXPORT_NAME_PREFIX)
|
|
|
|
message(FATAL_ERROR "qt_internal_export_genex_properties: "
|
|
|
|
"Missing EXPORT_NAME_PREFIX argument.")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(NOT arg_TARGETS)
|
|
|
|
message(FATAL_ERROR "qt_internal_export_genex_properties: "
|
|
|
|
"TARGETS argument must contain at least one target")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
foreach(target IN LISTS arg_TARGETS)
|
|
|
|
get_cmake_property(is_multi_config GENERATOR_IS_MULTI_CONFIG)
|
|
|
|
|
|
|
|
set(output_file_base_name "${arg_EXPORT_NAME_PREFIX}ExtraProperties")
|
|
|
|
set(should_append "")
|
|
|
|
set(config_suffix "")
|
|
|
|
if(is_multi_config)
|
|
|
|
list(GET CMAKE_CONFIGURATION_TYPES 0 first_config_type)
|
|
|
|
set(config_suffix "$<$<NOT:$<CONFIG:${first_config_type}>>:-$<CONFIG>>")
|
|
|
|
# If the generated file belongs to the 'main' config type, we should set property
|
|
|
|
# but not append it.
|
|
|
|
string(JOIN "" should_append
|
|
|
|
"$<$<NOT:$<CONFIG:${first_config_type}>>: APPEND>")
|
|
|
|
endif()
|
|
|
|
set(file_name "${output_file_base_name}${config_suffix}.cmake")
|
|
|
|
|
|
|
|
qt_path_join(output_file "${arg_CONFIG_INSTALL_DIR}"
|
|
|
|
"${file_name}")
|
|
|
|
|
|
|
|
if(NOT IS_ABSOLUTE "${output_file}")
|
|
|
|
qt_path_join(output_file "${QT_BUILD_DIR}" "${output_file}")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(target_name "${QT_CMAKE_EXPORT_NAMESPACE}::${target}")
|
|
|
|
|
|
|
|
string(JOIN "" set_property_begin "set_property(TARGET "
|
|
|
|
"${target_name}${should_append} PROPERTY "
|
|
|
|
)
|
|
|
|
set(set_property_end ")")
|
|
|
|
set(set_property_glue "${set_property_end}\n${set_property_begin}")
|
|
|
|
set(property_list
|
|
|
|
"$<GENEX_EVAL:$<TARGET_PROPERTY:${target},_qt_export_genex_properties_content>>")
|
|
|
|
string(JOIN "" set_property_content "${set_property_begin}"
|
|
|
|
"$<JOIN:${property_list},${set_property_glue}>"
|
|
|
|
"${set_property_end}")
|
|
|
|
|
|
|
|
if(is_multi_config)
|
|
|
|
set(config_includes "")
|
|
|
|
foreach(config IN LISTS CMAKE_CONFIGURATION_TYPES)
|
|
|
|
if(NOT first_config_type STREQUAL config)
|
|
|
|
set(include_file_name
|
|
|
|
"${output_file_base_name}-${config}.cmake")
|
|
|
|
list(APPEND config_includes
|
|
|
|
"include(\"\${CMAKE_CURRENT_LIST_DIR}/${include_file_name}\")")
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
list(JOIN config_includes "\n" config_includes_string)
|
|
|
|
set(config_includes_string
|
|
|
|
"\n$<$<CONFIG:${first_config_type}>:${config_includes_string}>")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
file(GENERATE OUTPUT "${output_file}"
|
|
|
|
CONTENT "$<$<BOOL:${property_list}>:${set_property_content}${config_includes_string}>"
|
|
|
|
CONDITION "$<BOOL:${property_list}>"
|
|
|
|
)
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
qt_install(FILES "$<$<BOOL:${property_list}>:${output_file}>"
|
|
|
|
DESTINATION "${arg_CONFIG_INSTALL_DIR}"
|
|
|
|
COMPONENT Devel
|
|
|
|
)
|
|
|
|
endfunction()
|
2024-01-30 15:30:16 +00:00
|
|
|
|
2024-07-02 13:44:02 +00:00
|
|
|
# A small wrapper for adding the Platform target, and a building block for the PlatformXInternal
|
|
|
|
# and GlobalConfig INTERFACE targets to apply common options.
|
|
|
|
function(qt_internal_add_platform_target target)
|
|
|
|
_qt_internal_add_library("${target}" INTERFACE)
|
|
|
|
qt_internal_add_target_aliases("${target}")
|
CMake: Prevent most global promotion errors when building Qt
Backstory.
The main reason why we keep getting "unable to promote 3rd party 'X'
target to global scope" errors when building Qt repositories, is
because we try to promote 3rd party imported targets in a different
scope than where the imported targets were created.
What were the main motivations for promoting 3rd party targets to
global?
1) imported targets are by default local to the directory scope they
were created in
2) we want 3rd party targets to be accessible across subdirectory
scopes, but looked up once, e.g. qt_find_package(JPEG) looked up in
src/gui/CMakeLists.txt, but the target should also be usable in the
sibling scope
src/plugins/imageformats/CMakeLists.txt
Having the package lookup close to the consuming qt module is easier
to maintain, because all the other 3rd party dependency lookups are
in the same file. This goes against the conventional CMake advice
where each subdirectory should look for its own dependencies, or the
dependency should be available directly in the root project scope.
3) to make the 3rd party targets available in the root project scope
as part of the following flow:
QtPostProcess.cmake ->
qt_internal_create_module_depends_file() ->
qt_collect_third_party_deps() ->
get_property(INTERFACE_QT_PACKAGE_NAME) ->
write 3rd party Dependencies.cmake file for each qt module.
Properties can only be queried from an imported target if it's in
the same scope or was promoted to global, otherwise you get
'non-existent target' errors.
4) for prl and pri file generation, where we need the targets to be
available during generator expression evaluation within the
relevant qt module directory scope
Here is a list of approaches I came up with on how to improve the
situation.
1) Make all imported targets global during the Qt build, by iterating
over the directory property IMPORTED_TARGETS and making each one
global.
Requires CMake 3.21.
Status: Already implemented for a long time, but is opt-in.
Pros: Relatively robust
Cons: Minimum CMake version for building Qt is 3.16.
2) Make all imported targets global during the Qt build using the
CMAKE_FIND_PACKAGE_TARGETS_GLOBAL variable.
Requires CMake 3.24.
Status: Not implemented, but can be set by Qt builders directly on
the command line.
Pros: Should be robust
Cons: Minimum CMake version for building Qt is 3.16.
3) Abandon the desire to have a single qt_find_package in a single
directory scope, and embrace the CMake-way of repeating the
dependency in each subdirectory that requires it.
Status: Not implemented.
Pros: Should be robust
Cons: A lot of qt_find_package duplication, will require rewriting
various code paths, QtPostProcess would have to be done at
directory scope, unclear if dependency tracking will still work
work reliably when there might be multiple same-named
directory-scoped targets, other unknown unknowns
4) Move all qt_find_package calls into a $repo_name/dependencies.cmake
file which would be read at project root scope. This would
potentially avoid all scoping issues, because all dependencies will
have to be specified at root scope.
Status: Not implemented.
Pros: No duplication
Cons: Dependencies are not scoped anymore to module directories,
won't be able to conditionally look for dependencies based on
module feature evaluation, not clear yet how this will tie into
standalone tests which are in tests/ subdir, other unknown unknowns
5) Try to promote as many 3rd party libraries at project root scope
as possible.
Currently we have 2 general locations where we look up
dependencies.
One is each qt_find_package call. The other is
Qt6FooDependencies.cmake ->
_qt_internal_find_third_party_dependencies().
Many 3rd party targets are created by
_qt_internal_find_third_party_dependencies() in the root scope, but
not promoted, and then we try to promote them in child scopes using
qt_find_package, which causes the promotion errors.
Starting with 58eefbd0b6169d0749b312268c1ae1e594e04362 and
37a5e001277db9e1392a242171ab2b88cb6c3049 we now record the provided
targets of previous qt_find_package calls.
So instead of waiting to try and promote targets later during the
configuration process, we can make sure we promote the targets at
_qt_internal_find_third_party_dependencies() call time, right
when we lookup the Qt dependencies of the qt repo, in the root
scope.
Status: Implemented in this change
Notably, we only promote 3rd party targets to global for qt builds,
and not user projects, to not accidentally break user project
behaviors.
Also, we only promote 3rd party targets, and not Qt internal
targets like Qt6::Core, Qt6::Platform, Qt6::PlatformCommonInternal,
Qt6::GlobalConfig, etc, for a few reasons:
- the code that requires targets to be global only cares about
3rd party targets
- promoting the internal targets is more prone to breaking, because
there is more than one place where find_package(Qt6Foo) might be
called, and if that ends up being in a different directory scope,
we encounter the same global promotion errors.
Some notable cases where this happens:
- tests/CMakeLists.txt brings in extra Qt packages via
StandaloneTestsConfig.cmake files
- qtbase standalone tests qt_internal_qtbase_pre_project_setup()
calls find_package(Qt6 COMPONENTS BuildInternals) which ends
up creating the Platform target in the root scope instead of
the tests/ scope
- Qt6::BundledLibpng links against Core, which ends up trying to
promote Core's internal dependencies Platform and GlobalConfig
To only promote 3rd party targets, we walk the dependencies of
an initial target recursively, and skip promoting targets that have
the _qt_is_internal_target or
_qt_should_skip_global_promotion_always properties set.
Pros: Improves the situation compared to the status quo
Cons: Still not ideal due to the various filtering of internal
targets and having to mark them as such.
6) Avoid promoting targets to global if we can detect that the target
was created in a different scope than where we are trying to
promote it.
We can do that by comparing the target's BINARY_DIR to the
CMAKE_CURRENT_BINARY_DIR and skip promotion if they are not equal.
Status: Not implemented, but we can consider it because it's
quick to do.
Pros: More robust than newly implemented approach (5)
Cons: Requires CMake 3.18, because trying to read the BINARY_DIR
property on an INTERFACE_LIBRARY would error out.
Also, if we implement it and make it the default when using 3.18+,
we might 'collect' a lot more hidden promotion errors that will
only be revealed later once someone uses CMake 3.16 or 3.17,
because most will probably use newer CMake versions.
Perhaps the trade-off is worth it?
Pick-to: 6.8
Fixes: QTBUG-89204
Fixes: QTBUG-94356
Fixes: QTBUG-95052
Fixes: QTBUG-98807
Fixes: QTBUG-125371
Change-Id: I088a17a98ef35aa69537a3ad208c61de40def581
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2024-07-01 17:10:26 +00:00
|
|
|
|
|
|
|
# The platform targets should never be promoted to global via the
|
|
|
|
# _qt_internal_promote_3rd_party_target_to_global command.
|
|
|
|
set_property(TARGET "${target}" PROPERTY _qt_should_skip_3rd_party_global_promotion TRUE)
|
|
|
|
set_property(TARGET "${target}" APPEND PROPERTY EXPORT_PROPERTIES
|
|
|
|
"_qt_should_skip_3rd_party_global_promotion")
|
2024-07-02 13:44:02 +00:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
# A small wrapper for adding the PlatformXInternal and GlobalConfig INTERFACE targets to apply
|
|
|
|
# common options.
|
|
|
|
# They can't be added via qt_internal_add_module, because it automatically links to the
|
|
|
|
# PlatformInternal targets creating a cyclic dependency.
|
|
|
|
function(qt_internal_add_platform_internal_target target)
|
|
|
|
qt_internal_add_platform_target("${target}")
|
|
|
|
qt_internal_mark_as_internal_library("${target}")
|
|
|
|
|
|
|
|
qt_internal_add_sbom("${target}"
|
|
|
|
TYPE QT_MODULE
|
|
|
|
IMMEDIATE_FINALIZATION
|
|
|
|
)
|
|
|
|
endfunction()
|
2025-08-07 02:12:26 +00:00
|
|
|
|
|
|
|
# A small wrapper for passing --dynamic-list to the linker. It will ensure that the symbols will
|
|
|
|
# be mangled when qt is compiled in a namespace
|
|
|
|
function(qt_internal_apply_dynamic_list_linker_flags target dynlist_template)
|
|
|
|
if(NOT (QT_FEATURE_reduce_relocations AND UNIX AND GCC))
|
|
|
|
return()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
string(REPLACE ".in" "" dynlist_file "${dynlist_template}")
|
|
|
|
set(dynlist_file_abspath "${CMAKE_CURRENT_BINARY_DIR}/${dynlist_file}")
|
|
|
|
|
|
|
|
if(QT_NAMESPACE)
|
|
|
|
set(QT_NAMESPACE_PREFIX "${QT_NAMESPACE}::")
|
|
|
|
set(QT_NAMESPACE_MANGLE_SUFFIX "_${QT_NAMESPACE}")
|
|
|
|
else()
|
|
|
|
set(QT_NAMESPACE_PREFIX "")
|
|
|
|
set(QT_NAMESPACE_MANGLE_SUFFIX "")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
configure_file(
|
|
|
|
"${dynlist_template}"
|
|
|
|
"${dynlist_file_abspath}"
|
|
|
|
)
|
|
|
|
|
|
|
|
qt_internal_extend_target(${target}
|
|
|
|
SOURCES
|
|
|
|
"${dynlist_template}"
|
|
|
|
"${dynlist_file_abspath}"
|
|
|
|
)
|
|
|
|
|
|
|
|
target_link_options(${target} PRIVATE "LINKER:--dynamic-list=${dynlist_file_abspath}")
|
|
|
|
endfunction()
|