From efc3a9972db37093fc2402a2c2d63f2b2e00bc2b Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Thu, 29 Aug 2024 18:11:15 +0200 Subject: [PATCH] CMake: Add a function to detect qt 3rd party entity types for SBOM Removes some condition duplication. Task-number: QTBUG-122899 Change-Id: Ib245a96b5f8c78b2744cb4fd09a392b2924bf45c Reviewed-by: Alexey Edelev (cherry picked from commit ce7a01f0ec411643d8436c23a0d465b5746ac6be) Reviewed-by: Qt Cherry-pick Bot --- cmake/QtPublicSbomHelpers.cmake | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/cmake/QtPublicSbomHelpers.cmake b/cmake/QtPublicSbomHelpers.cmake index 80b3b85ab45..a66eb7e56e2 100644 --- a/cmake/QtPublicSbomHelpers.cmake +++ b/cmake/QtPublicSbomHelpers.cmake @@ -453,6 +453,7 @@ function(_qt_internal_sbom_add_target target) set(project_package_options "") _qt_internal_sbom_is_qt_entity_type("${arg_TYPE}" is_qt_entity_type) + _qt_internal_sbom_is_qt_3rd_party_entity_type("${arg_TYPE}" is_qt_3rd_party_entity_type) if(arg_FRIENDLY_PACKAGE_NAME) set(package_name_for_spdx_id "${arg_FRIENDLY_PACKAGE_NAME}") @@ -629,9 +630,7 @@ function(_qt_internal_sbom_add_target target) endif() set(supplier "") - if((is_qt_entity_type - OR arg_TYPE STREQUAL "QT_THIRD_PARTY_MODULE" - OR arg_TYPE STREQUAL "QT_THIRD_PARTY_SOURCES") + if((is_qt_entity_type OR is_qt_3rd_party_entity_type) AND NOT arg_NO_DEFAULT_QT_SUPPLIER) _qt_internal_sbom_get_default_supplier(supplier) endif() @@ -720,8 +719,7 @@ function(_qt_internal_sbom_add_target target) list(APPEND project_package_options ${purl_package_options}) endif() - if(arg_TYPE STREQUAL "QT_THIRD_PARTY_MODULE" - OR arg_TYPE STREQUAL "QT_THIRD_PARTY_SOURCES" + if(is_qt_3rd_party_entity_type OR arg_TYPE STREQUAL "SYSTEM_LIBRARY" OR arg_TYPE STREQUAL "THIRD_PARTY_LIBRARY" OR arg_TYPE STREQUAL "THIRD_PARTY_LIBRARY_WITH_FILES" @@ -2560,6 +2558,21 @@ function(_qt_internal_sbom_is_qt_entity_type sbom_type out_var) set(${out_var} ${is_qt_entity_type} PARENT_SCOPE) endfunction() +# Returns whether the given sbom type is considered to a Qt 3rd party entity type. +function(_qt_internal_sbom_is_qt_3rd_party_entity_type sbom_type out_var) + set(entity_types + QT_THIRD_PARTY_MODULE + QT_THIRD_PARTY_SOURCES + ) + + set(is_qt_third_party_entity_type FALSE) + if(sbom_type IN_LIST entity_types) + set(is_qt_third_party_entity_type TRUE) + endif() + + set(${out_var} ${is_qt_third_party_entity_type} PARENT_SCOPE) +endfunction() + # Save a spdx id for all known related target names of a given Qt target. # Related being the namespaced and versionless variants of a Qt target. # All the related targets will contain the same spdx id.