From df30953228f0e364e9a3915d97f522efd8e67489 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Tue, 3 Dec 2024 11:56:54 +0100 Subject: [PATCH] CMake: Fix standalone build of sqldrivers with SBOM The standalone build of the sqldrivers plugin never called the SBOM project begin and end functions. This cause an error in qt_internal_add_plugin which tried to read the SBOM project name. Replace the calls to qt_prepare_standalone_project and qt_print_feature_summary with qt_build_repo_begin and qt_build_repo_end. This ensures the SBOM project is setup, as well as many other behaviors that a standalone internal build of a module is expected to have. Additionally we need to tell the SBOM project where to find the licenses for the standalone build. This is done by setting the new QT_SBOM_LICENSE_DIRS variable to the qtbase license directory. Pick-to: 6.8 Fixes: QTBUG-131799 Change-Id: I2e31ecffdff28561d1c4a6b8fbcd8125188d2c48 Reviewed-by: Joerg Bornemann --- cmake/QtPublicSbomHelpers.cmake | 24 +++++++++++++++++++++++- src/plugins/sqldrivers/CMakeLists.txt | 8 +++++--- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/cmake/QtPublicSbomHelpers.cmake b/cmake/QtPublicSbomHelpers.cmake index 49056a6c015..ce674273dde 100644 --- a/cmake/QtPublicSbomHelpers.cmake +++ b/cmake/QtPublicSbomHelpers.cmake @@ -216,7 +216,29 @@ function(_qt_internal_sbom_begin_project) _qt_internal_get_current_project_sbom_dir(sbom_dir) set_property(GLOBAL APPEND PROPERTY _qt_internal_sbom_dirs "${sbom_dir}") - file(GLOB license_files "${PROJECT_SOURCE_DIR}/LICENSES/LicenseRef-*.txt") + # Collect project licenses. + set(license_dirs "") + + if(EXISTS "${PROJECT_SOURCE_DIR}/LICENSES") + list(APPEND license_dirs "${PROJECT_SOURCE_DIR}/LICENSES") + endif() + + # Allow specifying extra license dirs via a variable. Useful for standalone projects + # like sqldrivers. + if(QT_SBOM_LICENSE_DIRS) + foreach(license_dir IN LISTS QT_SBOM_LICENSE_DIRS) + if(EXISTS "${license_dir}") + list(APPEND license_dirs "${license_dir}") + endif() + endforeach() + endif() + list(REMOVE_DUPLICATES license_dirs) + + set(license_file_wildcard "LicenseRef-*.txt") + list(TRANSFORM license_dirs APPEND "/${license_file_wildcard}" OUTPUT_VARIABLE license_globs) + + file(GLOB license_files ${license_globs}) + foreach(license_file IN LISTS license_files) get_filename_component(license_id "${license_file}" NAME_WLE) _qt_internal_sbom_add_license( diff --git a/src/plugins/sqldrivers/CMakeLists.txt b/src/plugins/sqldrivers/CMakeLists.txt index 65f7fd47662..48369909961 100644 --- a/src/plugins/sqldrivers/CMakeLists.txt +++ b/src/plugins/sqldrivers/CMakeLists.txt @@ -22,8 +22,10 @@ if(NOT PROJECT_NAME STREQUAL "QtBase" AND NOT PROJECT_NAME STREQUAL "Qt") BuildInternals Core Sql - ) - qt_prepare_standalone_project() + ) + # Use qtbase license files for standalone builds. + set(QT_SBOM_LICENSE_DIRS "${PROJECT_SOURCE_DIR}/../../../LICENSES") + qt_build_repo_begin() else() qt_internal_upgrade_cmake_policies() endif() @@ -77,5 +79,5 @@ if(QT_FEATURE_sql_mimer) endif() if(NOT CMAKE_PROJECT_NAME STREQUAL "QtBase" AND NOT CMAKE_PROJECT_NAME STREQUAL "Qt") - qt_print_feature_summary() + qt_build_repo_end() endif()