-
-
Notifications
You must be signed in to change notification settings - Fork 258
/
CMakeLists.txt
58 lines (46 loc) · 2.42 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
cmake_minimum_required(VERSION 3.1)
project(dbg_macro)
include(GNUInstallDirs)
string(COMPARE EQUAL ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR} IS_MAIN_PROJECT)
option(DBG_MACRO_ENABLE_TESTS "Enable tests." ${IS_MAIN_PROJECT})
add_library(${PROJECT_NAME} INTERFACE)
target_include_directories(${PROJECT_NAME}
INTERFACE
$<BUILD_INTERFACE:${${PROJECT_NAME}_SOURCE_DIR}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
if (DBG_MACRO_ENABLE_TESTS)
add_subdirectory(tests/Catch2)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/tests/Catch2/contrib)
include(CTest)
include(Catch)
if(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
set(WARNING_FLAGS "-W4")
# Required to force MSVC to set __cplusplus to the correct value
# https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
set(ADDITIONAL_FLAGS "/Zc:__cplusplus")
else()
set(WARNING_FLAGS "-Wall" "-pedantic")
set(ADDITIONAL_FLAGS "")
endif()
# unit tests with dbg(...) enabled
add_executable(${PROJECT_NAME}-tests tests/main.cpp tests/basic.cpp)
target_compile_options(${PROJECT_NAME}-tests PRIVATE ${WARNING_FLAGS} ${ADDITIONAL_FLAGS} -DDBG_MACRO_NO_WARNING)
target_link_libraries(${PROJECT_NAME}-tests ${PROJECT_NAME} Catch2::Catch2)
catch_discover_tests(${PROJECT_NAME}-tests)
# unit tests with dbg(...) disabled
add_executable(${PROJECT_NAME}-tests-macro_disabled tests/main.cpp tests/basic.cpp)
target_compile_options(${PROJECT_NAME}-tests-macro_disabled PRIVATE ${WARNING_FLAGS} ${ADDITIONAL_FLAGS} -DDBG_MACRO_NO_WARNING -DDBG_MACRO_DISABLE)
target_link_libraries(${PROJECT_NAME}-tests-macro_disabled ${PROJECT_NAME} Catch2::Catch2)
catch_discover_tests(${PROJECT_NAME}-tests-macro_disabled)
# dbg(…) example file
add_executable(${PROJECT_NAME}-example tests/example.cpp)
target_compile_options(${PROJECT_NAME}-example PRIVATE ${WARNING_FLAGS} ${ADDITIONAL_FLAGS} -DDBG_MACRO_NO_WARNING)
target_link_libraries(${PROJECT_NAME}-example ${PROJECT_NAME})
# dbg(…) demo file
add_executable(${PROJECT_NAME}-demo tests/demo.cpp)
target_compile_options(${PROJECT_NAME}-demo PRIVATE ${WARNING_FLAGS} ${ADDITIONAL_FLAGS} -DDBG_MACRO_NO_WARNING)
target_link_libraries(${PROJECT_NAME}-demo ${PROJECT_NAME})
add_test(${PROJECT_NAME}-demo ${PROJECT_NAME}-demo)
endif()
install(FILES "dbg.h" DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})