-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
305 lines (264 loc) · 9.92 KB
/
CMakeLists.txt
File metadata and controls
305 lines (264 loc) · 9.92 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
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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# Copyright 2024 Huawei Technologies Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# @author Toni Boehnlein, Benjamin Lozes, Pal Andras Papp, Raphael S. Steiner
cmake_minimum_required(VERSION 3.12)
project(OneStopParallel VERSION 1.0.0 LANGUAGES CXX)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
# Set C++ standard
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) # Ensure C++17 standard is strictly enforced
# --- Code Coverage (optional) ---
option(ENABLE_COVERAGE "Enable code coverage flags" OFF)
if(ENABLE_COVERAGE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
message(STATUS "Code coverage enabled")
add_compile_options(--coverage -g)
add_link_options(--coverage)
endif()
# Configure git hooks
add_subdirectory(.githooks)
# --- Compile Options Configuration ---
# Common compile options including strict warnings and error-on-warning
set(COMMON_CXX_WARNING_FLAGS
"-Wfatal-errors"
"-Wconversion"
"-Wsign-conversion"
"-Wunreachable-code"
"-Wuninitialized"
"-pedantic"
"-Wpedantic"
"-Wold-style-cast"
"-Wcast-align"
"-Werror"
"-Wall"
"-Wextra"
"-Wundef"
"-Wunused"
"-Wcast-qual"
"-Wpointer-arith"
"-Wdate-time"
"-Wfloat-equal"
"-Wformat=2"
"-Wshadow"
"-Wsign-compare"
"-Wunused-macros"
"-Wvla"
"-Wdisabled-optimization"
"-Wempty-body"
"-Wignored-qualifiers"
"-Wtype-limits"
"-Wshift-negative-value"
"-Wswitch-default"
"-Woverloaded-virtual"
"-Wnon-virtual-dtor"
"-Wshift-overflow=2"
"-Wshift-count-overflow"
"-Wwrite-strings"
"-Wmissing-format-attribute"
"-Wformat-nonliteral"
"-Wduplicated-cond"
"-Wtrampolines"
"-Wsized-deallocation"
"-Wlogical-op"
"-Wsuggest-attribute=format"
"-Wduplicated-branches"
"-Wmissing-include-dirs"
"-Wformat-signedness"
"-Wreturn-local-addr"
"-Wredundant-decls"
"-Wfloat-conversion"
"-fno-common"
"-fno-strict-aliasing"
"-Wno-return-type"
"-Wno-array-bounds"
"-Wno-maybe-uninitialized"
"-Wno-unused-but-set-variable"
"-Wno-unused-variable"
"-Wno-unused-parameter"
"-Wno-unused-result"
)
# --- Project-specific Compile Flags ---
# An interface library to hold compile flags for executables built in this project.
add_library(ProjectExecutableFlags INTERFACE)
target_compile_options(ProjectExecutableFlags INTERFACE ${COMMON_CXX_WARNING_FLAGS})
# Set build-type specific compile options
target_compile_options(ProjectExecutableFlags INTERFACE
$<IF:$<CONFIG:Debug>,
# Debug flags
-g,
# Else (not Debug)
$<IF:$<CONFIG:RelWithDebInfo>,
# RelWithDebInfo flags
-O3;-g;-DNDEBUG,
# Release and other/custom flags
-O3;-DNDEBUG
>
>
)
# Flag for address sanitizer
option(ENABLE_ASAN "Enable Address Sanitizer" OFF)
if (ENABLE_ASAN)
message(STATUS "Address sanitizer enabled.")
target_compile_options(ProjectExecutableFlags INTERFACE -fsanitize=address)
target_link_options(ProjectExecutableFlags INTERFACE -fsanitize=address)
endif ()
# Flag for undefined behaviour sanitizer
option(ENABLE_UBSAN "Enable Undefined Behaviour Sanitizer" OFF)
if (ENABLE_UBSAN)
message(STATUS "Undefined behaviour sanitizer enabled.")
target_compile_options(ProjectExecutableFlags INTERFACE -fsanitize=undefined)
target_link_options(ProjectExecutableFlags INTERFACE -fsanitize=undefined)
endif ()
# --- Find External Libraries ---
# Find COPT libraries
find_package(COPT)
# Find Boost libraries
find_package(Boost 1.71.0 OPTIONAL_COMPONENTS graph unit_test_framework)
# The modern CMake approach uses target-based properties, so global include_directories is avoided.
if(NOT Boost_FOUND)
message(WARNING "Boost not found. Any features or tests depending on it will be disabled.")
endif()
# Find Eigen
find_package(Eigen3 3.4)
if(Eigen3_FOUND)
message(STATUS "Eigen3 found!")
else()
message(WARNING "Eigen3 not found. Some features may be disabled.")
endif()
# Find OpenMP
find_package(OpenMP)
if(OpenMP_FOUND)
set(OSP_DEPENDS_ON_OPENMP ON)
message(STATUS "OpenMP found, enabling OpenMP support.")
else()
set(OSP_DEPENDS_ON_OPENMP OFF)
message(WARNING "OpenMP not found. The library will be built without OpenMP support.")
endif()
# --- Library Definition ---
add_library(OneStopParallel INTERFACE)
target_include_directories(OneStopParallel INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>
)
# Display status messages for build types
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "Configuring for Debug build. Debug symbols enabled.")
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
message(STATUS "Configuring for Release build. Optimization -O3 and NDEBUG enabled.")
elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
message(STATUS "Configuring for Release with Debug Info build. Optimization -O3 and debug symbols enabled.")
elseif(CMAKE_BUILD_TYPE STREQUAL "Library")
message(STATUS "Configuring for Library build. Only installing headers.")
else()
message(STATUS "Configuring for custom build type '${CMAKE_BUILD_TYPE}'. Applying default optimization and warnings.")
endif()
if(OpenMP_FOUND)
target_link_libraries(OneStopParallel INTERFACE OpenMP::OpenMP_CXX)
endif()
if(Boost_graph_FOUND)
set(OSP_DEPENDS_ON_BOOST_GRAPH ON)
target_link_libraries(OneStopParallel INTERFACE Boost::graph)
else()
set(OSP_DEPENDS_ON_BOOST_GRAPH OFF)
endif()
if (COPT_FOUND)
target_link_libraries(OneStopParallel INTERFACE COPT::COPT)
list(APPEND CMAKE_BUILD_RPATH ${COPT_RPATHS})
endif()
if(Eigen3_FOUND)
target_link_libraries(OneStopParallel INTERFACE Eigen3::Eigen)
target_compile_definitions(OneStopParallel INTERFACE EIGEN_FOUND)
endif()
# --- Subdirectories for Source and Executables ---
if(CMAKE_BUILD_TYPE STREQUAL "Library")
message(STATUS "Library build type: apps will not be built by 'make all' or 'make install'.")
add_subdirectory(apps EXCLUDE_FROM_ALL)
add_subdirectory(apps/graph_generator EXCLUDE_FROM_ALL)
else()
message(STATUS "Build type is not Library: apps will be built by 'make all' and 'make install'.")
add_subdirectory(apps)
add_subdirectory(apps/graph_generator)
endif()
# --- Build Tests Configuration ---
# Option to control whether tests are built.
set(OSP_DATA_DIR ${PROJECT_SOURCE_DIR}/data CACHE INTERNAL "Path to project data files")
# Defaults to ON, but will be OFF if CMAKE_BUILD_TYPE is Library.
option(BUILD_TESTS "Build tests for the project" ON)
if(CMAKE_BUILD_TYPE STREQUAL "Library")
set(BUILD_TESTS OFF)
message(STATUS "CMAKE_BUILD_TYPE is Library, so BUILD_TESTS is forced to OFF.")
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Release")
set(BUILD_TESTS OFF)
message(STATUS "CMAKE_BUILD_TYPE is Release, so BUILD_TESTS is forced to OFF.")
endif()
if(BUILD_TESTS)
# Check if Boost::unit_test_framework was found for tests to be enabled.
if(NOT Boost_graph_FOUND)
message(WARNING "Boost::graph component not found. Tests require it and will be disabled.")
elseif(NOT Boost_unit_test_framework_FOUND)
message(WARNING "Boost::unit_test_framework component not found. Tests require it and will be disabled.")
elseif(NOT OpenMP_FOUND)
message(WARNING "OpenMP not found. Tests require it and will be disabled.")
else()
enable_testing()
add_subdirectory(tests)
message(STATUS "Tests will be built.")
endif()
else()
message(STATUS "Tests will not be built (BUILD_TESTS is OFF).")
endif()
# --- Documentation Generation ---
# Add a custom target to build Doxygen documentation
find_package(Doxygen QUIET)
if(DOXYGEN_FOUND)
add_custom_target(doc
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/doc/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM
)
message(STATUS "Doxygen found. 'doc' target available for building documentation.")
else()
message(STATUS "Doxygen not found. Documentation target 'doc' will not be available.")
endif()
# --- Installation ---
# Set a default installation prefix for local development if the user has not specified one.
#if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
# set(CMAKE_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/install" CACHE PATH "Default install path for developer builds" FORCE)
# message(STATUS "Setting default install prefix to ${CMAKE_INSTALL_PREFIX}")
#endif()
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
install(TARGETS OneStopParallel EXPORT OneStopParallelTargets)
install(DIRECTORY include/
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/OneStopParallelConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY AnyNewerVersion
)
configure_package_config_file(cmake/OneStopParallelConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/OneStopParallelConfig.cmake"
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OneStopParallel
)
install(EXPORT OneStopParallelTargets
FILE OneStopParallelTargets.cmake
NAMESPACE OneStopParallel::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OneStopParallel
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/OneStopParallelConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/OneStopParallelConfigVersion.cmake"
"${PROJECT_SOURCE_DIR}/cmake/FindCOPT.cmake"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/OneStopParallel
)