2017-08-26 00:06:22 +08:00
|
|
|
#############################################################################
|
|
|
|
# Catch library with the main function to speed up build
|
|
|
|
#############################################################################
|
|
|
|
|
2017-02-12 19:46:54 +08:00
|
|
|
add_library(catch_main OBJECT
|
|
|
|
"src/unit.cpp"
|
|
|
|
)
|
|
|
|
set_target_properties(catch_main PROPERTIES
|
|
|
|
CXX_STANDARD 11
|
|
|
|
CXX_STANDARD_REQUIRED ON
|
2017-08-26 00:06:22 +08:00
|
|
|
COMPILE_DEFINITIONS "$<$<CXX_COMPILER_ID:MSVC>:_SCL_SECURE_NO_WARNINGS>"
|
|
|
|
COMPILE_OPTIONS "$<$<CXX_COMPILER_ID:MSVC>:/EHsc;$<$<CONFIG:Release>:/Od>>"
|
2017-02-12 19:46:54 +08:00
|
|
|
)
|
|
|
|
target_include_directories(catch_main PRIVATE "thirdparty/catch")
|
|
|
|
|
2017-08-26 00:06:22 +08:00
|
|
|
#############################################################################
|
|
|
|
# one executable for each unit test file
|
|
|
|
#############################################################################
|
2016-05-11 08:25:54 +08:00
|
|
|
|
2017-08-26 00:06:22 +08:00
|
|
|
file(GLOB files "src/unit-*.cpp")
|
|
|
|
foreach(file ${files})
|
|
|
|
get_filename_component(file_basename ${file} NAME_WE)
|
|
|
|
string(REGEX REPLACE "unit-([^$]+)" "test-\\1" testcase ${file_basename})
|
2016-05-11 08:25:54 +08:00
|
|
|
|
2017-08-26 00:06:22 +08:00
|
|
|
add_executable(${testcase} $<TARGET_OBJECTS:catch_main> ${file})
|
|
|
|
set_target_properties(${testcase} PROPERTIES
|
|
|
|
CXX_STANDARD 11
|
|
|
|
CXX_STANDARD_REQUIRED ON
|
|
|
|
COMPILE_DEFINITIONS "$<$<CXX_COMPILER_ID:MSVC>:_SCL_SECURE_NO_WARNINGS>"
|
|
|
|
COMPILE_OPTIONS "$<$<CXX_COMPILER_ID:MSVC>:/EHsc;$<$<CONFIG:Release>:/Od>>"
|
2017-02-12 19:46:54 +08:00
|
|
|
)
|
|
|
|
|
2017-08-26 00:06:22 +08:00
|
|
|
target_compile_definitions(${testcase} PRIVATE CATCH_CONFIG_FAST_COMPILE)
|
|
|
|
target_include_directories(${testcase} PRIVATE "thirdparty/catch")
|
|
|
|
target_link_libraries(${testcase} ${JSON_TARGET_NAME})
|
|
|
|
|
|
|
|
if(NOT MSVC)
|
|
|
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated -Wno-float-equal")
|
|
|
|
endif()
|
2016-05-11 08:38:52 +08:00
|
|
|
|
2017-08-26 00:06:22 +08:00
|
|
|
include(cotire OPTIONAL)
|
|
|
|
if(COMMAND cotire)
|
|
|
|
cotire(${testcase})
|
|
|
|
endif()
|
2017-02-12 19:46:54 +08:00
|
|
|
|
2017-08-26 00:06:22 +08:00
|
|
|
add_test(NAME "${testcase}_default"
|
|
|
|
COMMAND ${testcase}
|
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
2017-02-12 19:46:54 +08:00
|
|
|
)
|
2017-08-26 00:06:22 +08:00
|
|
|
set_tests_properties("${testcase}_default" PROPERTIES LABELS "default")
|
2017-02-12 19:46:54 +08:00
|
|
|
|
2017-08-26 00:06:22 +08:00
|
|
|
add_test(NAME "${testcase}_all"
|
|
|
|
COMMAND ${testcase} "*"
|
|
|
|
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
|
|
|
|
)
|
|
|
|
set_tests_properties("${testcase}_all" PROPERTIES LABELS "all")
|
|
|
|
endforeach()
|