aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorStephen Kelly <steveire@gmail.com>2012-02-01 13:25:14 +0100
committerStephen Kelly <steveire@gmail.com>2012-02-01 13:25:14 +0100
commitb7bec845e2da25ec3a75d3a315dd0aa5bd07b159 (patch)
tree59d0b3c3e66fb1f42d901c66ba4e014e673d47c6 /modules
parent3e6f0279e8b1d551155776b8bec383f95c53fece (diff)
downloadextra-cmake-modules-b7bec845e2da25ec3a75d3a315dd0aa5bd07b159.tar.gz
extra-cmake-modules-b7bec845e2da25ec3a75d3a315dd0aa5bd07b159.tar.bz2
Add the ecm_mark_as_test macro.
This is for cases when adding targets that are only part of the testing infrastructure so that they can be built conditionally or not at all.
Diffstat (limited to 'modules')
-rw-r--r--modules/ECMMarkAsTest.cmake32
1 files changed, 32 insertions, 0 deletions
diff --git a/modules/ECMMarkAsTest.cmake b/modules/ECMMarkAsTest.cmake
new file mode 100644
index 00000000..5d359a61
--- /dev/null
+++ b/modules/ECMMarkAsTest.cmake
@@ -0,0 +1,32 @@
+# - Function for marking targets as being only for testing
+# This module provides the function ECM_MARK_AS_TEST().
+#
+# The ECM_MARK_AS_TEST function is used to indicate that a target should only
+# be built if the BUILD_TESTING option (provided by CTest) is enabled.
+#
+# ECM_MARK_AS_TEST( target1 target2 ... targetN )
+#
+# If BUILD_TESTING is False, then targets marked as tests are exluded from
+# the ALL target. They are all part of the 'buildtests' target though, so
+# even if building with BUILD_TESTING set to False, it is possible to build
+# all tests by invoking the 'buildtests' target.
+
+if (NOT BUILD_TESTING)
+ get_property(_buildtestsAdded GLOBAL PROPERTY BUILDTESTS_ADDED)
+ if(NOT _buildtestsAdded)
+ add_custom_target(buildtests)
+ set_property(GLOBAL PROPERTY BUILDTESTS_ADDED TRUE)
+ endif()
+endif()
+
+function(ecm_mark_as_test)
+ if (NOT BUILD_TESTING)
+ foreach(_target ${ARGN})
+ set_target_properties(${_target}
+ PROPERTIES
+ EXCLUDE_FROM_ALL 1
+ )
+ add_dependencies(buildtests ${_target})
+ endforeach()
+ endif()
+endfunction()