diff --git a/CMakeLists.txt b/CMakeLists.txt index 0f0fd6c..97f3fab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,18 +30,33 @@ if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) function(boost_test) - cmake_parse_arguments(PARSE "" "NAME" "SOURCES;LIBRARIES" ${ARGN}) + cmake_parse_arguments(_ "" "PREFIX;NAME" "SOURCES;LIBRARIES" ${ARGN}) - add_executable(${PARSE_NAME} EXCLUDE_FROM_ALL ${PARSE_SOURCES}) - target_link_libraries(${PARSE_NAME} ${PARSE_LIBRARIES}) + if(NOT __PREFIX) + set(__PREFIX ${PROJECT_NAME}) + endif() - add_test(NAME compile-${PARSE_NAME} COMMAND "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target ${PARSE_NAME}) + if(NOT __NAME) + list(GET __SOURCES 0 __NAME) + string(MAKE_C_IDENTIFIER ${__NAME} __NAME) + endif() - add_test(NAME run-${PARSE_NAME} COMMAND ${PARSE_NAME}) - set_tests_properties(run-${PARSE_NAME} PROPERTIES DEPENDS compile-${PARSE_NAME}) + set(__NAME ${__PREFIX}-${__NAME}) + + add_executable(${__NAME} EXCLUDE_FROM_ALL ${__SOURCES}) + target_link_libraries(${__NAME} ${__LIBRARIES}) + + add_test(NAME compile-${__NAME} COMMAND "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target ${__NAME}) + + add_test(NAME run-${__NAME} COMMAND ${__NAME}) + set_tests_properties(run-${__NAME} PROPERTIES DEPENDS compile-${__NAME}) endfunction(boost_test) +endif() + +if(COMMAND boost_test) + add_subdirectory(test) endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index ee0316b..8c42364 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -5,19 +5,19 @@ # See accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt -boost_test(NAME assert_test SOURCES assert_test.cpp LIBRARIES Boost::assert Boost::core) -boost_test(NAME current_function_test SOURCES current_function_test.cpp LIBRARIES Boost::assert Boost::core) -boost_test(NAME verify_test SOURCES verify_test.cpp LIBRARIES Boost::assert Boost::core) -boost_test(NAME assert_is_void_test SOURCES assert_is_void_test.cpp LIBRARIES Boost::assert Boost::core) +boost_test(SOURCES assert_test.cpp LIBRARIES Boost::assert Boost::core) +boost_test(SOURCES current_function_test.cpp LIBRARIES Boost::assert Boost::core) +boost_test(SOURCES verify_test.cpp LIBRARIES Boost::assert Boost::core) +boost_test(SOURCES assert_is_void_test.cpp LIBRARIES Boost::assert Boost::core) # expansion tests are in exp/ so that there is a backslash in the path on Windows -boost_test(NAME assert_exp_test SOURCES exp/assert_exp_test.cpp LIBRARIES Boost::assert Boost::core) -boost_test(NAME assert_msg_exp_test SOURCES exp/assert_msg_exp_test.cpp LIBRARIES Boost::assert Boost::core) -boost_test(NAME verify_exp_test SOURCES exp/verify_exp_test.cpp LIBRARIES Boost::assert Boost::core) -boost_test(NAME verify_msg_exp_test SOURCES exp/verify_msg_exp_test.cpp LIBRARIES Boost::assert Boost::core) +boost_test(SOURCES exp/assert_exp_test.cpp LIBRARIES Boost::assert Boost::core) +boost_test(SOURCES exp/assert_msg_exp_test.cpp LIBRARIES Boost::assert Boost::core) +boost_test(SOURCES exp/verify_exp_test.cpp LIBRARIES Boost::assert Boost::core) +boost_test(SOURCES exp/verify_msg_exp_test.cpp LIBRARIES Boost::assert Boost::core) -boost_test(NAME assert_test2 SOURCES assert_test2.cpp LIBRARIES Boost::assert Boost::core) -boost_test(NAME assert_msg_test2 SOURCES assert_msg_test2.cpp LIBRARIES Boost::assert Boost::core) +boost_test(SOURCES assert_test2.cpp LIBRARIES Boost::assert Boost::core) +boost_test(SOURCES assert_msg_test2.cpp LIBRARIES Boost::assert Boost::core) -boost_test(NAME quick SOURCES quick.cpp LIBRARIES Boost::assert Boost::core) +boost_test(SOURCES quick.cpp LIBRARIES Boost::assert Boost::core)