generated from abdes/asap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
252 lines (211 loc) · 9.89 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
# ===-----------------------------------------------------------------------===#
# Distributed under the 3-Clause BSD License. See accompanying file LICENSE or
# copy at https://opensource.org/licenses/BSD-3-Clause).
# SPDX-License-Identifier: BSD-3-Clause
# ===-----------------------------------------------------------------------===#
# ------------------------------------------------------------------------------
# CMake basic options
# ------------------------------------------------------------------------------
# It's time to move on! We require 3.14 for modern CMake with nice quality of
# life features and simpler scripts.
cmake_minimum_required(VERSION 3.14)
# List of directories specifying a search path for CMake modules to be loaded by
# the the include() or find_package() commands before checking the default
# modules that come with CMake.
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
# ------------------------------------------------------------------------------
# Project description and (meta) information
# ------------------------------------------------------------------------------
# Get git revision
find_package(Git REQUIRED)
include(GetGitRevisionDescription)
get_git_head_revision(GIT_REFSPEC GIT_SHA1)
string(SUBSTRING "${GIT_SHA1}" 0 12 GIT_REV)
if(NOT GIT_SHA1)
set(GIT_REV "0")
endif()
# Meta information about the project
# cmake-format: off
set(META_PROJECT_NAME "asap-fsm")
set(META_PROJECT_DESCRIPTION "C++ template-based Finite State Machines.")
set(META_AUTHOR_ORGANIZATION "The Authors")
set(META_GITHUB_REPO "https://github.com/asap-projects/asap-fsm")
set(META_AUTHOR_DOMAIN "https://github.com/asap-projects")
set(META_AUTHOR_MAINTAINER "Abdessattar Sassi")
set(META_VERSION_MAJOR "1")
set(META_VERSION_MINOR "0")
set(META_VERSION_PATCH "3")
set(META_VERSION_REVISION "${GIT_REV}")
set(META_VERSION "${META_VERSION_MAJOR}.${META_VERSION_MINOR}.${META_VERSION_PATCH}")
set(META_NAME_VERSION "${META_PROJECT_NAME} v${META_VERSION} (${META_VERSION_REVISION})")
set(META_CMAKE_INIT_SHA "${GIT_REV}")
# cmake-format: on
string(MAKE_C_IDENTIFIER ${META_PROJECT_NAME} META_PROJECT_ID)
string(TOUPPER ${META_PROJECT_ID} META_PROJECT_ID)
# Determine if this is built as a subproject or if it is the master project.
if(NOT DEFINED ${META_PROJECT_ID}_IS_MASTER_PROJECT)
set(${META_PROJECT_ID}_IS_MASTER_PROJECT OFF)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(${META_PROJECT_ID}_IS_MASTER_PROJECT ON)
endif()
endif()
message(
"=> Project : ${META_NAME_VERSION} (IS_MASTER: ${${META_PROJECT_ID}_IS_MASTER_PROJECT})"
)
# ------------------------------------------------------------------------------
# Project configuration options
# ------------------------------------------------------------------------------
# Project options
# cmake-format: off
option(BUILD_SHARED_LIBS "Build shared instead of static libraries." ON)
option(ASAP_BUILD_TESTS "Build tests." OFF)
option(ASAP_BUILD_EXAMPLES "Build examples." OFF)
option(ASAP_WITH_GOOGLE_ASAN "Instrument code with address sanitizer" OFF)
option(ASAP_WITH_GOOGLE_UBSAN "Instrument code with undefined behavior sanitizer" OFF)
option(ASAP_WITH_GOOGLE_TSAN "Instrument code with thread sanitizer" OFF)
option(ASAP_WITH_VALGRIND "Builds targets with valgrind profilers added" OFF)
# cmake-format: on
# ------------------------------------------------------------------------------
# Project Declaration
# ------------------------------------------------------------------------------
# Generate folders for IDE targets (e.g., VisualStudio solutions)
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(IDE_FOLDER "${META_PROJECT_NAME}")
# Declare project
project(
${META_PROJECT_NAME}
VERSION ${META_VERSION}
DESCRIPTION ${META_PROJECT_DESCRIPTION}
HOMEPAGE_URL ${META_GITHUB_REPO}
LANGUAGES C CXX)
# Set output directories
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
# ------------------------------------------------------------------------------
# Additional CMake modules
# ------------------------------------------------------------------------------
# Register general cmake commands
include(AsapTargets)
include(BuildHelpers)
include(GenerateExportHeader)
include(CompileOptions)
# Override the ${META_PROJECT_ID}_INSTALL option to ON/OFF to respectively force
# install/no-install behavior for this project. This is particularly useful when
# this project is used as a sub-project and the user publicly depends on it and
# wants to have a self-contained install.
include(AsapInstall)
# The default build type provided by CMake is to include no compiler flags for
# optimization. For some projects you may want to set a default build type so
# that you do not have to remember to set it.
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(
STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
set(CMAKE_BUILD_TYPE
RelWithDebInfo
CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
endif()
# If no contract mode is specified, we set the contract mode based on the build
# type.
if(NOT OPTION_CONTRACT_MODE)
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(OPTION_CONTRACT_MODE
"AUDIT"
CACHE STRING "Contract mode for assertions (common module).")
elseif(CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo)
set(OPTION_CONTRACT_MODE
"DEFAULT"
CACHE STRING "Contract mode for assertions (common module).")
else()
set(OPTION_CONTRACT_MODE
"OFF"
CACHE STRING "Contract mode for assertions (common module).")
endif()
endif()
message(
"-- Building for ${CMAKE_BUILD_TYPE} with OPTION_CONTRACT_MODE : ${OPTION_CONTRACT_MODE}"
)
include(FetchContent)
# We make sure that we have 'third_party' in the name so that the targets get
# excluded from the generated target lists for the various tools.
set(FETCHCONTENT_BASE_DIR ${CMAKE_BINARY_DIR}/third_party_deps)
# ------------------------------------------------------------------------------
# Testing
# ------------------------------------------------------------------------------
if(ASAP_BUILD_TESTS)
include(GoogleSanitizers)
include(CodeCoverage)
# Enable this target when the project has test cases
asap_add_code_coverage_all_targets(EXCLUDE */test/* *googlemock* *googletest*
/usr/*)
include(Valgrind)
include(FetchGoogleTest)
include(GoogleTest)
include(CTest)
endif()
# ------------------------------------------------------------------------------
# RPATH setup
# ------------------------------------------------------------------------------
# Set runtime path
set(CMAKE_SKIP_BUILD_RPATH FALSE) # Add absolute path to all dependencies for
# BUILD
set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH FALSE)
if(NOT SYSTEM_DIR_INSTALL)
# Find libraries relative to binary
if(APPLE)
set(CMAKE_INSTALL_RPATH "@loader_path/../../../${ASAP_INSTALL_LIB}")
else()
set(CMAKE_INSTALL_RPATH "$ORIGIN/${ASAP_INSTALL_LIB}")
endif()
endif()
# ------------------------------------------------------------------------------
# Top level code generation
# ------------------------------------------------------------------------------
# Generate version-header
configure_file(templates/version.h.in
${CMAKE_CURRENT_BINARY_DIR}/include/asap/asap-version.h)
# Generate a clangd configuration file that points to the compilation database
# in the cmake build directory. We need to do this as the build directory is
# different for every preset and can be different as well when the user decides
# to build somewhere else. Currently we cannot configure this properly in vscode
# settings. See https://github.com/clangd/vscode-clangd/issues/48
configure_file(.clangd.in ${CMAKE_SOURCE_DIR}/.clangd @ONLY)
# ------------------------------------------------------------------------------
# Documentation - doxygen, sphinx/breathe/exhale
# ------------------------------------------------------------------------------
# Doxygen
set(DOXYGEN_BUILD_DIR "${CMAKE_BINARY_DIR}/dox")
include(DoxGeneration)
# Sphinx/breathe/exhale
set(SPHINX_BUILD_DIR "${CMAKE_BINARY_DIR}/sphinx")
include(SphinxGeneration)
# ==============================================================================
# Third party modules
# ==============================================================================
add_subdirectory(third_party)
# ==============================================================================
# Project modules
# ==============================================================================
add_subdirectory(fsm)
# ==============================================================================
# Code analyzers: clang-tidy, cppcheck, valgrind, sanitizers, etc...
#
# Call after sub-modules have been added so that source code files can be
# properly collected for analysis.
# ==============================================================================
if(${META_PROJECT_ID}_IS_MASTER_PROJECT)
include(ClangFormat)
include(ClangTidy)
# Enable this target when the project has header or source files (.h or .cpp)
asap_setup_clang_format()
# Enable this target when the project has source files (.cpp)
asap_create_clang_tidy_targets()
endif()
# ==============================================================================
# Deployment (global project files)
# ==============================================================================
asap_top_level_install()