-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
89 lines (76 loc) · 2.87 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# (C) 2020 The University of Chicago
# See COPYRIGHT in top-level directory.
cmake_minimum_required (VERSION 3.8)
project (alpha C CXX)
enable_testing ()
add_definitions (-Wextra -Wall -Wpedantic)
add_library (coverage_config INTERFACE)
option (ENABLE_TESTS "Build tests" OFF)
option (ENABLE_EXAMPLES "Build examples" OFF)
option (ENABLE_BEDROCK "Build bedrock module" OFF)
option (ENABLE_COVERAGE "Build with coverage" OFF)
option (ENABLE_ASAN "Build with address sanitizer" OFF)
# add our cmake module directory to the path
set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
"${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# link shared lib with full rpath
set (CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# setup cache variables for ccmake
if (NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE Release
CACHE STRING "Choose the type of build." FORCE)
set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
"Debug" "Release" "RelWithDebInfo" "MinSizeRel")
endif ()
set (CMAKE_PREFIX_PATH "" CACHE STRING "External dependencies path")
set (BUILD_SHARED_LIBS "ON" CACHE BOOL "Build a shared library")
if (ENABLE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options (coverage_config INTERFACE
-O0 # no optimization
-g # generate debug info
--coverage # sets all required flags
)
if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.13)
target_link_options (coverage_config INTERFACE --coverage)
else ()
target_link_libraries (coverage_config INTERFACE --coverage)
endif ()
endif ()
if (ENABLE_ASAN)
set (CMAKE_BUILD_TYPE Debug)
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
set (CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
endif ()
find_package (PkgConfig REQUIRED)
if (${ENABLE_BEDROCK})
find_package (bedrock-module-api REQUIRED)
endif ()
# search for margo
pkg_check_modules (margo REQUIRED IMPORTED_TARGET margo)
# search for json-c
pkg_check_modules (json-c REQUIRED IMPORTED_TARGET json-c)
# library version set here (e.g. for shared libs).
set (ALPHA_VERSION_MAJOR 0)
set (ALPHA_VERSION_MINOR 1)
set (ALPHA_VERSION_PATCH 0)
set (ALPHA_VERSION
"${ALPHA_VERSION_MAJOR}.${ALPHA_VERSION_MINOR}.${ALPHA_VERSION_PATCH}")
add_subdirectory (src)
if (${ENABLE_TESTS})
enable_testing ()
find_package (Catch2 3.6.0 QUIET)
if (NOT Catch2_FOUND)
include (FetchContent)
FetchContent_Declare (
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.6.0
)
FetchContent_MakeAvailable (Catch2)
endif ()
add_subdirectory (tests)
endif (${ENABLE_TESTS})
if (${ENABLE_EXAMPLES})
add_subdirectory (examples)
endif (${ENABLE_EXAMPLES})