-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
64 lines (51 loc) · 2.55 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
cmake_minimum_required(VERSION 3.9)
# ╔╦╗┌─┐┌┬┐┌─┐┬─┐┬ ┬ ╔═╗┌─┐┌┐┌┌┬┐┬┌┐┌┌─┐┬
# ║║║├┤ ││││ │├┬┘└┬┘ ╚═╗├┤ │││ │ ││││├┤ │
# ╩ ╩└─┘┴ ┴└─┘┴└─ ┴ ╚═╝└─┘┘└┘ ┴ ┴┘└┘└─┘┴─┘
###########################################################
# MAIN
project(MemorySentinel)
# Set C++ standard to C++14
set(CMAKE_CXX_STANDARD 14)
set(CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CODE_COVERAGE OFF CACHE BOOL "Build with instrumentation and code coverage")
# LIB SOURCES
file(GLOB_RECURSE source "source/*.[h,c]*")
set (LIB_NAME "MemorySentinel")
add_library(${LIB_NAME} ${source})
# TEST TARGET
set (TEST_NAME "${LIB_NAME}Test")
file(GLOB_RECURSE source_test "test/*.[h,c]*")
add_executable(${TEST_NAME} ${source_test})
# Create XCode / VS groups
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${source})
target_include_directories(${TEST_NAME} PUBLIC source)
target_include_directories(${TEST_NAME} PRIVATE test)
target_include_directories(${TEST_NAME} PRIVATE test/external-utils)
if (CODE_COVERAGE)
message("Code Coverage tracking enabled")
# When building with coverage, we usually disable exceptions, for more meaningful results
# In this case, however, exceptions constitute a fundamental behaviour, so it's best to enable them
target_compile_options(${LIB_NAME} PRIVATE
$<$<COMPILE_LANGUAGE:CXX>:-fprofile-arcs -ftest-coverage -fexceptions -fno-inline>
$<$<COMPILE_LANGUAGE:C>:-fprofile-arcs -ftest-coverage -fexceptions -fno-inline>)
target_link_options(${LIB_NAME} PRIVATE -fprofile-arcs -ftest-coverage)
target_compile_options(${TEST_NAME} PRIVATE
$<$<COMPILE_LANGUAGE:CXX>:-fprofile-arcs -ftest-coverage -fexceptions -fno-inline>
$<$<COMPILE_LANGUAGE:C>:-fprofile-arcs -ftest-coverage -fexceptions -fno-inline>)
target_link_options(${TEST_NAME} PRIVATE -fprofile-arcs -ftest-coverage)
endif()
target_link_libraries(${TEST_NAME} ${LIB_NAME})
if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" )
target_link_libraries(${TEST_NAME} dl)
endif()
# Explicitly set CMP0110 to "NEW" to allow whitespace in tests names
if (POLICY CMP0110)
cmake_policy(SET CMP0110 NEW)
endif()
## ENABLE THE USE OF CTEST
include("test/external-utils/catch2/ParseAndAddCatchTests.cmake")
#include(CTest) # this will generate lots of additional targets
enable_testing()
ParseAndAddCatchTests(${TEST_NAME})