diff --git a/cmake/QtCreatorAPI.cmake b/cmake/QtCreatorAPI.cmake index 18f9120ded8..88242484371 100644 --- a/cmake/QtCreatorAPI.cmake +++ b/cmake/QtCreatorAPI.cmake @@ -40,6 +40,7 @@ set(_THIS_MODULE_BASE_DIR "${CMAKE_CURRENT_LIST_DIR}") option(BUILD_PLUGINS_BY_DEFAULT "Build plugins by default. This can be used to build all plugins by default, or none." ON) option(BUILD_EXECUTABLES_BY_DEFAULT "Build executables by default. This can be used to build all executables by default, or none." ON) option(BUILD_LIBRARIES_BY_DEFAULT "Build libraries by default. This can be used to build all libraries by default, or none." ON) +option(BUILD_TESTS_BY_DEFAULT "Build tests by default. This can be used to build all tests by default, or none." ON) option(QTC_SEPARATE_DEBUG_INFO "Extract debug information from binary files." OFF) option(WITH_SCCACHE_SUPPORT "Enables support for building with SCCACHE and separate debug info with MSVC, which SCCACHE normally doesn't support." OFF) @@ -51,6 +52,7 @@ function(qtc_check_default_values_for_list list_type) set(PLUGINS_single plugin) set(EXECUTABLES_single executable) set(LIBRARIES_single library) + set(TESTS_single test) if (NOT DEFINED BUILD_${list_type}) return() @@ -67,6 +69,7 @@ endfunction() qtc_check_default_values_for_list(PLUGINS) qtc_check_default_values_for_list(EXECUTABLES) qtc_check_default_values_for_list(LIBRARIES) +qtc_check_default_values_for_list(TESTS) function(qtc_plugin_enabled varName name) if (NOT (name IN_LIST __QTC_PLUGINS)) @@ -790,6 +793,17 @@ function(add_qtc_test name) update_cached_list(__QTC_TESTS "${name}") + string(TOUPPER "BUILD_TEST_${name}" _build_test_var) + set(_build_test_default ${BUILD_TESTS_BY_DEFAULT}) + if (DEFINED ENV{QTC_${_build_test_var}}) + set(_build_test_default "$ENV{QTC_${_build_test_var}}") + endif() + set(${_build_test_var} "${_build_test_default}" CACHE BOOL "Build test ${name}.") + + if (NOT ${_build_test_var}) + return() + endif() + foreach(dependency ${_arg_DEPENDS}) if (NOT TARGET ${dependency} AND NOT _arg_GTEST) if (WITH_DEBUG_CMAKE) diff --git a/tests/unit/unittest/CMakeLists.txt b/tests/unit/unittest/CMakeLists.txt index 14b1263563a..c600016cf60 100644 --- a/tests/unit/unittest/CMakeLists.txt +++ b/tests/unit/unittest/CMakeLists.txt @@ -194,6 +194,10 @@ add_qtc_test(unittest GTEST mockimagecachestorage.h ) +if (NOT TARGET unittest) + return() +endif() + function(extend_qtc_test_with_target_sources target) cmake_parse_arguments(_arg "" "" "DEFINES;INCLUDES" ${ARGN})