-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathCMakeLists.txt
229 lines (191 loc) · 7.82 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
################################################################################
# CMakeLists.txt
#
# Root CMake build script for generator
#
# Copyright (C) 2016-2017 Sebastian Lamm <lamm@ira.uka.de>
#
# All rights reserved. Published under the BSD-2 license in the LICENSE file.
################################################################################
cmake_minimum_required(VERSION 3.16)
project(kagen LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 20)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
################################################################################
option(KAGEN_NODEPS "Build KaGen without any dependencies." OFF)
option(KAGEN_USE_MARCH_NATIVE "Compile with -march=native." OFF)
option(KAGEN_USE_CGAL "If available, link against CGal to enable RDG generators." ON)
option(KAGEN_USE_SPARSEHASH "Build with Google Sparsehash. If turned off, fall back to std::unordered_map<>." ON)
option(KAGEN_USE_FAST_MATH "Use -ffast-math." OFF)
option(KAGEN_USE_MKL "Build with Intel MKL random generator." OFF)
option(KAGEN_USE_XXHASH "Build with xxHash. If turned off, path permutation will not be available." ON)
option(KAGEN_WARNINGS_ARE_ERRORS "Make compiler warnings compiler errors." OFF)
option(KAGEN_BUILD_TESTS "Build unit tests." OFF)
option(KAGEN_BUILD_APPS "Build binaries." ON)
option(KAGEN_BUILD_EXAMPLES "Build examples." ON)
################################################################################
include(FetchContent)
FetchContent_Declare(googletest
SYSTEM
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.12.1)
################################################################################
# If KAGEN_NODEPS is set, disable all dependency flags
if (KAGEN_NODEPS)
message(STATUS "Building without any dependencies.")
set(KAGEN_USE_CGAL OFF)
set(KAGEN_USE_SPARSEHASH OFF)
set(KAGEN_USE_MKL OFF)
set(KAGEN_USE_XXHASH OFF)
set(KAGEN_BUILD_TESTS OFF) # requires GoogleTest
endif ()
# Prohibit in-source builds
if ("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}")
message(SEND_ERROR "In-source builds are not allowed.")
endif ()
# Default to Release building for single-config generators
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Defaulting CMAKE_BUILD_TYPE to Release")
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type")
endif ()
# Warning flags
list(APPEND KAGEN_WARNING_FLAGS
"-W"
"-Wall"
"-Wextra"
"-Wpedantic"
"-Wno-unused-local-typedefs"
)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
list(APPEND KAGEN_WARNING_FLAGS
"-Wextra-semi"
"-fcolor-diagnostics"
"-Wdeprecated"
)
endif ()
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
list(APPEND KAGEN_WARNING_FLAGS
"-Wsuggest-override"
"-fdiagnostics-color=always"
"-Wcast-qual"
"-Winit-self"
"-Woverloaded-virtual"
"-Wredundant-decls"
)
endif ()
if (KAGEN_WARNINGS_ARE_ERRORS)
list(APPEND KAGEN_WARNING_FLAGS "-Werror")
endif ()
# Enable -march=native on Debug and Release builds
if (KAGEN_USE_MARCH_NATIVE)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-march=native" KAGEN_HAS_MARCH_NATIVE)
if(KAGEN_HAS_MARCH_NATIVE)
list(APPEND CMAKE_CXX_FLAGS "-march=native")
endif ()
endif ()
# Remove -rdynamic from linker flags (smaller binaries which cannot be loaded
# with dlopen() -- something no one needs)
string(REGEX REPLACE "-rdynamic" "" CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_C_FLAGS}")
string(REGEX REPLACE "-rdynamic" "" CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "${CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS}")
# Enable UndefinedBehaviorSanitizer
if (OFF)
list(APPEND CMAKE_CXX_FLAGS "-fsanitize=undefined")
endif ()
# Use -ffast-math
if (KAGEN_USE_FAST_MATH)
list(APPEND CMAKE_CXX_FLAGS "-ffast-math")
endif ()
###############################################################################
# libmorton
###############################################################################
add_library(morton INTERFACE)
target_include_directories(morton SYSTEM INTERFACE extlib/libmorton/include)
list(APPEND KAGEN_LINK_LIBRARIES morton)
###############################################################################
# xxHash
###############################################################################
if (KAGEN_USE_XXHASH)
message(STATUS "Building with xxHash")
set(${PROJECT_NAME}_XXHASH_DIR "${CMAKE_CURRENT_LIST_DIR}/extlib/xxHash")
set(BUILD_SHARED_LIBS OFF)
set(XXHASH_BUILD_ENABLE_INLINE_API ON)
set(XXHASH_BUILD_XXHSUM OFF)
add_subdirectory("${${PROJECT_NAME}_XXHASH_DIR}/cmake_unofficial" EXCLUDE_FROM_ALL)
list(APPEND KAGEN_LINK_LIBRARIES xxHash::xxhash)
add_definitions(-DKAGEN_XXHASH_FOUND)
endif ()
###############################################################################
# MPI
###############################################################################
set(MPI_DETERMINE_LIBRARY_VERSION TRUE) # needed for KaTestrophe
find_package(MPI REQUIRED)
list(APPEND KAGEN_LINK_LIBRARIES MPI::MPI_CXX)
###############################################################################
# pthread
###############################################################################
find_package(Threads REQUIRED)
list(APPEND KAGEN_LINK_LIBRARIES Threads::Threads)
###############################################################################
# Google Sparsehash
###############################################################################
if (KAGEN_USE_SPARSEHASH)
message(STATUS "Building with Sparsehash")
find_package(Sparsehash REQUIRED)
list(APPEND KAGEN_LINK_LIBRARIES Sparsehash::Sparsehash)
add_definitions(-DKAGEN_SPARSEHASH_FOUND)
endif ()
###############################################################################
# CGAL
###############################################################################
if (KAGEN_USE_CGAL)
set(CGAL_DO_NOT_WARN_ABOUT_CMAKE_BUILD_TYPE TRUE CACHE BOOL "Do not warn about Debug mode")
set(CGAL_DONT_OVERRIDE_CMAKE_FLAGS TRUE CACHE BOOL "Force CGAL to maintain CMAKE flags")
find_package(CGAL QUIET)
if (CGAL_FOUND)
add_definitions(-DKAGEN_CGAL_FOUND)
if (${CGAL_VERSION} VERSION_GREATER_EQUAL 5)
list(APPEND KAGEN_LINK_LIBRARIES CGAL::CGAL)
else()
include(${CGAL_USE_FILE})
endif()
else ()
message(STATUS "Could not find the CGAL library: Random Delaunay Graphs will not be available")
endif ()
endif ()
###############################################################################
# Sampling library -> MKL
###############################################################################
if (KAGEN_USE_MKL)
find_package(MKL)
if (MKL_FOUND)
message(STATUS "Building with MKL")
list(APPEND KAGEN_INCLUDE_DIRS ${MKL_INCLUDE_DIR})
list(APPEND KAGEN_LINK_LIBRARIES ${MKL_LP_LIBRARY} ${MKL_CORE_LIBRARY} ${MKL_SEQUENTIAL_LIBRARY})
add_definitions(-DSAMPLING_HAVE_MKL)
add_definitions(-DRMAT_HAVE_MKL)
add_definitions(-DKAGEN_MKL_FOUND)
else ()
message(STATUS "MKL requested but not found, building without MKL")
endif ()
endif ()
################################################################################
add_subdirectory(kagen)
if (KAGEN_BUILD_APPS)
add_subdirectory(app)
else ()
message(STATUS "Apps disabled.")
endif ()
if (KAGEN_BUILD_EXAMPLES)
add_subdirectory(examples)
else ()
message(STATUS "Examples disabled.")
endif ()
################################################################################
add_library(KaGen::KaGen ALIAS kagen)
add_library(KaGen::cKaGen ALIAS kagen) # @deprecated, use KaGen::KaGen
################################################################################
if (KAGEN_BUILD_TESTS)
enable_testing()
add_subdirectory(tests)
endif ()