Skip to content

Commit

Permalink
Add enable tests property
Browse files Browse the repository at this point in the history
  • Loading branch information
pfultz2 committed Apr 25, 2018
1 parent 7cda940 commit 55098e6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 1 deletion.
8 changes: 8 additions & 0 deletions doc/src/BCMTest.rst
Expand Up @@ -78,4 +78,12 @@ Rather than just test the include, using ``STATIC`` option will test the include

This won't link in the libraries specified by ``bcm_test_link_libraries``

-------------------------
bcm_add_test_subdirectory
-------------------------

.. program:: bcm_add_test_subdirectory

This calls ``add_subdirectory`` if the ``ENABLE_TESTS`` property is true. The default value for the property is set by ``CMAKE_ENABLE_TESTS`` variable.


18 changes: 18 additions & 0 deletions share/bcm/cmake/BCMTest.cmake
Expand Up @@ -2,6 +2,15 @@ option(BUILD_TESTING off)

enable_testing()

foreach(scope GLOBAL DIRECTORY)
define_property(${scope} PROPERTY "ENABLE_TESTS" INHERITED
BRIEF_DOCS "Enable tests"
FULL_DOCS "Enable tests"
)
endforeach()
option(CMAKE_ENABLE_TESTS "Enable tests" ON)
set_property(GLOBAL PROPERTY ENABLE_TESTS ${CMAKE_ENABLE_TESTS})

include(ProcessorCount)
ProcessorCount(_bcm_ctest_parallel_level)
set(CTEST_PARALLEL_LEVEL ${_bcm_ctest_parallel_level} CACHE STRING "CTest parallel level")
Expand Down Expand Up @@ -193,3 +202,12 @@ function(bcm_test_header)
endif()
set_tests_properties(${TEST_NAME} PROPERTIES LABELS ${PROJECT_NAME})
endfunction(bcm_test_header)

macro(bcm_add_test_subdirectory)
get_directory_property(_enable_tests_property ENABLE_TESTS)
get_property(_enable_tests_global_property GLOBAL PROPERTY ENABLE_TESTS)
string(TOUPPER "${_enable_tests_property}" _enable_tests_property_upper)
if(_enable_tests_property_upper STREQUAL "OFF" OR _enable_tests_property_upper EQUAL 1)
add_subdirectory(${ARGN})
endif()
endmacro()
1 change: 1 addition & 0 deletions test/fail/simple-test.cmake
@@ -0,0 +1 @@
install_dir(${TEST_DIR}/simpletest TARGETS check CMAKE_ARGS -DCMAKE_ENABLE_TESTS=Off)
7 changes: 6 additions & 1 deletion test/simpletest/CMakeLists.txt
Expand Up @@ -18,4 +18,9 @@ bcm_deploy(TARGETS simple INCLUDE include)
bcm_test(NAME simpletoptest SOURCES test.cpp)
target_link_libraries(simpletoptest simple)

add_subdirectory(test)
bcm_add_test_subdirectory(test)

if(TARGET simpletest)
message(FATAL_ERROR "simpletest was not added")
endif()

0 comments on commit 55098e6

Please sign in to comment.