-
Notifications
You must be signed in to change notification settings - Fork 19
/
CMakeLists.txt
345 lines (270 loc) · 12.8 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
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
#============= 0. GENERIC CONFIGURATION ==============================
cmake_minimum_required(VERSION 2.6.4 FATAL_ERROR)
set(PACKAGE_NAME libgeodecomp)
set(PACKAGE_VERSION "0.4.0")
set(PACKAGE_VENDOR "Ste||ar Group")
set(PACKAGE_HOMEPAGE "http:\\\\www.libgeodecomp.org")
set(PACKAGE_EMAIL "[email protected]")
project(${PACKAGE_NAME})
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")
include(util)
include(CheckCXXCompilerFlag)
include(CheckLanguage)
if (CMAKE_VERSION VERSION_GREATER 2.7)
cmake_policy(SET CMP0012 NEW)
endif()
if (NOT CMAKE_VERSION VERSION_LESS 3.18)
cmake_policy(SET CMP0104 NEW)
endif()
# this is a workaround for CMake complaining about the interface
# include path of geodecomp.lib including the current build
# directory.
if(WIN32)
cmake_policy(SET CMP0041 OLD)
endif()
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
get_directory_property(lgd_has_parent PARENT_DIRECTORY)
#============= 1. FIND PACKAGES WE DEPEND ON =========================
find_package(HPX QUIET)
if(NOT HPX_FOUND)
if(NOT DEFINED BOOST_ROOT)
# deduce Boost location from environment (e.g. on woody.rrze.uni-erlangen.de)
set(BOOST_ENV_LIBDIR "$ENV{BOOST_LIBDIR}")
if(BOOST_ENV_LIBDIR)
set(Boost_NO_SYSTEM_PATHS true)
set(BOOST_ROOT "$ENV{BOOST_LIBDIR}/../")
set(Boost_LIBRARY_DIRS "$ENV{BOOST_LIBDIR}")
set(Boost_INCLUDE_DIRS "$ENV{BOOST_INCDIR}")
endif()
endif()
else()
# If HPX was found, we use the Boost libraries found by HPX
set(ALL_BOOST_LIBS ${HPX_LIBRARIES})
endif()
find_package(Boost QUIET COMPONENTS serialization)
set(Boost_SERIALIZATION_LIBRARIES "${Boost_LIBRARIES}")
find_package(Boost QUIET COMPONENTS mpi)
set(Boost_MPI_LIBRARIES "${Boost_LIBRARIES}")
# search for external LibFlatArray, but -- if none was found -- default to bundled version:
find_package(libflatarray QUIET)
if(NOT libflatarray_FOUND)
add_subdirectory(lib/libflatarray)
# add this include paths only to BUILD_INCLUDE_DIRECTORIES as must
# not be exported during install in any case (the build tree must be
# considered a temporary directory, and CMake would complain).
list(APPEND BUILD_INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}/lib/libflatarray/include")
else()
message(STATUS External LibFlatArray at ${libflatarray_INCLUDE_DIRS})
# if LibFlatArray was found outside, we'll assume we're not using
# the bundled version and we need export the relevant directory:
list(APPEND INSTALL_INCLUDE_DIRECTORIES ${libflatarray_INCLUDE_DIRS})
endif()
# currently VisIt only supports Python 2.x. This (undocumented?)
# feature of CMake allows us to avoid Python 3.y.
set(PythonLibs_FIND_VERSION 2)
# setting this variable is required since CMake 3.0
set(PythonLibs_FIND_VERSION_MAJOR 2)
if(CMAKE_VERSION VERSION_LESS 3.10)
find_package(CUDA QUIET)
if(NOT DEFINED CUDA_FOUND)
set(CUDA_FOUND false)
endif()
else()
check_language(CUDA)
if(CMAKE_CUDA_COMPILER)
enable_language(CUDA)
set(CUDA_FOUND true)
else()
set(CUDA_FOUND false)
endif()
endif()
find_package(Doxygen)
find_package(OpenCL)
find_package(MPI)
find_package(OpenCV)
find_package(OpenMP)
find_package(PythonLibs)
find_package(Ruby)
find_package(SCOTCH)
find_package(Silo)
find_package(Qt5 COMPONENTS OpenGL Gui Core Widgets)
find_package(VisIt)
# if a package was not found it's safer to set the corresponding
# variable to false, this avoids undefined/unintended behavior in some
# cases.
if(NOT DEFINED Boost_SERIALIZATION_FOUND)
set(Boost_SERIALIZATION_FOUND false)
endif()
if(NOT DEFINED Boost_MPI_FOUND)
set(Boost_MPI_FOUND false)
endif()
if(NOT DEFINED Boost_MOVE_FOUND)
set(Boost_MOVE_FOUND false)
endif()
if(NOT DEFINED DOXYGEN_FOUND)
set(DOXYGEN_FOUND false)
endif()
if(NOT DEFINED HPX_FOUND)
set(HPX_FOUND false)
endif()
if(NOT DEFINED MPI_FOUND)
set(MPI_FOUND false)
endif()
if(NOT DEFINED OpenCV_FOUND)
set(OpenCV_FOUND false)
endif()
if(NOT DEFINED OPENMP_FOUND)
set(OPENMP_FOUND false)
endif()
if(NOT DEFINED PYTHONLIBS_FOUND)
set(PYTHONLIBS_FOUND false)
endif()
if(NOT DEFINED Qt5_FOUND)
set(Qt5_FOUND false)
endif()
if(NOT DEFINED RUBY_FOUND)
set(RUBY_FOUND false)
endif()
if(NOT DEFINED SCOTCH_FOUND)
set(SCOTCH_FOUND false)
endif()
if(NOT DEFINED Silo_FOUND)
set(Silo_FOUND false)
endif()
#============= 2. DETECT DEFAULTS ====================================
set(RELEASE false)
lgd_detect_distro()
# A word on the various CMake compiler flag variables used inside LibGeoDecomp:
#
# DEFAULT_C_FLAGS, DEFAULT_CXX_FLAGS, NVCC_FLAGS standard flags which may depend on the compiler,
# | | | but not on 3rd party packages being installed.
# _|_ _|_ |
# \ / \ / |
# Y Y |
# LGD_ADDITIONAL_C/CXX_COMPILE_FLAGS | May be overridden by the user via CMake.
# | | |
# _|_ _|_ |
# \ / \ / |
# Y Y |
# LGD_AGGREGATED_C/CXX_FLAGS | Adds flags exported from packages used by LGD,
# | | | exported to the parent scope of a CMake project
# _|_ _|_ | if LGD is nested.
# \ / \ / |
# Y Y |
# CMAKE_C_FLAGS, CMAKE_CXX_FLAGS | Default CMake variables
# | | |
# _|_ _|_ _|_
# \ / \ / \ /
# Y Y Y
# C compiler C++ compiler nvcc
# |
# _|_
# \ /
# Y
# libgeodecomp_FLAGS Exported via the CMake module
#
if (MSVC)
# -Wall on Microsoft Visual C++ generates too much noise
set(DEFAULT_C_FLAGS "${DEFAULT_C_FLAGS} /W4")
set(DEFAULT_CXX_FLAGS "${DEFAULT_CXX_FLAGS} /W4")
else()
set(DEFAULT_C_FLAGS "${DEFAULT_C_FLAGS} -Wall")
set(DEFAULT_CXX_FLAGS "${DEFAULT_CXX_FLAGS} -Wall")
endif()
check_cxx_compiler_flag("-Wno-sign-conversion" SUPPORTS_WARN_NO_WSIGN)
if(SUPPORTS_WARN_NO_WSIGN)
set(DEFAULT_CXX_FLAGS "${DEFAULT_CXX_FLAGS} -Wno-sign-conversion")
endif()
check_cxx_compiler_flag("-Wnon-virtual-dtor" SUPPORTS_WARN_NON_VIRTUAL_DTOR)
if(SUPPORTS_WARN_NON_WSIGN)
set(DEFAULT_CXX_FLAGS "${DEFAULT_CXX_FLAGS} -Wnon-virtual-dtor")
endif()
check_cxx_compiler_flag("-fdiagnostics-color=always" SUPPORTS_COLOR)
if(SUPPORTS_COLOR)
set(DEFAULT_C_FLAGS "${DEFAULT_C_FLAGS} -fdiagnostics-color=always")
set(DEFAULT_CXX_FLAGS "${DEFAULT_CXX_FLAGS} -fdiagnostics-color=always")
endif()
if(MSVC)
set(SUPPORTS_CPP14 true)
else()
check_cxx_compiler_flag("-std=c++14" SUPPORTS_CPP14)
if(NOT SUPPORTS_CPP14)
set(SUPPORTS_CPP14 false)
endif()
endif()
check_cxx_compiler_flag("-march=native" SUPPORTS_MARCH_NATIVE)
if(SUPPORTS_MARCH_NATIVE AND NOT APPLE)
set(DEFAULT_C_FLAGS "${DEFAULT_C_FLAGS} -march=native")
set(DEFAULT_CXX_FLAGS "${DEFAULT_CXX_FLAGS} -march=native")
endif()
# configure whether the dreaded typemap-generator will run:
set(DEFAULT_TYPEMAP_GENERATION false)
if((NOT RELEASE) AND DOXYGEN_FOUND AND RUBY_FOUND)
set(DEFAULT_TYPEMAP_GENERATION true)
endif()
# check if we can can enable some hard-coded AMD64, X86 intrinsics. See option below.
execute_process(
COMMAND uname -m
OUTPUT_VARIABLE MACHINE_ARCH
ERROR_QUIET)
set(AMD64_LINUX false)
if (MACHINE_ARCH MATCHES "x86_64")
set(AMD64_LINUX true)
endif()
# test if mpirun/mpiexec supports the --oversubscribe flag:
if(MPI_FOUND)
execute_process(
COMMAND ${MPIEXEC} --oversubscribe ${MPIEXEC_NUMPROC_FLAG} 4 echo ok
RESULT_VARIABLE MPIEXEC_OVERSUBSCRIBE_RETURN_CODE
OUTPUT_QUIET
ERROR_QUIET)
if (MPIEXEC_OVERSUBSCRIBE_RETURN_CODE EQUAL 0)
set(MPIEXEC_OVERSUBSCRIBE_FLAG "--oversubscribe")
else()
set(MPIEXEC_OVERSUBSCRIBE_FLAG "")
endif()
endif()
#============= 3. CONFIGURABLE BUILD OPTIONS =========================
lgd_add_config_option(LGD_ADDITIONAL_C_COMPILE_FLAGS "Add these flags when compiling C code." "${DEFAULT_C_FLAGS}" false)
lgd_add_config_option(LGD_ADDITIONAL_CXX_COMPILE_FLAGS "Add these flags when compiling C++ code." "${DEFAULT_CXX_FLAGS}" false)
lgd_add_config_option(CMAKE_BUILD_TYPE "Sets the compile/link options, e.g. Debug, Release... Refer to the cmake documentation for more details." "Release" false)
lgd_add_config_option(CMAKE_CXX_COMPILER "Select the C++ compiler" ${CMAKE_CXX_COMPILER} false)
lgd_add_config_option(CMAKE_INSTALL_PREFIX "Path for installation" "/usr/local" false)
# setting DEBUG_LEVEL to " 0" is a hack to ensure it's included in the config header, as just "0" would evaluate to false (see util.cmake)
lgd_add_config_option(DEBUG_LEVEL "Configure the amount/verbosity of debug output" " 0" true)
lgd_add_config_option(LIB_LINKAGE_TYPE "Controls which type of library to build. Suggested: SHARED on Linux (creates a shared object \"libgeodecomp.so\"), STATIC should work for builds on Cray and Windows." "SHARED" false)
lgd_add_config_option(LIB_DIR "Library subdirectory (e.g. lib, lib32, lib64), useful for multilib builds" "lib" false)
lgd_add_config_option(LIMIT_TESTS "Limit the directories of tests to run. Only tests matching the specified pattern will be run." false false)
lgd_add_config_option(UNITEXEC "May be used to specify a wrapper which then calls a unit test executable. Handy if for instance the unit tests shall be run on a remote machine." "" false)
lgd_add_config_option(WITH_BOOST_ASIO "Some Boost distributions ship too old versions of ASIO which are not compatible with LibGeoDecomp. Use this flag to switch ASIO-related code off." false true)
lgd_add_config_option(WITH_BOOST_MOVE "Enable/disable Boost.Move for move semantics (e.g. to avoid copies of vectors)." ${Boost_MOVE_FOUND} true)
lgd_add_config_option(WITH_BOOST_MPI "Enable/disable Boost.MPI related code." ${Boost_MPI_FOUND} true)
lgd_add_config_option(WITH_BOOST_SERIALIZATION "Explicitly disable Boost.Serialization, which isn't available on some machines (e.g. woody.rrze.uni-erlangen.de). Don't do this if you need the HPX backend." ${Boost_SERIALIZATION_FOUND} true)
lgd_add_config_option(WITH_BOOST_SHARED_PTR "Lets LibGeoDecomp use boost::shared_ptr instead of std::shared_ptr. Useful if your C++ compiler doesn't support the latter." false true)
lgd_add_config_option(WITH_CUDA "Enable modules which harness NVIDIA CUDA GPUs" ${CUDA_FOUND} true)
lgd_add_config_option(WITH_FORTRAN "Build Fortran examples/utilities, too" false true)
lgd_add_config_option(WITH_HPX "Build those modules which require HPX" ${HPX_FOUND} true)
lgd_add_config_option(WITH_INTRINSICS "Switch on/off the code parts which require SSE or AVX intrinsics. Only used for tests and examples." ${AMD64_LINUX} true)
lgd_add_config_option(WITH_LAX_VISIT_TESTS "Remove some of the stricter assertions from VisIt related unit tests -- VisIt sometimes produces erroneous results when running on a remote machine (e.g. for autobuilds)" false true)
lgd_add_config_option(WITH_MPI "If set, all MPI related components will be built. This option is required for the MPI unit tests." ${MPI_FOUND} true)
lgd_add_config_option(WITH_OPENCL "Enable modules for delegating to OpenCL devices" false true)
lgd_add_config_option(WITH_OPENCV "Build those modules which require OpenCV" ${OpenCV_FOUND} false)
lgd_add_config_option(WITH_QT5 "Build example codes which rely on QT5 for the GUI" ${Qt5_FOUND} true)
lgd_add_config_option(WITH_SCOTCH "Enables LibGeoDecomp to use Scotch and PT-Scotch for domain decomposition." ${SCOTCH_FOUND} true)
lgd_add_config_option(WITH_SILO "Silo is a flexible output library developed by LLNL." ${Silo_FOUND} true)
lgd_add_config_option(WITH_THREADS "Lets you control whether we'll use threads (e.g. boost::thread)" ${OPENMP_FOUND} true)
lgd_add_config_option(WITH_TYPEMAPS "Controls whether the build system should regenerate typemaps.{h,cpp}. Requires Ruby and some Unix tools." ${DEFAULT_TYPEMAP_GENERATION} false)
lgd_add_config_option(WITH_VISIT "Activate code parts which use VisitWriter and SerialVisitWriter" ${VISIT_FOUND} true)
lgd_add_config_option(WITH_CPP14 "LibGeoDecomp is largely written in C++98, but some components use language features from a newer standard. This option will enable those." ${SUPPORTS_CPP14} true)
lgd_print_options()
lgd_dump_config("config.h")
#============= 4. RECURSE INTO SUBDIRECTORIES ========================
add_subdirectory(src)
#============= 5. EXPORT SETTINGS FOR NESTED USE =====================
if(lgd_has_parent)
# export this for users who bundle a checkout of LibGeoDecomp in their own CMake source tree
set(libgeodecomp_ALL_INCLUDE_DIRECTORIES ${LIBGEODECOMP_ALL_INCLUDE_DIRECTORIES} PARENT_SCOPE)
set(libgeodecomp_FLAGS ${LGD_AGGREGATED_CXX_FLAGS} PARENT_SCOPE)
endif()