-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
124 lines (96 loc) · 3.49 KB
/
CMakeLists.txt
File metadata and controls
124 lines (96 loc) · 3.49 KB
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
cmake_minimum_required(VERSION 3.21)
##############################################################
# Language setup
##############################################################
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
##############################################################
# Build Targets
##############################################################
option(BUILD_TESTS "Build" OFF)
option(BUILD_PROFILING "Build" OFF)
##############################################################
# Establish project
##############################################################
project(valla VERSION 0.1 LANGUAGES C CXX)
include(GNUInstallDirs)
# Compilation flags, some configuration-specific -fsanitize=address -fsanitize-recover=address
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wextra -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()
option(ENABLE_TESTING "Enables compilation of tests." OFF)
if (ENABLE_TESTING)
message("Building tests enabled.")
else()
message("Building tests disabled.")
endif()
if(VERBOSE)
add_compile_definitions(VERBOSE)
endif()
##############################################################
# Dependency Handling
##############################################################
find_package(fmt REQUIRED PATHS ${CMAKE_PREFIX_PATH} NO_DEFAULT_PATH)
if(fmt_FOUND)
include_directories(${fmt_INCLUDE_DIRS})
message(STATUS "Found fmt: ${fmt_DIR} (found version ${fmt_VERSION})")
endif()
##############################################################
# Add library and executable targets
##############################################################
# ------------
# Target valla
# ------------
add_subdirectory(src)
# ----------------
# Target Profiling
# ----------------
if(BUILD_PROFILING)
add_subdirectory(benchmark)
endif()
# -----------
# Target Test
# -----------
if(BUILD_TESTS)
add_subdirectory(tests)
endif()
###########
# Install #
###########
# Install header files
install(DIRECTORY "${PROJECT_SOURCE_DIR}/include/valla"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}")
###########
# 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}/vallaConfigVersion.cmake"
VERSION ${valla_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}/vallaConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/valla"
NO_CHECK_REQUIRED_COMPONENTS_MACRO
)
# Install config files
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/vallaConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/vallaConfigVersion.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/valla"
)