forked from feltor-dev/feltor
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
271 lines (227 loc) · 9.81 KB
/
Copy pathCMakeLists.txt
File metadata and controls
271 lines (227 loc) · 9.81 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
cmake_minimum_required(VERSION 3.26)
# ============================================
# User Options
# Set these using -DFELTOR_WITH_MPI=ON, etc.
# By default, compiles single threaded on a CUDA.
option(FELTOR_WITH_MPI "Configure all executables that allow MPI parallelization with MPI. Do not configure executables that do not allow MPI." OFF)
# option(FELTOR_INSTALL "Create install rules" ${PROJECT_IS_TOP_LEVEL})
# Currently our install rules do not quite work (see related issue on github page)
set( FELTOR_INSTALL OFF)
option(FELTOR_FILE_WITH_JSONCPP "Use jsoncpp instead of nlohmann/json." OFF)
option(FELTOR_FILE_WITH_NETCDF "Configure dg_file_netcdf and dg_file_file targets. Depends on NetCDF." ON)
option(FELTOR_DG_WITH_MATRIX "Configure dg_matrix target. Depends on Boost and Lapack." ON)
include(CMakeDependentOption)
cmake_dependent_option(
FELTOR_WITH_GLFW
"Configure executables, which allow it, with plotting support. Ignored if MPI is used."
ON
"NOT FELTOR_WITH_MPI"
OFF
)
cmake_dependent_option(
FELTOR_WITH_NCCL
"Use the nccl library for GPU-GPU MPI communication."
OFF # default value if cuda is true
"FELTOR_WITH_MPI AND (CCCL_THRUST_DEVICE_SYSTEM STREQUAL \"CUDA\" OR CCCL_THRUST_DEVICE_SYSTEM STREQUAL \"\")"
OFF # default value if cuda is false
)
cmake_dependent_option(
FELTOR_CUDA_UNAWARE_MPI
"Assume the mpi library is cuda-unaware. In that case all GPU-GPU communication is forced through the host. This variable should only be set to true if the MPI library is not Open-MPI and the MPI library is not cuda aware and FELTOR_WITH_NCCL is false. Ignored if FELTOR_WITH_NCCL is true."
OFF # default value if cuda is true
"FELTOR_WITH_MPI AND (CCCL_THRUST_DEVICE_SYSTEM STREQUAL \"CUDA\" OR CCCL_THRUST_DEVICE_SYSTEM STREQUAL \"\")"
OFF # default value if cuda is false
)
if( FELTOR_WITH_MPI AND (CCCL_THRUST_DEVICE_SYSTEM STREQUAL "CUDA" OR CCCL_THRUST_DEVICE_SYSTEM STREQUAL ""))
message( "Feltor dependent variables")
message( " FELTOR_WITH_NCCL = " ${FELTOR_WITH_NCCL})
message( " FELTOR_CUDA_UNAWARE_MPI = " ${FELTOR_CUDA_UNAWARE_MPI})
endif()
if( NOT FELTOR_WITH_MPI)
message( "Feltor dependent variables")
message( " FELTOR_WITH_GLFW = " ${FELTOR_WITH_GLFW})
endif()
# If using vcpkg to install dependencies
# this is a bit of a hack until a better solution
# reveals itself,
# because the options need to be defined here
# because vcpkg needs to called before project
# Or use e.g. vcpkg install --x-feature=netcdf
if(FELTOR_FILE_WITH_NETCDF)
# Installing netcdf from scratch on windows takes about 20 min
list(APPEND VCPKG_MANIFEST_FEATURES "netcdf")
endif()
if(FELTOR_DG_WITH_MATRIX)
# Installing lapack from scratch on windows takes about 1.5 hours
list( APPEND VCPKG_MANIFEST_FEATURES "matrix")
endif()
if(FELTOR_WITH_GLFW)
# Installing glfw from scratch on windows takes about a minute
list( APPEND VCPKG_MANIFEST_FEATURES "glfw")
endif()
# Project name and version
project(
feltor
VERSION 8.3 # Update every time a release (tag) is made
DESCRIPTION "Numerical methods for fluid simulations of magnetized plasmas"
HOMEPAGE_URL "https://feltor-dev.github.io"
LANGUAGES CXX
)
option(FELTOR_BUILD_PROJECTS "Configure feltor project target feltor_projects." ${PROJECT_IS_TOP_LEVEL})
option(FELTOR_BUILD_TESTS "Configure test target dg_tests." ${PROJECT_IS_TOP_LEVEL})
option(FELTOR_BUILD_BENCHMARKS "Configure benchmark target dg_benchmarks." ${PROJECT_IS_TOP_LEVEL})
# Enable support for IDEs like Visual Studio
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
# Add cmake modules (e.g. FindThrust.cmake)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
# ============================================
# Make cpm package manager visible here and in subdirectories
include(CPM)
# Make installation dirs available here and in subdirectories
include(GNUInstallDirs)
# ============================================
# Set up testing dependencies
if(FELTOR_BUILD_TESTS)
enable_testing()
CPMAddPackage(
NAME Catch2
GITHUB_REPOSITORY catchorg/Catch2
VERSION 3.8.0
SYSTEM ON
EXCLUDE_FROM_ALL ON
)
# Make include(Catch2) available according to
# https://github.com/catchorg/Catch2/blob/devel/docs/cmake-integration.md
list(APPEND CMAKE_MODULE_PATH ${Catch2_SOURCE_DIR}/extras)
endif()
if(FELTOR_WITH_MPI)
find_package(MPI REQUIRED)
# target_link_libraries(dg INTERFACE MPI::MPI_CXX)
endif()
# =============================================
# On naming targets:
#https://stackoverflow.com/questions/67757157/change-exported-target-name-in-cmake-install-alias-to-a-target
# ============================================
# MW: CMake switches on -forward-unknown-to-host-compiler by default, so C++ flags
# may be set even when compiling for CUDA.
# We set warnings globally for this folder and below
# https://cmake.org/cmake/help/latest/command/add_compile_options.html
# Also note that "add_compile_options" only applies to targets defined after
# Set up compiler-specific flags
if (MSVC)
# warning level 4
add_compile_options(/W4 /permissive-)
else()
# additional warnings
if(CCCL_THRUST_DEVICE_SYSTEM STREQUAL "CUDA" OR CCCL_THRUST_DEVICE_SYSTEM STREQUAL "")
# For CUDA pedantic spits out too many warnings
add_compile_options(-Wall -Wextra)
elseif(CCCL_THRUST_DEVICE_SYSTEM STREQUAL "OMP")
# Clang has warnings about not vectorizing loops
add_compile_options(-Wall -Wextra -Wpedantic)
else()
add_compile_options(-Wall -Wextra -Wpedantic -Werror)
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
add_compile_options( -Wno-c++20-extensions) # Necessary for Catch2 TEMPLATE_TEST_CASE
endif()
endif()
# =============================================
# Set up DG header-only library
# Defines the targets:
# - dg library, alias dg::dg
# - dg file library, alias dg::file
# - dg_benchmarks
# - dg_tests
# This is a somewhat chicken-egg problem: The cuda language can only be enabled
# once in the project. But before including the cccl package the device macro
# is not defined. So we must assume the user defines CCCL_THRUST_DEVICE_SYSTEM
# and/or if they do not, then the default is also CUDA
if(CCCL_THRUST_DEVICE_SYSTEM STREQUAL "CUDA" OR CCCL_THRUST_DEVICE_SYSTEM STREQUAL "")
#MW: For some reason enable_language should not be called in subprojects
#https://gitlab.kitware.com/cmake/cmake/-/issues/26751
if(${PROJECT_IS_TOP_LEVEL})
enable_language(CUDA)
endif()
get_property(languages GLOBAL PROPERTY ENABLED_LANGUAGES)
if( NOT "CUDA" IN_LIST languages)
message( FATAL_ERROR "You have to use enable_language(CUDA) before fetching the feltor package with CCCL_THRUST_DEVICE_SYSTEM = CUDA.")
endif()
find_package(CUDAToolkit REQUIRED)
endif()
add_subdirectory("${PROJECT_SOURCE_DIR}/inc/dg")
# ============================================
# Add FELTOR executables
if(FELTOR_BUILD_PROJECTS)
include(feltor-add-executable)
if(FELTOR_WITH_GLFW)
if(FELTOR_WITH_MPI)
message(WARNING "GLFW is not compatible with MPI when building FELTOR and will be ignored")
else()
# Draw Links to GLFW and OpenGL
# Must be installed separately, e.g. `sudo apt install libglfw3-dev`
CPMAddPackage(
NAME draw
GIT_REPOSITORY https://github.com/feltor-dev/draw.git
GIT_TAG master
SYSTEM ON
EXCLUDE_FROM_ALL ON
)
if( draw_ADDED)
message( STATUS "Found Draw library in ${draw_SOURCE_DIR}")
endif()
endif()
endif()
add_custom_target( feltor_projects)
# =========================================
# Include all individual src projects
add_subdirectory("${PROJECT_SOURCE_DIR}/src/esol")
add_subdirectory("${PROJECT_SOURCE_DIR}/src/feltor")
add_subdirectory("${PROJECT_SOURCE_DIR}/src/feltorSesol")
add_subdirectory("${PROJECT_SOURCE_DIR}/src/feltorSH")
add_subdirectory("${PROJECT_SOURCE_DIR}/src/feltorSHp")
add_subdirectory("${PROJECT_SOURCE_DIR}/src/feltorShw")
add_subdirectory("${PROJECT_SOURCE_DIR}/src/geometry_diag")
add_subdirectory("${PROJECT_SOURCE_DIR}/src/hasegawa")
add_subdirectory("${PROJECT_SOURCE_DIR}/src/heat")
add_subdirectory("${PROJECT_SOURCE_DIR}/src/lamb_dipole")
add_subdirectory("${PROJECT_SOURCE_DIR}/src/navier_stokes")
add_subdirectory("${PROJECT_SOURCE_DIR}/src/ping")
add_subdirectory("${PROJECT_SOURCE_DIR}/src/poet")
add_subdirectory("${PROJECT_SOURCE_DIR}/src/reco2D")
add_subdirectory("${PROJECT_SOURCE_DIR}/src/toefl")
add_subdirectory("${PROJECT_SOURCE_DIR}/src/thermal")
endif()
# ============================================
# INSTALL
# PROVIDING A PACKAGE CONFIG FILE
# A config file is the preferred way for an installed project to make itself
# available for other CMake projects via find_package
# First, we generate the config files via the helper utilities in the current build directory
include(CMakePackageConfigHelpers)
configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/feltor-config.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/feltor-config.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/feltor"
PATH_VARS PROJECT_NAME PROJECT_VERSION
)
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/feltor-version.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion
)
if(FELTOR_INSTALL)
# Second, we need an install rule that copies the above two generated files
# to the cmake install libdir
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/feltor-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/feltor-version.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/feltor"
COMPONENT feltor_dg
)
# ============================================
# PACKAGING
# Simply include CPack will generate CPack...cmake files
include(CPack)
endif()