forked from espressomd/espresso
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
510 lines (447 loc) · 16.3 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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
# Copyright (C) 2009-2019 The ESPResSo project
# Copyright (C) 2009,2010
# Max-Planck-Institute for Polymer Research, Theory Group
#
# This file is part of ESPResSo.
#
# ESPResSo is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# ESPResSo is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
cmake_minimum_required(VERSION 3.10)
message(STATUS "CMake version: ${CMAKE_VERSION}")
if(POLICY CMP0076)
# make target_sources() convert relative paths to absolute
cmake_policy(SET CMP0076 NEW)
endif()
if(POLICY CMP0025)
# make CXX_COMPILER_ID return "AppleClang" instead of "Clang" for Apple Clang
cmake_policy(SET CMP0025 NEW)
endif()
# CMake modules/macros are in a subdirectory to keep this file cleaner
set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
# C++ standard
enable_language(CXX)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
include(FeatureSummary)
include(GNUInstallDirs)
project(ESPResSo)
include(option_enum)
include(option_if_available)
if(POLICY CMP0074)
# make find_package() use <PackageName>_ROOT variables
cmake_policy(SET CMP0074 NEW)
endif()
set(PROJECT_VERSION "4.2-dev")
#
# CMake internal vars
#
# Select the build type
option_enum(
varname "CMAKE_BUILD_TYPE" help_text "build type" default_value "Release"
possible_values
"Debug;Release;RelWithDebInfo;MinSizeRel;Coverage;RelWithAssert")
set(CMAKE_CXX_FLAGS_COVERAGE "${CMAKE_CXX_FLAGS_COVERAGE} -Og -g")
set(CMAKE_CXX_FLAGS_RELWITHASSERT "${CMAKE_CXX_FLAGS_RELWITHASSERT} -O3 -g")
# On Mac OS X, first look for other packages, then frameworks
set(CMAKE_FIND_FRAMEWORK LAST)
# ##############################################################################
# User input options
# ##############################################################################
option(WITH_PYTHON "Build with Python bindings" ON)
option_if_available(WITH_GSL "Build with GSL support" ON)
option(WITH_CUDA "Build with GPU support" OFF)
option_if_available(WITH_HDF5 "Build with HDF5 support" ON)
option(WITH_TESTS "Enable tests" ON)
option_if_available(WITH_SCAFACOS "Build with ScaFaCoS support" OFF)
option_if_available(WITH_STOKESIAN_DYNAMICS "Build with Stokesian Dynamics" ON)
option(WITH_BENCHMARKS "Enable benchmarks" OFF)
option(WITH_VALGRIND_INSTRUMENTATION
"Build with valgrind instrumentation markers" OFF)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
option(WITH_CLANG_TIDY "Run Clang-Tidy during compilation" OFF)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL
"GNU")
option(WITH_COVERAGE "Generate code coverage report" OFF)
option(WITH_ASAN "Build with address sanitizer" OFF)
option(WITH_UBSAN "Build with undefined behavior sanitizer" OFF)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND NOT APPLE)
option(
WITH_MSAN
"Build with memory sanitizer (experimental; requires a memory-sanitized Python interpreter)"
OFF)
endif()
option(WARNINGS_ARE_ERRORS "Treat warnings as errors during compilation" OFF)
option(WITH_CCACHE "Use ccache compiler invocation." OFF)
option(WITH_PROFILER "Enable profiler annotations." OFF)
set(TEST_TIMEOUT "300" CACHE STRING
"Timeout in seconds for each testsuite test")
if(WITH_CCACHE)
find_program(CCACHE ccache)
if(CCACHE)
message(STATUS "Found ccache ${CCACHE}")
set(CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE} CACHE STRING "ccache executable")
else()
message(FATAL_ERROR "ccache not found.")
endif(CCACHE)
endif(WITH_CCACHE)
# Write compile commands to file, for various tools...
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# choose the name of the config file
set(MYCONFIG_NAME "myconfig.hpp" CACHE STRING
"Default name of the local config file")
# Check which config file to use
include(MyConfig)
#
# Pretty function
#
include(CheckCXXSourceCompiles)
set(__PRETTYFUNC__ __func__)
foreach(func_name __PRETTY_FUNCTION__ __FUNCTION__)
check_cxx_source_compiles(
"
#include <string>
int main() { std::string(${func_name}); }
" result${func_name})
if(result${func_name})
set(__PRETTYFUNC__ ${func_name})
break()
endif(result${func_name})
endforeach(func_name __PRETTY_FUNCTION__ __FUNCTION__)
#
# Libraries
#
# CUDA compiler
if(WITH_CUDA)
set(CMAKE_CUDA_STANDARD ${CMAKE_CXX_STANDARD})
set(MINIMAL_CUDA_VERSION 9.0)
option_enum(varname "WITH_CUDA_COMPILER" help_text "CUDA compiler"
default_value "nvcc" possible_values "nvcc;hip;clang")
if(WITH_CUDA_COMPILER STREQUAL "nvcc")
find_package(CUDA ${MINIMAL_CUDA_VERSION} REQUIRED)
find_package(CUDACompilerNVCC ${MINIMAL_CUDA_VERSION} REQUIRED)
elseif(WITH_CUDA_COMPILER STREQUAL "hip")
find_package(CUDACompilerHIP 1.5.18494 REQUIRED)
elseif(WITH_CUDA_COMPILER STREQUAL "clang")
if(WITH_COVERAGE)
message(
FATAL_ERROR
"Cannot enable code coverage with Clang as the CUDA compiler")
endif()
set(MINIMAL_CUDA_VERSION 8.0)
find_package(CUDACompilerClang 6.0 REQUIRED)
else()
message(FATAL_ERROR "Unknown CUDA compiler '${WITH_CUDA_COMPILER}'")
endif()
endif(WITH_CUDA)
find_package(PythonInterp 3.5 REQUIRED)
if(WITH_PYTHON)
find_package(Cython 0.26 REQUIRED)
find_package(PythonHeaders REQUIRED)
find_package(NumPy REQUIRED)
find_program(IPYTHON_EXECUTABLE NAMES jupyter ipython3 ipython)
endif(WITH_PYTHON)
find_package(FFTW3)
if(FFTW3_FOUND)
set(FFTW 3)
endif(FFTW3_FOUND)
# If we build Python bindings, turn on script interface
if(WITH_PYTHON)
set(WITH_SCRIPT_INTERFACE ON)
endif()
# We need the parallel hdf5 version!
if(WITH_HDF5)
# The FindHDF5 function will fall back to the serial version if no parallel
# version was found, and print to the CMake log that HDF5 was found. There is
# no QUIET argument to override that message. This can be confusing to people
# who are not familiar with the way hdf5 is distributed in Linux package
# repositories (libhdf5-dev is the serial version).
set(HDF5_PREFER_PARALLEL 1)
find_package(HDF5 "1.8" COMPONENTS C)
if(HDF5_FOUND)
if(HDF5_IS_PARALLEL)
set(H5MD 1)
add_feature_info(HDF5 ON "parallel")
else()
unset(H5MD)
set(HDF5_FOUND FALSE)
if(NOT WITH_HDF5_IS_DEFAULT_VALUE)
message(
FATAL_ERROR
"Optional dependency HDF5 explicitly requested, but parallel version not found."
)
endif()
endif(HDF5_IS_PARALLEL)
elseif(NOT WITH_HDF5_IS_DEFAULT_VALUE)
message(
FATAL_ERROR
"Optional dependency HDF5 explicitly requested, but not found.")
endif(HDF5_FOUND)
endif(WITH_HDF5)
# Check for the h5xx submodule and try to check it out if not found or update it
# if found.
if(WITH_HDF5 AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
# Try to find git
find_package(Git)
if(GIT_FOUND)
if(NOT EXISTS "${CMAKE_SOURCE_DIR}/libs/h5xx/.git")
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --
libs/h5xx WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
else()
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update -- libs/h5xx
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
endif()
endif()
endif()
if(WITH_SCAFACOS)
find_package(PkgConfig)
pkg_check_modules(SCAFACOS scafacos)
if(SCAFACOS_FOUND)
set(SCAFACOS 1)
elseif(NOT WITH_SCAFACOS_IS_DEFAULT_VALUE)
message(
FATAL_ERROR
"Optional dependency ScaFaCoS explicitly requested, but not found.")
endif(SCAFACOS_FOUND)
endif(WITH_SCAFACOS)
if(WITH_GSL)
find_package(GSL)
if(GSL_FOUND)
set(GSL 1)
elseif(NOT WITH_GSL_IS_DEFAULT_VALUE)
message(
FATAL_ERROR "Optional dependency GSL explicitly requested, but not found."
)
endif(GSL_FOUND)
endif(WITH_GSL)
find_package(BLAS)
if(BLAS_FOUND)
set(BLAS 1)
endif()
find_package(LAPACK)
if(LAPACK_FOUND)
set(LAPACK 1)
endif()
if(WITH_STOKESIAN_DYNAMICS)
if(BLAS AND LAPACK)
set(STOKESIAN_DYNAMICS 1)
endif()
if(NOT STOKESIAN_DYNAMICS AND NOT WITH_STOKESIAN_DYNAMICS_IS_DEFAULT_VALUE)
message(
FATAL_ERROR
"Optional feature Stokesian Dynamics explicitly requested, but dependencies not found."
)
endif()
endif(WITH_STOKESIAN_DYNAMICS)
if(WITH_STOKESIAN_DYNAMICS)
set(CMAKE_INSTALL_LIBDIR
"${CMAKE_INSTALL_PREFIX}/${PYTHON_INSTDIR}/espressomd")
cmake_minimum_required(VERSION 3.11)
include(FetchContent)
FetchContent_Declare(
stokesian_dynamics
GIT_REPOSITORY https://github.com/hmenke/espresso-stokesian-dynamics.git
GIT_TAG 860ceac208175)
FetchContent_GetProperties(stokesian_dynamics)
if(NOT stokesian_dynamics_POPULATED)
FetchContent_Populate(stokesian_dynamics)
add_subdirectory(${stokesian_dynamics_SOURCE_DIR}
${stokesian_dynamics_BINARY_DIR})
endif()
endif(WITH_STOKESIAN_DYNAMICS)
if(WITH_VALGRIND_INSTRUMENTATION)
find_package(PkgConfig)
pkg_check_modules(VALGRIND valgrind)
if(VALGRIND_FOUND)
set(VALGRIND_INSTRUMENTATION 1)
message(STATUS ${VALGRIND_INCLUDE_DIRS})
include_directories(SYSTEM ${VALGRIND_INCLUDE_DIRS})
endif(VALGRIND_FOUND)
endif(WITH_VALGRIND_INSTRUMENTATION)
#
# MPI
#
find_package(MPI 3.0 REQUIRED)
# CMake < 3.9
if(NOT TARGET MPI::MPI_CXX)
add_library(MPI::MPI_CXX IMPORTED INTERFACE)
# Workaround for https://gitlab.kitware.com/cmake/cmake/issues/18349
foreach(_MPI_FLAG ${MPI_CXX_COMPILE_FLAGS})
set_property(TARGET MPI::MPI_CXX PROPERTY INTERFACE_COMPILE_OPTIONS
${_MPI_FLAG})
endforeach()
set_property(TARGET MPI::MPI_CXX PROPERTY INTERFACE_INCLUDE_DIRECTORIES
"${MPI_CXX_INCLUDE_PATH}")
# Workaround for https://gitlab.kitware.com/cmake/cmake/issues/18349
foreach(_MPI_FLAG ${MPI_CXX_LINK_FLAGS})
set_property(TARGET MPI::MPI_CXX PROPERTY INTERFACE_LINK_LIBRARIES
${_MPI_FLAG})
endforeach()
set_property(TARGET MPI::MPI_CXX PROPERTY INTERFACE_LINK_LIBRARIES
${MPI_CXX_LIBRARIES})
endif()
# ##############################################################################
# Boost
# ##############################################################################
list(APPEND BOOST_COMPONENTS mpi serialization filesystem system)
if(WITH_TESTS)
list(APPEND BOOST_COMPONENTS unit_test_framework)
endif()
set(BOOST_MINIMUM_VERSION "1.65.0")
if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND CUDA_FOUND
AND CUDA_VERSION VERSION_GREATER_EQUAL "9.0")
set(BOOST_MINIMUM_VERSION "1.66.0")
endif()
# old Boost.MPI versions contain a use-after-free bug that seems to only cause
# crashes on 32-bit architectures
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(BOOST_MINIMUM_VERSION "1.67.0")
endif()
find_package(Boost ${BOOST_MINIMUM_VERSION} REQUIRED ${BOOST_COMPONENTS})
#
# Paths
#
set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${PYTHON_INSTDIR}/espressomd")
#
# Flags
#
# drop 'lib' prefix from all libraries
set(CMAKE_SHARED_LIBRARY_PREFIX "")
add_library(coverage_interface INTERFACE)
if(WITH_COVERAGE)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(
coverage_interface INTERFACE -g -fprofile-instr-generate
-fcoverage-mapping)
else()
target_compile_options(
coverage_interface INTERFACE -g --coverage -fprofile-arcs -ftest-coverage)
target_link_libraries(coverage_interface INTERFACE gcov)
endif()
endif()
add_library(cxx_interface INTERFACE)
target_compile_options(
cxx_interface
INTERFACE -Wall
-Wextra
$<$<BOOL:${WARNINGS_ARE_ERRORS}>:-Werror>
# add extra warnings
$<$<CXX_COMPILER_ID:Clang>:-Wextern-initializer>
# disable warnings from -Wextra
-Wno-sign-compare
-Wno-unused-function
-Wno-unused-variable
-Wno-unused-parameter
-Wno-missing-braces
$<$<CXX_COMPILER_ID:GNU>:-Wno-clobbered>
$<$<CXX_COMPILER_ID:Intel>:-wd592>)
# disable more warnings from -Wextra
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_SYSTEM_PROCESSOR MATCHES
"arm")
target_compile_options(cxx_interface INTERFACE -Wno-psabi)
endif()
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "Intel"
AND NOT (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION
VERSION_LESS "7.0.0"))
target_compile_options(cxx_interface INTERFACE -Wno-implicit-fallthrough)
endif()
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT CMAKE_CXX_COMPILER_ID
STREQUAL "Intel")
target_compile_options(cxx_interface INTERFACE -Wno-unused-private-field)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
target_compile_options(cxx_interface
INTERFACE -Wno-gnu-zero-variadic-macro-arguments)
endif()
if(NOT CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_VERSION
VERSION_GREATER "4.8.5")
# older GCC versions don't support -Wno-pedantic which we need in src/python
target_compile_options(cxx_interface INTERFACE -pedantic)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION
VERSION_GREATER_EQUAL "8.1.0")
target_compile_options(cxx_interface INTERFACE -Wno-cast-function-type)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "Intel" AND CMAKE_CXX_COMPILER_VERSION
VERSION_LESS "16.0")
# workaround for compiler crash related to decltype() and variadic template
# usage inside Boost
target_compile_options(cxx_interface
INTERFACE -DBOOST_NO_CXX11_VARIADIC_TEMPLATES)
endif()
# prevent 80-bit arithmetic on old Intel processors
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_SIZEOF_VOID_P EQUAL 4
AND CMAKE_SYSTEM_PROCESSOR MATCHES "[xX]86")
target_compile_options(cxx_interface INTERFACE -ffloat-store)
endif()
set(CMAKE_MACOSX_RPATH TRUE)
if(WITH_ASAN AND WITH_MSAN)
message(
FATAL_ERROR
"Address sanitizer and memory sanitizer cannot be enabled simultaneously")
endif()
if(WITH_ASAN)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g -O1")
target_compile_options(cxx_interface INTERFACE -fsanitize=address
-fno-omit-frame-pointer)
target_link_libraries(cxx_interface INTERFACE -fsanitize=address)
endif()
if(WITH_MSAN)
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -g -O1")
target_compile_options(cxx_interface INTERFACE -fsanitize=memory
-fno-omit-frame-pointer)
target_link_libraries(cxx_interface INTERFACE -fsanitize=memory)
endif()
if(WITH_UBSAN)
target_compile_options(cxx_interface INTERFACE -fsanitize=undefined)
target_link_libraries(cxx_interface INTERFACE -fsanitize=undefined)
endif()
target_link_libraries(cxx_interface INTERFACE coverage_interface)
#
# Testing
# ##############################################################################
if(WITH_CLANG_TIDY)
find_package(ClangTidy "${CMAKE_CXX_COMPILER_VERSION}" EXACT REQUIRED)
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXE};--extra-arg=--cuda-host-only")
endif()
if(WITH_TESTS)
enable_testing()
if(Boost_UNIT_TEST_FRAMEWORK_FOUND)
set(WITH_UNIT_TESTS ON)
endif(Boost_UNIT_TEST_FRAMEWORK_FOUND)
add_custom_target(check)
if(WITH_PYTHON)
add_subdirectory(testsuite)
endif(WITH_PYTHON)
set(CTEST_ARGS ""
CACHE STRING
"Extra arguments to give to ctest calls (separated by semicolons)")
endif(WITH_TESTS)
if(WITH_BENCHMARKS)
add_custom_target(benchmark)
add_subdirectory(maintainer/benchmarks)
endif(WITH_BENCHMARKS)
#
# Subdirectories
#
add_subdirectory(doc)
add_subdirectory(src)
add_subdirectory(libs)
#
# Feature summary
#
include(FeatureSummary)
feature_summary(WHAT ALL)