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