-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathCMakeLists.txt
72 lines (62 loc) · 2.5 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
cmake_minimum_required(VERSION 3.0)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/modules")
project(WrenBind17)
option(WRENBIND17_BUILD_TESTS "Build with tests" OFF)
option(WRENBIND17_BUILD_WREN "Build Wren library too" OFF)
option(WRENBIND17_COVERAGE "Enable coverage reporting" OFF)
# Add WrenBind17 header only library
add_library(${PROJECT_NAME} INTERFACE)
set(WRENBIND17_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/include)
target_include_directories(${PROJECT_NAME} INTERFACE ${WRENBIND17_INCLUDE_DIR})
if(WRENBIND17_BUILD_TESTS OR WRENBIND17_BUILD_WREN)
# Find Wren library
find_package(Wren REQUIRED)
endif()
if(WRENBIND17_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
# Code Coverage Configuration
add_library(${PROJECT_NAME}_Coverage INTERFACE)
# Add required flags (GCC & LLVM/Clang)
target_compile_options(${PROJECT_NAME}_Coverage INTERFACE
-O0 # no optimization
-g # generate debug info
--coverage # sets all required flags
)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13)
target_link_options(${PROJECT_NAME}_Coverage INTERFACE --coverage)
else()
target_link_libraries(${PROJECT_NAME}_Coverage INTERFACE --coverage)
endif()
endif()
if(WRENBIND17_BUILD_TESTS)
# Find Catch2 library
find_package(Catch2 REQUIRED)
# Add tests
enable_testing()
file(GLOB TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/tests/*.cpp)
file(GLOB TEST_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/tests/*.hpp)
file(GLOB LIB_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/include/wrenbind17/*.hpp)
add_executable(${PROJECT_NAME}_Tests ${TEST_SOURCES} ${TEST_HEADERS} ${LIB_HEADERS})
set_target_properties(${PROJECT_NAME}_Tests PROPERTIES CXX_STANDARD 17 CXX_EXTENSIONS OFF)
target_include_directories(${PROJECT_NAME}_Tests PRIVATE ${CATCH2_INCLUDE_DIR})
target_link_libraries(${PROJECT_NAME}_Tests PUBLIC Wren ${PROJECT_NAME})
if(UNIX AND NOT APPLE)
# Coverage info
target_compile_options(${PROJECT_NAME}_Tests PRIVATE --coverage -g -O0)
target_link_options(${PROJECT_NAME}_Tests PRIVATE --coverage)
endif()
if(MINGW)
target_compile_options(${PROJECT_NAME}_Tests PRIVATE -Wa,-mbig-obj)
endif()
add_test(NAME ${PROJECT_NAME}_Tests COMMAND ${PROJECT_NAME}_Tests)
if(WRENBIND17_COVERAGE)
target_link_libraries(${PROJECT_NAME}_Tests PUBLIC ${PROJECT_NAME}_Coverage)
endif()
endif()
# install headers
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/wrenbind17"
DESTINATION include
FILES_MATCHING
PATTERN "*.hxx"
PATTERN "*.hpp"
PATTERN "*.h"
)