CMake: Skip handling binary files in SBOM for excluded targets

If a target has the _qt_internal_excluded_from_default_target property
set, don't try to add file SBOM information for the target, because
the file will not be built nor installed by default.

We check for a new custom _qt_internal_excluded_from_default_target
property instead of EXCLUDE_FROM_ALL, because EXCLUDE_FROM_ALL might
be set to a genex that excludes all configs except the main one, but
we are interested whether the target is entirely excluded.

Task-number: QTBUG-122899
Change-Id: I79d6a4b0c65356da14f7ff50ee3639705f5fabbd
Reviewed-by:  Alexey Edelev <alexey.edelev@qt.io>
(cherry picked from commit 34b5dc041b0d34a76c081719fafa8f48265e34ae)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Alexandru Croitor 2024-06-21 16:25:05 +02:00 committed by Qt Cherry-pick Bot
parent 62f86062d4
commit cbc03bd5ba
2 changed files with 11 additions and 1 deletions

View File

@ -159,7 +159,10 @@ function(qt_internal_add_executable name)
string(FIND "${CMAKE_CURRENT_SOURCE_DIR}" "${absolute_dir}" dir_starting_pos) string(FIND "${CMAKE_CURRENT_SOURCE_DIR}" "${absolute_dir}" dir_starting_pos)
if(dir_starting_pos EQUAL 0) if(dir_starting_pos EQUAL 0)
set(exclude_from_all TRUE) set(exclude_from_all TRUE)
set_target_properties("${name}" PROPERTIES EXCLUDE_FROM_ALL TRUE) set_target_properties("${name}" PROPERTIES
EXCLUDE_FROM_ALL TRUE
_qt_internal_excluded_from_default_target TRUE
)
break() break()
endif() endif()
endforeach() endforeach()

View File

@ -1069,6 +1069,13 @@ function(_qt_internal_sbom_handle_target_binary_files target)
return() return()
endif() endif()
get_target_property(excluded ${target} _qt_internal_excluded_from_default_target)
if(excluded)
message(DEBUG "Target ${target} has no binary files to reference in the SBOM "
"because it was excluded from the default 'all' target.")
return()
endif()
if(NOT arg_SPDX_ID) if(NOT arg_SPDX_ID)
message(FATAL_ERROR "SPDX_ID must be set") message(FATAL_ERROR "SPDX_ID must be set")
endif() endif()