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
Pick-to: 6.7
Reviewed-by:  Alexey Edelev <alexey.edelev@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Tim Blechmann 2024-02-07 11:25:33 +08:00
parent 68179f7605
commit 25b89f2c88
2 changed files with 14 additions and 13 deletions

View File

@ -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()

View File

@ -429,9 +429,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()
@ -441,7 +445,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()