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. Task-number: QTBUG-122899 Change-Id: I9c730a6bbc47e02ce1836fccf00a14ec8eb1a5f4 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io> Reviewed-by: Alexey Edelev <alexey.edelev@qt.io> (cherry picked from commit 37a5e001277db9e1392a242171ab2b88cb6c3049) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
445 lines
17 KiB
CMake
445 lines
17 KiB
CMake
# Copyright (C) 2022 The Qt Company Ltd.
|
|
# SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
# This function creates a CMake target for a generic console or GUI binary.
|
|
# Please consider to use a more specific version target like the one created
|
|
# by qt_add_test or qt_add_tool below.
|
|
# One-value Arguments:
|
|
# CORE_LIBRARY
|
|
# The argument accepts 'Bootstrap' or 'None' values. If the argument value is set to
|
|
# 'Bootstrap' the Qt::Bootstrap library is linked to the executable instead of Qt::Core.
|
|
# The 'None' value points that core library is not necessary and avoids linking neither
|
|
# Qt::Core or Qt::Bootstrap libraries. Otherwise the Qt::Core library will be publicly
|
|
# linked to the executable target by default.
|
|
function(qt_internal_add_executable name)
|
|
cmake_parse_arguments(PARSE_ARGV 1 arg
|
|
"${__qt_internal_add_executable_optional_args}"
|
|
"${__qt_internal_add_executable_single_args}"
|
|
"${__qt_internal_add_executable_multi_args}")
|
|
_qt_internal_validate_all_args_are_parsed(arg)
|
|
|
|
if ("x${arg_OUTPUT_DIRECTORY}" STREQUAL "x")
|
|
set(arg_OUTPUT_DIRECTORY "${QT_BUILD_DIR}/${INSTALL_BINDIR}")
|
|
endif()
|
|
|
|
get_filename_component(arg_OUTPUT_DIRECTORY "${arg_OUTPUT_DIRECTORY}"
|
|
ABSOLUTE BASE_DIR "${QT_BUILD_DIR}")
|
|
|
|
if ("x${arg_INSTALL_DIRECTORY}" STREQUAL "x")
|
|
set(arg_INSTALL_DIRECTORY "${INSTALL_BINDIR}")
|
|
endif()
|
|
|
|
_qt_internal_create_executable(${name})
|
|
qt_internal_mark_as_internal_target(${name})
|
|
if(ANDROID)
|
|
_qt_internal_android_executable_finalizer(${name})
|
|
endif()
|
|
|
|
if(arg_QT_APP AND QT_FEATURE_debug_and_release AND CMAKE_VERSION VERSION_GREATER_EQUAL "3.19.0")
|
|
set_property(TARGET "${name}"
|
|
PROPERTY EXCLUDE_FROM_ALL "$<NOT:$<CONFIG:${QT_MULTI_CONFIG_FIRST_CONFIG}>>")
|
|
endif()
|
|
|
|
if (arg_VERSION)
|
|
if(arg_VERSION MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+")
|
|
# nothing to do
|
|
elseif(arg_VERSION MATCHES "[0-9]+\\.[0-9]+\\.[0-9]+")
|
|
set(arg_VERSION "${arg_VERSION}.0")
|
|
elseif(arg_VERSION MATCHES "[0-9]+\\.[0-9]+")
|
|
set(arg_VERSION "${arg_VERSION}.0.0")
|
|
elseif (arg_VERSION MATCHES "[0-9]+")
|
|
set(arg_VERSION "${arg_VERSION}.0.0.0")
|
|
else()
|
|
message(FATAL_ERROR "Invalid version format")
|
|
endif()
|
|
endif()
|
|
|
|
if(arg_DELAY_TARGET_INFO)
|
|
# Delay the setting of target info properties if requested. Needed for scope finalization
|
|
# of Qt apps.
|
|
set_target_properties("${name}" PROPERTIES
|
|
QT_DELAYED_TARGET_VERSION "${arg_VERSION}"
|
|
QT_DELAYED_TARGET_PRODUCT "${arg_TARGET_PRODUCT}"
|
|
QT_DELAYED_TARGET_DESCRIPTION "${arg_TARGET_DESCRIPTION}"
|
|
QT_DELAYED_TARGET_COMPANY "${arg_TARGET_COMPANY}"
|
|
QT_DELAYED_TARGET_COPYRIGHT "${arg_TARGET_COPYRIGHT}"
|
|
)
|
|
else()
|
|
if(NOT arg_TARGET_DESCRIPTION)
|
|
set(arg_TARGET_DESCRIPTION "Qt ${name}")
|
|
endif()
|
|
qt_set_target_info_properties(${name} ${ARGN}
|
|
TARGET_DESCRIPTION ${arg_TARGET_DESCRIPTION}
|
|
TARGET_VERSION ${arg_VERSION})
|
|
endif()
|
|
|
|
if (WIN32 AND NOT arg_DELAY_RC)
|
|
_qt_internal_generate_win32_rc_file(${name})
|
|
endif()
|
|
|
|
qt_set_common_target_properties(${name})
|
|
|
|
qt_internal_add_repo_local_defines(${name})
|
|
|
|
if(ANDROID)
|
|
# The above call to qt_set_common_target_properties() sets the symbol
|
|
# visibility to hidden, but for Android, we need main() to not be hidden
|
|
# because it has to be loadable at runtime using dlopen().
|
|
set_property(TARGET ${name} PROPERTY C_VISIBILITY_PRESET default)
|
|
set_property(TARGET ${name} PROPERTY CXX_VISIBILITY_PRESET default)
|
|
endif()
|
|
|
|
qt_autogen_tools_initial_setup(${name})
|
|
qt_skip_warnings_are_errors_when_repo_unclean("${name}")
|
|
|
|
set(extra_libraries "")
|
|
if(arg_CORE_LIBRARY STREQUAL "Bootstrap")
|
|
list(APPEND extra_libraries ${QT_CMAKE_EXPORT_NAMESPACE}::Bootstrap)
|
|
elseif(NOT arg_CORE_LIBRARY STREQUAL "None")
|
|
list(APPEND extra_libraries ${QT_CMAKE_EXPORT_NAMESPACE}::Core)
|
|
endif()
|
|
|
|
set(private_includes
|
|
"${CMAKE_CURRENT_SOURCE_DIR}"
|
|
"${CMAKE_CURRENT_BINARY_DIR}"
|
|
${arg_INCLUDE_DIRECTORIES}
|
|
)
|
|
|
|
if(arg_PUBLIC_LIBRARIES)
|
|
message(WARNING
|
|
"qt_internal_add_executable's PUBLIC_LIBRARIES option is deprecated, and will be "
|
|
"removed in a future Qt version. Use the LIBRARIES option instead.")
|
|
endif()
|
|
|
|
if(arg_NO_UNITY_BUILD)
|
|
set(arg_NO_UNITY_BUILD "NO_UNITY_BUILD")
|
|
else()
|
|
set(arg_NO_UNITY_BUILD "")
|
|
endif()
|
|
|
|
qt_internal_extend_target("${name}"
|
|
${arg_NO_UNITY_BUILD}
|
|
SOURCES ${arg_SOURCES}
|
|
NO_PCH_SOURCES ${arg_NO_PCH_SOURCES}
|
|
NO_UNITY_BUILD_SOURCES ${arg_NO_UNITY_BUILD_SOURCES}
|
|
INCLUDE_DIRECTORIES ${private_includes}
|
|
DEFINES ${arg_DEFINES}
|
|
LIBRARIES
|
|
${arg_LIBRARIES}
|
|
${arg_PUBLIC_LIBRARIES}
|
|
Qt::PlatformCommonInternal
|
|
${extra_libraries}
|
|
DBUS_ADAPTOR_SOURCES ${arg_DBUS_ADAPTOR_SOURCES}
|
|
DBUS_ADAPTOR_FLAGS ${arg_DBUS_ADAPTOR_FLAGS}
|
|
DBUS_INTERFACE_SOURCES ${arg_DBUS_INTERFACE_SOURCES}
|
|
DBUS_INTERFACE_FLAGS ${arg_DBUS_INTERFACE_FLAGS}
|
|
COMPILE_OPTIONS ${arg_COMPILE_OPTIONS}
|
|
LINK_OPTIONS ${arg_LINK_OPTIONS}
|
|
MOC_OPTIONS ${arg_MOC_OPTIONS}
|
|
ENABLE_AUTOGEN_TOOLS ${arg_ENABLE_AUTOGEN_TOOLS}
|
|
DISABLE_AUTOGEN_TOOLS ${arg_DISABLE_AUTOGEN_TOOLS}
|
|
ATTRIBUTION_ENTRY_INDEX "${arg_ATTRIBUTION_ENTRY_INDEX}"
|
|
ATTRIBUTION_FILE_PATHS ${arg_ATTRIBUTION_FILE_PATHS}
|
|
ATTRIBUTION_FILE_DIR_PATHS ${arg_ATTRIBUTION_FILE_DIR_PATHS}
|
|
SBOM_DEPENDENCIES ${arg_SBOM_DEPENDENCIES}
|
|
)
|
|
set_target_properties("${name}" PROPERTIES
|
|
RUNTIME_OUTPUT_DIRECTORY "${arg_OUTPUT_DIRECTORY}"
|
|
LIBRARY_OUTPUT_DIRECTORY "${arg_OUTPUT_DIRECTORY}"
|
|
WIN32_EXECUTABLE "${arg_GUI}"
|
|
MACOSX_BUNDLE "${arg_GUI}"
|
|
)
|
|
|
|
qt_internal_set_exceptions_flags("${name}" ${arg_EXCEPTIONS})
|
|
|
|
if(WASM)
|
|
qt_internal_wasm_add_finalizers("${name}")
|
|
endif()
|
|
|
|
# Check if target needs to be excluded from all target. Also affects qt_install.
|
|
# Set by qt_exclude_tool_directories_from_default_target.
|
|
set(exclude_from_all FALSE)
|
|
if(__qt_exclude_tool_directories)
|
|
foreach(absolute_dir ${__qt_exclude_tool_directories})
|
|
string(FIND "${CMAKE_CURRENT_SOURCE_DIR}" "${absolute_dir}" dir_starting_pos)
|
|
if(dir_starting_pos EQUAL 0)
|
|
set(exclude_from_all TRUE)
|
|
set_target_properties("${name}" PROPERTIES EXCLUDE_FROM_ALL TRUE)
|
|
break()
|
|
endif()
|
|
endforeach()
|
|
endif()
|
|
|
|
if(NOT arg_NO_INSTALL)
|
|
set(additional_install_args "")
|
|
if(exclude_from_all)
|
|
list(APPEND additional_install_args EXCLUDE_FROM_ALL COMPONENT "ExcludedExecutables")
|
|
endif()
|
|
|
|
qt_get_cmake_configurations(cmake_configs)
|
|
foreach(cmake_config ${cmake_configs})
|
|
qt_get_install_target_default_args(
|
|
OUT_VAR install_targets_default_args
|
|
CMAKE_CONFIG "${cmake_config}"
|
|
ALL_CMAKE_CONFIGS ${cmake_configs}
|
|
RUNTIME "${arg_INSTALL_DIRECTORY}"
|
|
LIBRARY "${arg_INSTALL_DIRECTORY}"
|
|
BUNDLE "${arg_INSTALL_DIRECTORY}")
|
|
|
|
# Make installation optional for targets that are not built by default in this config
|
|
if(NOT exclude_from_all AND arg_QT_APP AND QT_FEATURE_debug_and_release
|
|
AND NOT (cmake_config STREQUAL QT_MULTI_CONFIG_FIRST_CONFIG))
|
|
set(install_optional_arg "OPTIONAL")
|
|
else()
|
|
unset(install_optional_arg)
|
|
endif()
|
|
|
|
qt_install(TARGETS "${name}"
|
|
${additional_install_args} # Needs to be before the DESTINATIONS.
|
|
${install_optional_arg}
|
|
CONFIGURATIONS ${cmake_config}
|
|
${install_targets_default_args})
|
|
endforeach()
|
|
|
|
if(NOT exclude_from_all AND arg_QT_APP AND QT_FEATURE_debug_and_release)
|
|
set(separate_debug_info_executable_arg "QT_EXECUTABLE")
|
|
else()
|
|
unset(separate_debug_info_executable_arg)
|
|
endif()
|
|
qt_enable_separate_debug_info(${name} "${arg_INSTALL_DIRECTORY}"
|
|
${separate_debug_info_executable_arg}
|
|
ADDITIONAL_INSTALL_ARGS ${additional_install_args})
|
|
qt_internal_install_pdb_files(${name} "${arg_INSTALL_DIRECTORY}")
|
|
endif()
|
|
endfunction()
|
|
|
|
# This function compiles the target at configure time the very first time and creates the custom
|
|
# ${target}_build that re-runs compilation at build time if necessary. The resulting executable is
|
|
# imported under the provided target name. This function should only be used to compile tiny
|
|
# executables with system dependencies only.
|
|
# One-value Arguments:
|
|
# CMAKELISTS_TEMPLATE
|
|
# The CMakeLists.txt templated that is used to configure the project
|
|
# for an executable. By default the predefined template from the Qt installation is used.
|
|
# INSTALL_DIRECTORY
|
|
# installation directory of the executable. Ignored if NO_INSTALL is set.
|
|
# OUTPUT_NAME
|
|
# the output name of an executable
|
|
# CONFIG
|
|
# the name of configuration that tool needs to be build with.
|
|
# Multi-value Arguments:
|
|
# PACKAGES
|
|
# list of system packages are required to successfully build the project.
|
|
# INCLUDES
|
|
# list of include directories are required to successfully build the project.
|
|
# DEFINES
|
|
# list of definitions are required to successfully build the project.
|
|
# COMPILE_OPTIONS
|
|
# list of compiler options are required to successfully build the project.
|
|
# LINK_OPTIONS
|
|
# list of linker options are required to successfully build the project.
|
|
# SOURCES
|
|
# list of project sources.
|
|
# CMAKE_FLAGS
|
|
# specify flags of the form -DVAR:TYPE=VALUE to be passed to the cmake command-line used to
|
|
# drive the test build.
|
|
# Options:
|
|
# WIN32
|
|
# reflects the corresponding add_executable argument.
|
|
# MACOSX_BUNDLE
|
|
# reflects the corresponding add_executable argument.
|
|
# NO_INSTALL
|
|
# avoids installing the tool.
|
|
function(qt_internal_add_configure_time_executable target)
|
|
set(one_value_args
|
|
CMAKELISTS_TEMPLATE
|
|
INSTALL_DIRECTORY
|
|
OUTPUT_NAME
|
|
CONFIG
|
|
)
|
|
set(multi_value_args
|
|
PACKAGES
|
|
INCLUDES
|
|
DEFINES
|
|
COMPILE_OPTIONS
|
|
LINK_OPTIONS
|
|
SOURCES
|
|
CMAKE_FLAGS
|
|
)
|
|
set(option_args WIN32 MACOSX_BUNDLE NO_INSTALL)
|
|
cmake_parse_arguments(PARSE_ARGV 1 arg
|
|
"${option_args}" "${one_value_args}" "${multi_value_args}")
|
|
|
|
set(target_binary_dir "${CMAKE_CURRENT_BINARY_DIR}/configure_time_bins")
|
|
if(arg_CONFIG)
|
|
set(CMAKE_TRY_COMPILE_CONFIGURATION "${arg_CONFIG}")
|
|
string(TOUPPER "_${arg_CONFIG}" config_suffix)
|
|
endif()
|
|
|
|
get_cmake_property(is_multi_config GENERATOR_IS_MULTI_CONFIG)
|
|
if(is_multi_config AND CMAKE_TRY_COMPILE_CONFIGURATION)
|
|
set(configuration_path "${CMAKE_TRY_COMPILE_CONFIGURATION}/")
|
|
set(config_build_arg "--config" "${CMAKE_TRY_COMPILE_CONFIGURATION}")
|
|
endif()
|
|
|
|
set(configure_time_target "${target}")
|
|
if(arg_OUTPUT_NAME)
|
|
set(configure_time_target "${arg_OUTPUT_NAME}")
|
|
endif()
|
|
set(target_binary "${configure_time_target}${CMAKE_EXECUTABLE_SUFFIX}")
|
|
|
|
set(install_dir "${INSTALL_BINDIR}")
|
|
if(arg_INSTALL_DIRECTORY)
|
|
set(install_dir "${arg_INSTALL_DIRECTORY}")
|
|
endif()
|
|
|
|
set(output_directory_relative "${install_dir}")
|
|
set(output_directory "${QT_BUILD_DIR}/${install_dir}")
|
|
|
|
set(target_binary_path_relative
|
|
"${output_directory_relative}/${configuration_path}${target_binary}")
|
|
set(target_binary_path
|
|
"${output_directory}/${configuration_path}${target_binary}")
|
|
|
|
get_filename_component(target_binary_path "${target_binary_path}" ABSOLUTE)
|
|
|
|
if(NOT DEFINED arg_SOURCES)
|
|
message(FATAL_ERROR "No SOURCES given to target: ${target}")
|
|
endif()
|
|
set(sources "${arg_SOURCES}")
|
|
|
|
# Timestamp file is required because CMake ignores 'add_custom_command' if we use only the
|
|
# binary file as the OUTPUT.
|
|
set(timestamp_file "${target_binary_dir}/${target_binary}_timestamp")
|
|
add_custom_command(OUTPUT "${target_binary_path}" "${timestamp_file}"
|
|
COMMAND
|
|
${CMAKE_COMMAND} --build "${target_binary_dir}" --clean-first ${config_build_arg}
|
|
COMMAND
|
|
${CMAKE_COMMAND} -E touch "${timestamp_file}"
|
|
DEPENDS
|
|
${sources}
|
|
COMMENT
|
|
"Compiling ${target}"
|
|
VERBATIM
|
|
)
|
|
|
|
add_custom_target(${target}_build ALL
|
|
DEPENDS
|
|
"${target_binary_path}"
|
|
"${timestamp_file}"
|
|
)
|
|
|
|
set(should_build_at_configure_time TRUE)
|
|
if(QT_INTERNAL_HAVE_CONFIGURE_TIME_${target} AND
|
|
EXISTS "${target_binary_path}" AND EXISTS "${timestamp_file}")
|
|
set(last_ts 0)
|
|
foreach(source IN LISTS sources)
|
|
file(TIMESTAMP "${source}" ts "%s")
|
|
if(${ts} GREATER ${last_ts})
|
|
set(last_ts ${ts})
|
|
endif()
|
|
endforeach()
|
|
|
|
file(TIMESTAMP "${target_binary_path}" ts "%s")
|
|
if(${ts} GREATER_EQUAL ${last_ts})
|
|
set(should_build_at_configure_time FALSE)
|
|
endif()
|
|
endif()
|
|
|
|
set(cmake_flags_arg "")
|
|
if(arg_CMAKE_FLAGS)
|
|
set(cmake_flags_arg CMAKE_FLAGS "${arg_CMAKE_FLAGS}")
|
|
endif()
|
|
|
|
qt_internal_get_enabled_languages_for_flag_manipulation(enabled_languages)
|
|
foreach(lang IN LISTS enabled_languages)
|
|
set(compiler_flags_var "CMAKE_${lang}_FLAGS")
|
|
list(APPEND cmake_flags_arg "-D${compiler_flags_var}:STRING=${${compiler_flags_var}}")
|
|
if(arg_CONFIG)
|
|
set(compiler_flags_var_config "${compiler_flags_var}${config_suffix}")
|
|
list(APPEND cmake_flags_arg
|
|
"-D${compiler_flags_var_config}:STRING=${${compiler_flags_var_config}}")
|
|
endif()
|
|
endforeach()
|
|
|
|
qt_internal_get_target_link_types_for_flag_manipulation(target_link_types)
|
|
foreach(linker_type IN LISTS target_link_types)
|
|
set(linker_flags_var "CMAKE_${linker_type}_LINKER_FLAGS")
|
|
list(APPEND cmake_flags_arg "-D${linker_flags_var}:STRING=${${linker_flags_var}}")
|
|
if(arg_CONFIG)
|
|
set(linker_flags_var_config "${linker_flags_var}${config_suffix}")
|
|
list(APPEND cmake_flags_arg
|
|
"-D${linker_flags_var_config}:STRING=${${linker_flags_var_config}}")
|
|
endif()
|
|
endforeach()
|
|
|
|
if(NOT "${QT_INTERNAL_CMAKE_FLAGS_CONFIGURE_TIME_TOOL_${target}}" STREQUAL "${cmake_flags_arg}")
|
|
set(should_build_at_configure_time TRUE)
|
|
endif()
|
|
|
|
if(should_build_at_configure_time)
|
|
foreach(arg IN LISTS multi_value_args)
|
|
string(TOLOWER "${arg}" template_arg_name)
|
|
set(${template_arg_name} "")
|
|
if(DEFINED arg_${arg})
|
|
set(${template_arg_name} "${arg_${arg}}")
|
|
endif()
|
|
endforeach()
|
|
|
|
foreach(arg IN LISTS option_args)
|
|
string(TOLOWER "${arg}" template_arg_name)
|
|
set(${template_arg_name} "")
|
|
if(arg_${arg})
|
|
set(${template_arg_name} "${arg}")
|
|
endif()
|
|
endforeach()
|
|
|
|
file(MAKE_DIRECTORY "${target_binary_dir}")
|
|
set(template "${QT_CMAKE_DIR}/QtConfigureTimeExecutableCMakeLists.txt.in")
|
|
if(DEFINED arg_CMAKELISTS_TEMPLATE)
|
|
set(template "${arg_CMAKELISTS_TEMPLATE}")
|
|
endif()
|
|
|
|
configure_file("${template}" "${target_binary_dir}/CMakeLists.txt" @ONLY)
|
|
|
|
if(EXISTS "${target_binary_dir}/CMakeCache.txt")
|
|
file(REMOVE "${target_binary_dir}/CMakeCache.txt")
|
|
endif()
|
|
|
|
try_compile(result
|
|
"${target_binary_dir}"
|
|
"${target_binary_dir}"
|
|
${target}
|
|
${cmake_flags_arg}
|
|
OUTPUT_VARIABLE try_compile_output
|
|
)
|
|
|
|
set(QT_INTERNAL_CMAKE_FLAGS_CONFIGURE_TIME_TOOL_${target}
|
|
"${cmake_flags_arg}" CACHE INTERNAL "")
|
|
|
|
file(WRITE "${timestamp_file}" "")
|
|
set(QT_INTERNAL_HAVE_CONFIGURE_TIME_${target} ${result} CACHE INTERNAL
|
|
"Indicates that the configure-time target ${target} was built")
|
|
if(NOT result)
|
|
message(FATAL_ERROR "Unable to build ${target}: ${try_compile_output}")
|
|
endif()
|
|
endif()
|
|
|
|
add_executable(${target} IMPORTED GLOBAL)
|
|
add_executable(${QT_CMAKE_EXPORT_NAMESPACE}::${target} ALIAS ${target})
|
|
set_target_properties(${target} PROPERTIES
|
|
_qt_internal_configure_time_target TRUE
|
|
_qt_internal_configure_time_target_build_location "${target_binary_path_relative}"
|
|
IMPORTED_LOCATION "${target_binary_path}"
|
|
)
|
|
|
|
if(NOT arg_NO_INSTALL)
|
|
set_target_properties(${target} PROPERTIES
|
|
_qt_internal_configure_time_target_install_location
|
|
"${install_dir}/${target_binary}"
|
|
)
|
|
qt_path_join(target_install_dir ${QT_INSTALL_DIR} ${install_dir})
|
|
qt_install(PROGRAMS "${target_binary_path}" DESTINATION "${target_install_dir}")
|
|
endif()
|
|
endfunction()
|