forked from odygrd/quill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
158 lines (121 loc) · 6.22 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
cmake_minimum_required(VERSION 3.1.0)
project(my_project)
#-------------------------------------------------------------------------------------------------------
# Options
#-------------------------------------------------------------------------------------------------------
option(QUILL_FMT_EXTERNAL "Use external fmt library instead of bundled" OFF)
option(QUILL_NO_EXCEPTIONS "Build without exceptions with -fno-exceptions flag" OFF)
option(QUILL_USE_BOUNDED_QUEUE "Build with bounded queue instead of unbounded" OFF)
option(QUILL_BUILD_EXAMPLES "Build the examples" OFF)
option(QUILL_BUILD_TESTS "Build the tests (Requires https://github.com/google/googletest to be installed)" OFF)
option(QUILL_BUILD_BENCHMARKS "Build the benchmarks" OFF)
option(QUILL_SANITIZE_ADDRESS "Enable address sanitizer in tests" OFF)
option(QUILL_SANITIZE_THREAD "Enable thread sanitizer in tests (Using this option with any other compiler except clang may result to false positives)" OFF)
option(QUILL_CODE_COVERAGE "Enable code coverage" OFF)
option(QUILL_USE_VALGRIND "Use valgrind as the default memcheck tool in CTest (Requires Valgrind)" OFF)
option(QUILL_ENABLE_INSTALL "Enable CMake Install when Quill is not a master project" OFF)
#-------------------------------------------------------------------------------------------------------
# Use newer policies if possible, up to most recent tested version of CMake.
#-------------------------------------------------------------------------------------------------------
if (${CMAKE_VERSION} VERSION_LESS 3.16)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
else ()
cmake_policy(VERSION 3.16)
endif ()
#-------------------------------------------------------------------------------------------------------
# Determine if quill is built as a subproject (using add_subdirectory) or if it is the master project.
#-------------------------------------------------------------------------------------------------------
set(QUILL_MASTER_PROJECT FALSE CACHE BOOL "Master Project" FORCE)
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(QUILL_MASTER_PROJECT TRUE CACHE BOOL "Master Project" FORCE)
endif ()
#-------------------------------------------------------------------------------------------------------
# Custom cmake functions
#-------------------------------------------------------------------------------------------------------
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/quill/cmake" CACHE STRING "Modules for CMake" FORCE)
include(Utility)
#-------------------------------------------------------------------------------------------------------
# Resolve version
#-------------------------------------------------------------------------------------------------------
quill_extract_version()
project(quill VERSION ${QUILL_VERSION} LANGUAGES CXX)
#-------------------------------------------------------------------------------------------------------
# Set default build to release
#-------------------------------------------------------------------------------------------------------
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build" FORCE)
endif ()
#---------------------------------------------------------------------------------------
# Compiler config
#---------------------------------------------------------------------------------------
if (NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif ()
#-------------------------------------------------------------------------------------------------------
# Required Packages
#-------------------------------------------------------------------------------------------------------
find_package(Threads REQUIRED)
if (QUILL_BUILD_TESTS)
enable_testing()
if (QUILL_USE_VALGRIND)
# find valgrind
find_program(MEMORYCHECK_COMMAND NAMES valgrind)
if (NOT MEMORYCHECK_COMMAND)
message(WARNING "Valgrind not found")
endif ()
# set valgrind params
set(MEMORYCHECK_COMMAND_OPTIONS "--tool=memcheck --leak-check=full --leak-resolution=med --show-leak-kinds=all --track-origins=yes --vgdb=no --fair-sched=yes")
# add memcheck test action to ctest
include(CTest)
endif ()
endif ()
#-------------------------------------------------------------------------------------------------------
# Log Info
#-------------------------------------------------------------------------------------------------------
if (QUILL_MASTER_PROJECT)
option(QUILL_VERBOSE_MAKEFILE "Verbose make output" OFF)
message(STATUS "Build Type: " ${CMAKE_BUILD_TYPE})
message(STATUS "Quill Version: ${QUILL_VERSION}")
endif ()
#---------------------------------------------------------------------------------------
# Verbose make file option
#---------------------------------------------------------------------------------------
if (QUILL_VERBOSE_MAKEFILE)
set(CMAKE_VERBOSE_MAKEFILE TRUE CACHE BOOL "Verbose output" FORCE)
endif ()
#-------------------------------------------------------------------------------------------------------
# Additional Compiler Options
#-------------------------------------------------------------------------------------------------------
if (QUILL_NO_EXCEPTIONS)
add_definitions(-DQUILL_NO_EXCEPTIONS)
endif ()
if (QUILL_USE_BOUNDED_QUEUE)
add_definitions(-DQUILL_USE_BOUNDED_QUEUE)
endif ()
if (QUILL_FMT_EXTERNAL)
add_definitions(-DQUILL_FMT_EXTERNAL)
endif ()
message(STATUS "QUILL_NO_EXCEPTIONS: " ${QUILL_NO_EXCEPTIONS})
message(STATUS "QUILL_USE_BOUNDED_QUEUE: " ${QUILL_USE_BOUNDED_QUEUE})
message(STATUS "QUILL_FMT_EXTERNAL: " ${QUILL_FMT_EXTERNAL})
# address sanitizer flags
if (QUILL_SANITIZE_ADDRESS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -fno-omit-frame-pointer -g")
endif ()
# thread sanitizer flags
if (QUILL_SANITIZE_THREAD)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
endif ()
# Append extra options for coverage
if (QUILL_CODE_COVERAGE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
endif ()
# Build Examples
if (QUILL_BUILD_EXAMPLES)
add_subdirectory(examples)
endif ()
if (QUILL_BUILD_BENCHMARKS)
add_subdirectory(benchmarks)
endif ()
add_subdirectory(quill)