-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
155 lines (113 loc) · 4.25 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
cmake_minimum_required(VERSION 3.21)
##############################################################
# Language setup
##############################################################
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
##############################################################
# Establish project
##############################################################
project(loki VERSION "0.0.1" LANGUAGES C CXX)
# Compilation flags, some configuration-specific
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wextra -Wuninitialized -pedantic -fPIC")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -fomit-frame-pointer")
set(CMAKE_CXX_FLAGS_DEBUG "-O3 -DDEBUG")
# Set a default build type if none was specified
set(default_build_type "Debug")
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Setting build type to '${default_build_type}', as none was specified.")
set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
STRING "Choose the type of build." FORCE)
endif()
message(STATUS "Build configuration: ${CMAKE_BUILD_TYPE}")
# make cache variables for install destinations
include(GNUInstallDirs)
option(BUILD_TESTS "Enables compilation of tests." OFF)
if (BUILD_TESTS)
message("Build tests enabled.")
else()
message("Build tests disabled.")
endif()
option(BUILD_BENCHMARKS "Enables compilation of tests." OFF)
if (BUILD_BENCHMARKS)
message("Build benchmarks enabled.")
else()
message("Build benchmarks disabled.")
endif()
set(DATA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/data/")
add_definitions(-DDATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data/")
message("DATA_DIR: ${DATA_DIR}")
##############################################################
# CMake modules and macro files
##############################################################
list(APPEND CMAKE_MODULE_PATH
"${PROJECT_SOURCE_DIR}/cmake"
)
include("configure_boost")
include("configure_ccache")
##############################################################
# CCache
##############################################################
configure_ccache()
##############################################################
# Dependency Handling
##############################################################
# set(CMAKE_FIND_DEBUG_MODE ON)
# Boost
# Find Boost headers only according to https://cmake.org/cmake/help/latest/module/FindBoost.html
configure_boost()
find_package(Boost ${BOOST_MIN_VERSION} REQUIRED PATHS ${CMAKE_PREFIX_PATH} NO_DEFAULT_PATH)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
message(STATUS "Found Boost: ${Boost_DIR} (found version ${Boost_VERSION})")
endif()
##############################################################
# Add library and executable targets
##############################################################
add_subdirectory(src)
add_subdirectory(exe)
add_subdirectory(examples)
if (BUILD_TESTS)
add_subdirectory(tests)
endif()
if (BUILD_BENCHMARKS)
add_subdirectory(benchmarks)
endif()
###########
# Install #
###########
# Install header files
install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/loki"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
# Install cmake scripts
install(
DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/cmake/"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/loki/cmake"
)
###########
# Exports #
###########
# https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html
include(CMakePackageConfigHelpers)
# Generate the version file for the config file
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/lokiConfigVersion.cmake"
VERSION ${loki_VERSION}
COMPATIBILITY ExactVersion
)
# Create config file
# https://cmake.org/cmake/help/book/mastering-cmake/cmake/Help/guide/importing-exporting/index.html
# https://cmake.org/cmake/help/latest/module/CMakePackageConfigHelpers.html#generating-a-package-configuration-file
configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/Config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/lokiConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/loki"
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
# Install config files
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/lokiConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/lokiConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/loki"
)