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>
27 KiB
27 KiB
The following table describes the mapping of configure options to CMake arguments.
configure | cmake | Notes |
---|---|---|
-prefix /opt/qt6 | -DCMAKE_INSTALL_PREFIX=/opt/qta6 | |
-no-prefix (only available in Qt6) | -DCMAKE_INSTALL_PREFIX=$PWD (with bash) | In Qt5 this was done by specifying -prefix $PWD |
or -DFEATURE_no_prefix=ON | ||
-extprefix /opt/qt6 | -DCMAKE_STAGING_PREFIX=/opt/qt6 | |
-bindir | -DINSTALL_BINDIR= | similar for -headerdir -libdir and so on |
-hostdatadir | -DINSTALL_MKSPECSDIR= | |
-qt-host-path | -DQT_HOST_PATH= | |
-help | n/a | Handled by configure[.bat]. |
-verbose | --log-level=STATUS | Sets the CMake log level to STATUS. The default one is NOTICE. |
-continue | ||
-redo | n/a | Handled by configure[.bat]. |
-recheck [test,...] | ||
-feature-foo | -DFEATURE_foo=ON | |
-no-feature-foo | -DFEATURE_foo=OFF | |
-list-features | At the moment: configure with cmake once, | |
then use ccmake or cmake-gui to inspect the features. | ||
-opensource | n/a | |
-commercial | n/a | |
-confirm-license | n/a | |
-release | -DCMAKE_BUILD_TYPE=Release | |
-debug | -DCMAKE_BUILD_TYPE=Debug | |
-debug-and-release | -G "Ninja Multi-Config" | |
-DCMAKE_CONFIGURATION_TYPES=Release;Debug | ||
-optimize-debug | -DFEATURE_optimize_debug=ON | |
-optimize-size | -DFEATURE_optimize_size=ON | |
-optimized-tools | n/a | This affects only host tools. |
-force-debug-info | Use the RelWithDebInfo build config. | |
-separate-debug-info | -DFEATURE_separate_debug_info=ON | |
-gdb-index | -DFEATURE_enable_gdb_index=ON | |
-strip | cmake --install . --strip | This affects the install targets generated by qmake. |
-gc-binaries | -DFEATURE_gc_binaries=ON | |
-force-asserts | -DFEATURE_force_asserts=ON | |
-developer-build | -DFEATURE_developer_build=ON | |
-shared | -DBUILD_SHARED_LIBS=ON | |
-static | -DBUILD_SHARED_LIBS=OFF | |
-framework | -DFEATURE_framework=ON | |
-platform | -DQT_QMAKE_TARGET_MKSPEC= | |
-xplatform | -DQT_QMAKE_TARGET_MKSPEC= | Used for generating qmake-compatibility files. |
If passed 'macx-ios-clang', will configure an iOS build. | ||
-device | equivalent to -xplatform devices/ | |
-device-option <key=value> | -DQT_QMAKE_DEVICE_OPTIONS=key1=value1;key2=value2 | Only used for generation qmake-compatibility files. |
The device options are written into mkspecs/qdevice.pri. | ||
-appstore-compliant | -DFEATURE_appstore_compliant=ON | |
-sbom | -DQT_GENERATE_SBOM=ON | Enables generation and installation of an SBOM |
-qtinlinenamespace | -DQT_INLINE_NAMESPACE=ON | Make the namespace specified by -qtnamespace an inline one. |
-qtnamespace | -DQT_NAMESPACE= | |
-qtlibinfix | -DQT_LIBINFIX= | |
-coverage | -DINPUT_coverage= | Enables code coverage using the specified tool. |
-gcov | -DINPUT_coverage=gcov | Enables code coverage using the gcov tool. |
-trace [backend] | -DINPUT_trace=yes or -DINPUT_trace= | |
or -DFEATURE_ | ||
-sanitize address -sanitize undefined | -DFEATURE_sanitize_address=ON | Directly setting -DECM_ENABLE_SANITIZERS=foo is not supported |
-DFEATURE_sanitize_undefined=ON | ||
-c++std c++20 | -DFEATURE_cxx20=ON | |
-sse2/-sse3/-ssse3/-sse4.1 | -DFEATURE_sse4=ON | |
-mips_dsp/-mips_dspr2 | -DFEATURE_mips_dsp=ON | |
-qreal | -DQT_COORD_TYPE= | |
-R | -DQT_EXTRA_RPATHS=path1;path2 | |
-rpath | negative CMAKE_SKIP_BUILD_RPATH | |
negative CMAKE_SKIP_INSTALL_RPATH | ||
negative CMAKE_MACOSX_RPATH | ||
-reduce-exports | -DFEATURE_reduce_exports=ON | |
-reduce-relocations | -DFEATURE_reduce_relocations=ON | |
-plugin-manifests | ||
-static-runtime | -DFEATURE_static_runtime=ON | |
-pch | -DBUILD_WITH_PCH=ON | |
-ltcg | -DCMAKE_INTERPROCEDURAL_OPTIMIZATION=ON or | |
-DCMAKE_INTERPROCEDURAL_OPTIMIZATION_=ON | ||
-linker [bfd,gold,lld,mold] | -DINPUT_linker= or | |
-DFEATURE_use__linker=ON | ||
-incredibuild-xge | n/a | This option enables remote distribution of Visual Studio |
custom build steps for moc, uic, and rcc. | ||
This lacks support in CMake. | ||
-ccache | -DQT_USE_CCACHE=ON | |
-unity-build | -DQT_UNITY_BUILD=ON | |
-unity-build-batch-size | -DQT_UNITY_BUILD_BATCH_SIZE= | |
-warnings-are-errors | -DWARNINGS_ARE_ERRORS=ON | |
-no-pkg-config | -DFEATURE_pkg_config=OFF | |
-vcpkg | -DQT_USE_VCPKG=ON | |
-D | -DQT_EXTRA_DEFINES=; | |
-I | -DQT_EXTRA_INCLUDEPATHS=; | |
-L | -DQT_EXTRA_LIBDIRS=; | |
-F | -DQT_EXTRA_FRAMEWORKPATHS=; | |
-sdk | -DQT_APPLE_SDK= | Should be provided a value like 'iphoneos' or 'iphonesimulator' |
If no value is provided, a simulator_and_device build is | ||
assumed. | ||
-android-sdk | -DANDROID_SDK_ROOT= | |
-android-ndk | -DCMAKE_TOOLCHAIN_FILE= | |
-android-ndk-platform android-28 | -DANDROID_PLATFORM=android-28 | |
-android-abis <abi_1>,...,<abi_n> | -DANDROID_ABI=<abi_1> | only one ABI can be specified |
-android-style-assets | -DFEATURE_android_style_assets=ON | |
-android-javac-source | -DQT_ANDROID_JAVAC_SOURCE=7 | Set the javac build source version. |
-android-javac-target | -DQT_ANDROID_JAVAC_TARGET=7 | Set the javac build target version. |
-skip ,...,<repo_n> | -DBUILD_=OFF | |
-skip-tests ,...,<repo_n> | -DQT_BUILD_TESTS_PROJECT_=OFF | |
-skip-examples ,...,<repo_n> | -DQT_BUILD_EXAMPLES_PROJECT_=OFF | |
-submodules ,...,<repo_n> | -DQT_BUILD_SUBMODULES=;...; | |
-make | -DQT_BUILD_TESTS=ON | A way to turn on tools explicitly is missing. If tests/examples |
-DQT_BUILD_EXAMPLES=ON | are enabled, you can disable their building as part of the | |
'all' target by also passing -DQT_BUILD_TESTS_BY_DEFAULT=OFF or | ||
-DQT_BUILD_EXAMPLES_BY_DEFAULT=OFF. Note that if you entirely | ||
disable tests/examples at configure time (by using | ||
-DQT_BUILD_TESTS=OFF or -DQT_BUILD_EXAMPLES=OFF) you can't then | ||
build them separately, after configuration. | ||
-nomake | -DQT_BUILD_TESTS=OFF | A way to turn off tools explicitly is missing. |
-DQT_BUILD_EXAMPLES=OFF | ||
-install-examples-sources | -DQT_INSTALL_EXAMPLES_SOURCES=ON | |
-no-gui | -DFEATURE_gui=OFF | |
-no-widgets | -DFEATURE_widgets=OFF | |
-no-dbus | -DFEATURE_dbus=OFF | |
-dbus [linked/runtime] | -DINPUT_dbus=[linked/runtime] | |
-dbus-linked | -DINPUT_dbus=linked | |
-dbus-runtime | -DINPUT_dbus=runtime | |
-accessibility | -DFEATURE_accessibility=ON | |
-doubleconversion | -DFEATURE_doubleconversion=ON | |
-DFEATURE_system_doubleconversion=ON/OFF | ||
-glib | -DFEATURE_glib=ON | |
-inotify | -DFEATURE_inotify=ON | |
-icu | -DFEATURE_icu=ON | |
-pcre | -DFEATURE_pcre2=ON | |
-pcre [system/qt] | -DFEATURE_system_pcre2=ON/OFF | |
-pps | n/a | QNX feature. Not available for 6.0. |
-zlib [system/qt] | -DFEATURE_system_zlib=ON/OFF | |
-ssl | -DFEATURE_ssl=ON | |
-openssl [no/yes/linked/runtime] | -DINPUT_openssl=no/yes/linked/runtime | |
-openssl-linked | -DINPUT_openssl=linked | |
-openssl-runtime | -DINPUT_openssl=runtime | |
-schannel | -DFEATURE_schannel=ON | |
-securetransport | -DFEATURE_securetransport=ON | |
-sctp | -DFEATURE_sctp=ON | |
-libproxy | -DFEATURE_libproxy=ON | |
-system-proxies | -DFEATURE_system_proxies=ON | |
-cups | -DFEATURE_cups=ON | |
-fontconfig | -DFEATURE_fontconfig=ON | |
-freetype [no/qt/system] | -DFEATURE_freetype=ON/OFF | |
-DFEATURE_system_freetype=ON/OFF | ||
-harfbuzz [no/qt/system] | -DFEATURE_harfbuzz=ON | |
-DFEATURE_system_harfbuzz=ON/OFF | ||
-gtk | -DFEATURE_gtk3=ON | |
-lgmon | n/a | QNX-specific |
-no-opengl | -DINPUT_opengl=no | |
-opengl | -DINPUT_opengl= | |
-opengles3 | -DFEATURE_opengles3=ON | |
-egl | -DFEATURE_egl=ON | |
-qpa ;...;<name_n> | -DQT_QPA_PLATFORMS=;...;<name_n> | |
-default-qpa | -DQT_QPA_DEFAULT_PLATFORM= | |
-xcb-xlib | -DFEATURE_xcb_xlib=ON | |
-direct2d | -DFEATURE_direct2d=ON | |
-directfb | -DFEATURE_directfb=ON | |
-eglfs | -DFEATURE_eglfs=ON | |
-gbm | -DFEATURE_gbm=ON | |
-kms | -DFEATURE_kms=ON | |
-linuxfb | -DFEATURE_linuxfb=ON | |
-xcb | -DFEATURE_xcb=ON | |
-libudev | -DFEATURE_libudev=ON | |
-evdev | -DFEATURE_evdev=ON | |
-imf | n/a | QNX-specific |
-libinput | -DFEATURE_libinput=ON | |
-mtdev | -DFEATURE_mtdev=ON | |
-tslib | -DFEATURE_tslib=ON | |
-bundled-xcb-xinput | -DFEATURE_system_xcb_xinput=OFF | |
-xkbcommon | -DFEATURE_xkbcommon=ON | |
-gif | -DFEATURE_gif=ON | |
-ico | -DFEATURE_ico=ON | |
-libpng | -DFEATURE_png=ON | |
-libjpeg | -DFEATURE_jpeg=ON | |
-sql- | -DFEATURE_sql_=ON | |
-sqlite [qt/system] | -DFEATURE_system_sqlite=OFF/ON | |
-disable-deprecated-up-to <hex_version> | -DQT_DISABLE_DEPRECATED_UP_TO=<hex_version> | |
-mimetype-database-compression | -DINPUT_mimetype_database_compression= | Sets the compression type for mime type database. Supported |
types: gzip, zstd, none. |