-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
227 lines (189 loc) · 7.96 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
# Copyright (C) 2022 Roberto Rossini <roberros@uio.no>
#
# SPDX-License-Identifier: MIT
cmake_minimum_required(VERSION 3.25)
cmake_policy(VERSION 3.25...3.27)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules/")
# Not ideal to use this global variable, but necessary to make sure that tooling and projects use the same version
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_STANDARD 11)
# strongly encouraged to enable this globally to avoid conflicts between -Wpedantic being enabled and -std=c++20 and
# -std=gnu++20 for example when compiling with PCH enabled
set(CMAKE_CXX_EXTENSIONS OFF)
set(ENABLE_DEVELOPER_MODE
OFF
CACHE BOOL "Enable 'developer mode'")
if(BUILD_SHARED_LIBS)
message(
FATAL_ERROR
"Building project with dynamic linking is currently not supported! Please remove option -DBUILD_SHARED_LIBS=ON and re-run cmake."
)
endif()
include(FetchContent)
# cmake-format: off
FetchContent_Declare(
_project_options
URL ${CMAKE_CURRENT_SOURCE_DIR}/external/project_options-v0.28.0.tar.xz
URL_HASH SHA512=216d0970ace00e3176788a2b5abb7b92490c005111d26365e7807a5e86c6323e38b33e2e5b01f4ee43438a8f8e96cacf16cedc6f905a7e0ad58752905b260b38
)
# cmake-format: on
FetchContent_MakeAvailable(_project_options)
include(${_project_options_SOURCE_DIR}/Index.cmake)
include(cmake/Versioning.cmake)
project(
MoDLE
LANGUAGES CXX
VERSION "${MODLE_PROJECT_VERSION_MAJOR}.${MODLE_PROJECT_VERSION_MINOR}.${MODLE_PROJECT_VERSION_PATCH}"
HOMEPAGE_URL https://github.com/paulsengroup/modle
DESCRIPTION "MoDLE: High-performance stochastic modeling of DNA loop extrusion interactions.")
get_property(BUILDING_MULTI_CONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG)
if(BUILDING_MULTI_CONFIG)
if(NOT CMAKE_BUILD_TYPE)
# Make sure that all supported configuration types have their associated conan packages available. You can reduce
# this list to only the configuration types you use, but only if one is not forced-set on the command line for VS
message(TRACE "Setting up multi-config build types")
set(CMAKE_CONFIGURATION_TYPES
Debug Release RelWithDebInfo
CACHE STRING "Enabled build types" FORCE)
else()
message(TRACE "User chose a specific build type, so we are using that")
set(CMAKE_CONFIGURATION_TYPES
${CMAKE_BUILD_TYPE}
CACHE STRING "Enabled build types" FORCE)
endif()
endif()
include(${_project_options_SOURCE_DIR}/src/DynamicProjectOptions.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/CompilerWarnings.cmake)
# dynamic_project_options sets recommended defaults and provides user and developer modes and full GUI support for
# choosing options at configure time
# for more flexibility, look into project_options() macro
# Any default can be overridden set(<feature_name>_DEFAULT <value>) - set default for both user and developer modes
# set(<feature_name>_DEVELOPER_DEFAULT <value>) - set default for developer mode set(<feature_name>_USER_DEFAULT
# <value>) - set default for user mode
# Initialize project_options variable related to this project This overwrites `project_options` and sets
# `project_warnings` uncomment the options to enable them:
set(ENABLE_CACHE_DEFAULT ON)
set(ENABLE_CLANG_TIDY_DEFAULT OFF)
set(ENABLE_COMPILE_COMMANDS_SYMLINK_DEFAULT OFF)
set(ENABLE_CONAN_DEFAULT OFF)
set(ENABLE_CPPCHECK_DEFAULT OFF)
set(ENABLE_DOXYGEN_USER OFF)
set(ENABLE_DOXYGEN_DEVELOPER ON)
set(ENABLE_GCC_ANALYZER_DEFAULT OFF)
set(ENABLE_INTERPROCEDURAL_OPTIMIZATION_DEFAULT ON)
set(ENABLE_NATIVE_OPTIMIZATION_DEFAULT OFF)
set(ENABLE_PCH_DEFAULT OFF)
dynamic_project_options(
CPPCHECK_OPTIONS
--enable=performance,portability,style,warning
--inline-suppr
# We cannot act on a bug/missing feature of cppcheck
--suppress=internalAstError
# if a file does not have an internalAstError, we get an unmatchedSuppression error
--suppress=unmatchedSuppression
--suppress=passedByValue
--inconclusive
MSVC_WARNINGS
${MSVC_WARNINGS}
CLANG_WARNINGS
${CLANG_WARNINGS}
GCC_WARNINGS
${GCC_WARNINGS}
CUDA_WARNINGS
${CUDA_WARNINGS})
# This is used so that source files can include "modle/version/version.hpp" and "modle/version/git.hpp" which is
# automatically generated by CMake
include_directories(${CMAKE_CURRENT_BINARY_DIR}/src/version/include)
option(MODLE_WITH_BOOST_RANDOM "Use Boost's random library instead of that from the STL (recommended)" ON)
option(MODLE_OPTIMIZE_FOR_PROFILING
"Compile project in RelWithDebInfo and with less aggressive optimizations to aid profiling" OFF)
option(
MODLE_ENABLE_ASSERTIONS
"Enable assertions and various other runtime checks (this is done regardless of the type passed to CMAKE_BUILD_TYPE)"
OFF)
option(MODLE_DOWNLOAD_TEST_DATASET "Download datasets required by unit and integration tests" ON)
option(MODLE_ENABLE_TESTING "Build MoDLE's unit tests" ON)
target_compile_features(project_options INTERFACE cxx_std_${CMAKE_CXX_STANDARD})
include(cmake/TestStdlibFeatures.cmake)
target_compile_definitions(project_options
INTERFACE $<$<BOOL:${CHARCONV_VARIANT_AVAILABLE}>:MODLE_CHARCONV_VARIANT_AVAILABLE>)
find_package(Filesystem REQUIRED)
target_link_libraries(project_options INTERFACE std::filesystem)
# Reduce level of optimization to improve the code profiling experience
if(MODLE_OPTIMIZE_FOR_PROFILING)
if(NOT
"${uppercase_CMAKE_BUILD_TYPE}"
STREQUAL
"RelWithDebInfo")
message(
WARNING
"Switching build type from ${CMAKE_BUILD_TYPE} to RelWithDebInfo because MODLE_OPTIMIZE_FOR_PROFILING was set to ON by the user"
)
set(CMAKE_BUILD_TYPE "RelWithDebInfo")
endif()
target_compile_options(project_options INTERFACE -O1 -fno-omit-frame-pointer)
endif()
# Source:
# https://github.com/llvm/llvm-project/blob/656ebd519e3fd52050e1c8abeacafcf94d1fa260/llvm/cmake/modules/HandleLLVMOptions.cmake#L54
if(MODLE_ENABLE_ASSERTIONS)
if(NOT MSVC)
add_definitions(-D_DEBUG)
endif()
# On non-Debug builds cmake automatically defines NDEBUG, so we explicitly undefine it:
if(NOT
uppercase_CMAKE_BUILD_TYPE
STREQUAL
"DEBUG")
# NOTE: use `add_compile_options` rather than `add_definitions` since `add_definitions` does not support generator
# expressions.
target_compile_options(project_options INTERFACE $<$<OR:$<COMPILE_LANGUAGE:C>,$<COMPILE_LANGUAGE:CXX>>:-UNDEBUG>)
# Also remove /D NDEBUG to avoid MSVC warnings about conflicting defines.
foreach(
flags_var_to_scrub
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS_MINSIZEREL
CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS_MINSIZEREL)
string(
REGEX
REPLACE "(^| )[/-]D *NDEBUG($| )"
" "
"${flags_var_to_scrub}"
"${${flags_var_to_scrub}}")
endforeach()
endif()
endif()
if(MODLE_WITH_BOOST_RANDOM)
target_compile_definitions(project_options INTERFACE MODLE_WITH_BOOST_RANDOM=1)
endif()
# Tweak spdlog
target_compile_definitions(
project_options
INTERFACE SPDLOG_CLOCK_COARSE
SPDLOG_DISABLE_DEFAULT_LOGGER
SPDLOG_NO_ATOMIC_LEVELS
SPDLOG_PREVENT_CHILD_FD)
# Tweak fmt
target_compile_definitions(project_options INTERFACE FMT_ENFORCE_COMPILE_STRING)
# Tweak boost
find_package(Boost CONFIG REQUIRED COMPONENTS filesystem)
if(Boost_VERSION_STRING VERSION_GREATER_EQUAL 1.77.0)
target_compile_definitions(project_options INTERFACE BOOST_FILESYSTEM_VERSION=4)
elseif(Boost_VERSION_STRING VERSION_GREATER 1.44.0)
target_compile_definitions(project_options INTERFACE BOOST_FILESYSTEM_VERSION=3)
endif()
if(MODLE_ENABLE_TESTING)
enable_testing()
message("-- Configuring unit tests")
target_compile_definitions(project_options INTERFACE MODLE_ENABLE_TESTING)
if(MODLE_DOWNLOAD_TEST_DATASET)
message("-- Downloading test dataset...")
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/FetchTestDataset.cmake)
endif()
add_subdirectory(test)
endif()
add_subdirectory(src)
include(cmake/FetchExternalDeps.cmake)
# include(cmake/Packaging.cmake)