Skip to content

Commit

Permalink
e Add CMake options for use with add_subdirectory() to help with #69
Browse files Browse the repository at this point in the history
Now most of our tests are not executed if this projected has
been added inside another one.
  • Loading branch information
claremacrae committed Jan 15, 2020
1 parent f065814 commit 88c82f2
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,27 @@ add_subdirectory(ApprovalTests)
set(CMAKE_VERBOSE_MAKEFILE off)

option(APPROVAL_TESTS_ENABLE_CODE_COVERAGE "Enable coverage reporting for selected tests" OFF)

# TODO Rename s/ENABLE/BUILD/
# TODO Make this also work if not a subproject
option(APPROVAL_TESTS_ENABLE_CMAKE_INTEGRATION_TESTS "Enable tests that check our CMake integration" ON)

option(APPROVAL_TESTS_BUILD_THIRD_PARTY
"Include third_party directory. Note that these are always included if this is the top-level project"
OFF)
option(APPROVAL_TESTS_BUILD_TESTING
"Build self-tests. Note that these are always built if this is the top-level project"
OFF)
option(APPROVAL_TESTS_BUILD_EXAMPLES
"Build documentation examples. Note that these are always built if this is the top-level project"
OFF)

if(APPROVAL_TESTS_ENABLE_CODE_COVERAGE)
message(STATUS "Enable Code Coverage")
include(CodeCoverage)
append_coverage_compiler_flags()
endif()

if (NOT_SUBPROJECT)
if (NOT_SUBPROJECT OR APPROVAL_TESTS_BUILD_THIRD_PARTY)
# Download and unpack googletest at configure time
configure_file(CMakeLists.txt.in googletest-download/CMakeLists.txt)
execute_process(COMMAND "${CMAKE_COMMAND}" -G "${CMAKE_GENERATOR}" .
Expand All @@ -39,9 +51,18 @@ if (NOT_SUBPROJECT)
add_subdirectory("${CMAKE_BINARY_DIR}/googletest-src"
"${CMAKE_BINARY_DIR}/googletest-build")

enable_testing()
add_subdirectory(third_party)
endif()

if(NOT_SUBPROJECT OR APPROVAL_TESTS_BUILD_TESTING OR APPROVAL_TESTS_BUILD_EXAMPLES)
enable_testing()
endif()

if(NOT_SUBPROJECT OR APPROVAL_TESTS_BUILD_TESTING)
add_subdirectory(tests)
endif()

if(NOT_SUBPROJECT OR APPROVAL_TESTS_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()

Expand All @@ -54,3 +75,7 @@ message("CMAKE_CXX_COMPILER = ${CMAKE_CXX_COMPILER}")
message("CMAKE_CXX_COMPILER_ID = ${CMAKE_CXX_COMPILER_ID}")
message("CMAKE_CXX_COMPILER_VERSION = ${CMAKE_CXX_COMPILER_VERSION}")
message("CMAKE_UNITY_BUILD = ${CMAKE_UNITY_BUILD}")
#message("APPROVAL_TESTS_ENABLE_CMAKE_INTEGRATION_TESTS = ${APPROVAL_TESTS_ENABLE_CMAKE_INTEGRATION_TESTS}")
#message("APPROVAL_TESTS_BUILD_THIRD_PARTY = ${APPROVAL_TESTS_BUILD_THIRD_PARTY}")
#message("APPROVAL_TESTS_BUILD_TESTING = ${APPROVAL_TESTS_BUILD_TESTING}")
#message("APPROVAL_TESTS_BUILD_EXAMPLES = ${APPROVAL_TESTS_BUILD_EXAMPLES}")

0 comments on commit 88c82f2

Please sign in to comment.