From bd17f3f370a1b505ee07c431394cb6a9f53586d6 Mon Sep 17 00:00:00 2001 From: Tim Blechmann Date: Wed, 7 Feb 2024 11:25:33 +0800 Subject: [PATCH] cmake: build repo helpers - fine-grained test/example options the tests/examples could only be enabled globally. when working on a specific repo, it's beneficial to disable tests/examples for other projects to reduce project sizes (and cmake configure/generate times) Change-Id: I0026ba87b667d427043cc8eb1baa6c28b2046dd7 Reviewed-by: Alexey Edelev Reviewed-by: Alexandru Croitor (cherry picked from commit 25b89f2c88cdfc98bfa462949531a33f7ef50996) Reviewed-by: Qt Cherry-pick Bot --- CMakeLists.txt | 11 ++--------- cmake/QtBuildRepoHelpers.cmake | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a0da025418a..cf2031bd5a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -203,15 +203,8 @@ endif() qt_build_repo_post_process() -if(QT_BUILD_TESTS) - add_subdirectory(tests) - if(NOT QT_BUILD_TESTS_BY_DEFAULT) - set_property(DIRECTORY tests PROPERTY EXCLUDE_FROM_ALL TRUE) - endif() -endif() +qt_build_repo_impl_tests() qt_build_repo_end() -if(NOT QT_BUILD_STANDALONE_TESTS AND QT_BUILD_EXAMPLES) - add_subdirectory(examples) -endif() +qt_build_repo_impl_examples() diff --git a/cmake/QtBuildRepoHelpers.cmake b/cmake/QtBuildRepoHelpers.cmake index ef9cd137085..c0de166f8b6 100644 --- a/cmake/QtBuildRepoHelpers.cmake +++ b/cmake/QtBuildRepoHelpers.cmake @@ -428,9 +428,13 @@ endmacro() macro(qt_build_repo_impl_tests) if (QT_BUILD_TESTS AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tests/CMakeLists.txt") - add_subdirectory(tests) - if(NOT QT_BUILD_TESTS_BY_DEFAULT) - set_property(DIRECTORY tests PROPERTY EXCLUDE_FROM_ALL TRUE) + option(QT_BUILD_TESTS_PROJECT_${PROJECT_NAME} "Configure tests for project ${PROJECT_NAME}" TRUE) + + if (QT_BUILD_TESTS_PROJECT_${PROJECT_NAME}) + add_subdirectory(tests) + if(NOT QT_BUILD_TESTS_BY_DEFAULT) + set_property(DIRECTORY tests PROPERTY EXCLUDE_FROM_ALL TRUE) + endif() endif() endif() endmacro() @@ -440,7 +444,11 @@ macro(qt_build_repo_impl_examples) AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/examples/CMakeLists.txt" AND NOT QT_BUILD_STANDALONE_TESTS) message(STATUS "Configuring examples.") - add_subdirectory(examples) + + option(QT_BUILD_EXAMPLES_PROJECT_${PROJECT_NAME} "Configure examples for project ${PROJECT_NAME}" TRUE) + if (QT_BUILD_EXAMPLES_PROJECT_${PROJECT_NAME}) + add_subdirectory(examples) + endif() endif() endmacro()