From af623abc586091293fba6a47fad6392e1c5fc61b Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Mon, 26 May 2025 15:54:25 +0200 Subject: [PATCH] CMake: Skip sbom file checksum checks for excluded test targets If a developer configured Qt with -DQT_GENERATE_SBOM=ON -DQT_BUILD_TESTS=ON -DQT_BUILD_TESTS_BY_DEFAULT=OFF The would get the following error upon installation of qtmultimedia: CMake Error at qt_sbom/SPDXRef-PackagedFile-qt-plugin-MockMultimediaPlugin.cmake:5 (message): Cannot find 'plugins/multimedia/libmockmultimediaplugin.a' to compute its checksum. This happens because QT_BUILD_TESTS_BY_DEFAULT == ON sets the EXCLUDE_FROM_ALL directory property on the tests directory, which means all plugins created under tests/ subdir are not installed by default, and the SBOM code could not read the installed files to check the checksums. In such a case, set a QT_INTERNAL_TEST_TARGETS_EXCLUDE_FROM_ALL directory-scoped variable in the tests/ subdir, and use that as a marker for the sbom code to know it should skip the checksum check. Pick-to: 6.8 Fixes: QTBUG-137168 Change-Id: I970c3bc5732cc648549e5099fa1d50b3b39cb26f Reviewed-by: Alexey Edelev (cherry picked from commit d2ed84514d935aea412b6944866aeb41aa97ea89) Reviewed-by: Qt Cherry-pick Bot --- cmake/QtBuildRepoHelpers.cmake | 7 +++++++ cmake/QtPublicSbomFileHelpers.cmake | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cmake/QtBuildRepoHelpers.cmake b/cmake/QtBuildRepoHelpers.cmake index fc8945d4c9c..bca25233365 100644 --- a/cmake/QtBuildRepoHelpers.cmake +++ b/cmake/QtBuildRepoHelpers.cmake @@ -756,6 +756,13 @@ macro(qt_build_tests) # Indicates that we are configuring tests now set(QT_INTERNAL_CONFIGURING_TESTS TRUE) + # Set this as a directory scoped variable, so we can easily check the variable in child + # directories, to prevent certain code from running, like sbom file checks for all targets + # created in tests subdir. + if(NOT QT_BUILD_TESTS_BY_DEFAULT) + set(QT_INTERNAL_TEST_TARGETS_EXCLUDE_FROM_ALL TRUE) + endif() + # Tests are not unity-ready. set(CMAKE_UNITY_BUILD OFF) diff --git a/cmake/QtPublicSbomFileHelpers.cmake b/cmake/QtPublicSbomFileHelpers.cmake index db9ee95499c..c8a8c5f7c2c 100644 --- a/cmake/QtPublicSbomFileHelpers.cmake +++ b/cmake/QtPublicSbomFileHelpers.cmake @@ -93,8 +93,8 @@ function(_qt_internal_sbom_handle_target_binary_files target) return() endif() - get_target_property(excluded ${target} _qt_internal_excluded_from_default_target) - if(excluded) + get_target_property(excluded_via_property ${target} _qt_internal_excluded_from_default_target) + if(excluded_via_property OR QT_INTERNAL_TEST_TARGETS_EXCLUDE_FROM_ALL) message(DEBUG "Target ${target} has no binary files to reference in the SBOM " "because it was excluded from the default 'all' target.") return()