aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Funk <kfunk@kde.org>2017-08-07 15:50:25 +0200
committerKevin Funk <kfunk@kde.org>2017-08-07 22:25:47 +0200
commitb99d2d2c5dedcaba9745dddc1dd7b8d4811babf1 (patch)
tree593d114cfe6630a1404ecfd2e819be892ae06040
parent165465ee7116bbbd8c0dd2ae04c2037c45f208a8 (diff)
downloadextra-cmake-modules-b99d2d2c5dedcaba9745dddc1dd7b8d4811babf1.tar.gz
extra-cmake-modules-b99d2d2c5dedcaba9745dddc1dd7b8d4811babf1.tar.bz2
RFC: Make ECMAddTests respect BUILD_TESTING
Summary: Use-case: Make building unit tests optional, by just following the CMake BUILD_TESTING option. The usual approach to conditionally build tests is to do: ``` if (BUILD_TESTING) add_executable(TestOne TestOne.cpp) target_link_libraries(TestOne my_library) endif() ``` or: ``` if (BUILD_TESTING) add_subdirectory(tests) endif() ``` This patch just turns all calls to ecm_add_test(...) into no-ops if BUILD_TESTING=OFF. See: https://cmake.org/cmake/help/v3.6/module/CTest.html Reviewers: vkrause Reviewed By: vkrause Subscribers: kossebau, vkrause, elvisangelaccio, asturmlechner, apol, #frameworks, #build_system Tags: #frameworks, #build_system Differential Revision: https://phabricator.kde.org/D7187
-rw-r--r--modules/ECMAddTests.cmake10
1 files changed, 10 insertions, 0 deletions
diff --git a/modules/ECMAddTests.cmake b/modules/ECMAddTests.cmake
index 96673888..c77a7aaf 100644
--- a/modules/ECMAddTests.cmake
+++ b/modules/ECMAddTests.cmake
@@ -49,6 +49,12 @@
# be given; this will be used for both the target and test names (and, as with
# ecm_add_tests(), the NAME_PREFIX argument will be prepended to the test name).
#
+# If BUILD_TESTING is set to OFF, ecm_add_test will turn into a no-op and thus
+# will not add any test-related targets
+#
+# BUILD_TESTING is created as a cache variable by the CTest module and by the
+# :kde-module:`KDECMakeSettings` module.
+#
#
# Since pre-1.0.0.
@@ -84,6 +90,10 @@ include(ECMMarkAsTest)
include(ECMMarkNonGuiExecutable)
function(ecm_add_test)
+ if(NOT BUILD_TESTING)
+ return() # turn this function into a no-op
+ endif()
+
set(options GUI)
# TARGET_NAME_VAR and TEST_NAME_VAR are undocumented args used by
# ecm_add_tests