diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c84c98..9cbfb78 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,8 @@ find_package(everest-cmake 0.1 REQUIRED # option(BUILD_EXAMPLES "enable building of examples" OFF) option(FSM_INSTALL "Install the library (shared data might be installed anyway)" ${EVC_MAIN_PROJECT}) - +option(${PROJECT_NAME}_BUILD_TESTING "Build unit tests, used if included as dependency" OFF) +option(BUILD_TESTING "Build unit tests, used if standalone project" OFF) # # library declaration @@ -39,7 +40,7 @@ endif() # # tests # -if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) +if((${CMAKE_PROJECT_NAME} STREQUAL ${PROJECT_NAME} OR ${PROJECT_NAME}_BUILD_TESTING) AND BUILD_TESTING) include(CTest) add_subdirectory(tests) endif() diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 81d0ce2..1c79cdd 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -16,20 +16,21 @@ if (CODE_COVERAGE) evc_include(CodeCoverage) endif() -add_executable(test_state_allocator state_allocator.cpp) -target_link_libraries(test_state_allocator +set(TEST_TARGET_NAME ${PROJECT_NAME}_tests) +add_executable(${TEST_TARGET_NAME} state_allocator.cpp) +target_link_libraries(${TEST_TARGET_NAME} PRIVATE fsm::fsm Catch2::Catch2WithMain ) if (CODE_COVERAGE) - append_coverage_compiler_flags_to_target(test_state_allocator) + append_coverage_compiler_flags_to_target(${TEST_TARGET_NAME}) setup_target_for_coverage_gcovr_html( NAME coverage - EXECUTABLE test_state_allocator + EXECUTABLE ${TEST_TARGET_NAME} BASE_DIRECTORY "${PROJECT_SOURCE_DIR}/include" ) endif() -catch_discover_tests(test_state_allocator) +catch_discover_tests(${TEST_TARGET_NAME})