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
|
# Set C++17 for the whole build if not otherwise requested
#
# This is the easiest way to push up a C++17 requirement for AMReX, PICSAR and
# openPMD-api until they increase their requirement.
#
macro(set_cxx17_superbuild)
if(NOT DEFINED CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 17)
endif()
if(NOT DEFINED CMAKE_CXX_EXTENSIONS)
set(CMAKE_CXX_EXTENSIONS OFF)
endif()
if(NOT DEFINED CMAKE_CXX_STANDARD_REQUIRED)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
endif()
if(NOT DEFINED CMAKE_CUDA_STANDARD)
set(CMAKE_CUDA_STANDARD 17)
endif()
if(NOT DEFINED CMAKE_CUDA_EXTENSIONS)
set(CMAKE_CUDA_EXTENSIONS OFF)
endif()
if(NOT DEFINED CMAKE_CUDA_STANDARD_REQUIRED)
set(CMAKE_CUDA_STANDARD_REQUIRED ON)
endif()
endmacro()
# find the CCache tool and use it if found
#
macro(set_ccache)
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
if(WarpX_COMPUTE STREQUAL CUDA)
set(CMAKE_CUDA_COMPILER_LAUNCHER "${CCACHE_PROGRAM}")
endif()
message(STATUS "Found CCache: ${CCACHE_PROGRAM}")
else()
message(STATUS "Could NOT find CCache")
endif()
mark_as_advanced(CCACHE_PROGRAM)
endmacro()
# set names and paths of temporary build directories
# the defaults in CMake are sub-ideal for historic reasons, lets make them more
# Unix-ish and portable.
#
macro(set_default_build_dirs)
if(NOT CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
CACHE PATH "Build directory for archives")
mark_as_advanced(CMAKE_ARCHIVE_OUTPUT_DIRECTORY)
endif()
if(NOT CMAKE_LIBRARY_OUTPUT_DIRECTORY)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"
CACHE PATH "Build directory for libraries")
mark_as_advanced(CMAKE_LIBRARY_OUTPUT_DIRECTORY)
endif()
if(NOT CMAKE_RUNTIME_OUTPUT_DIRECTORY)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin"
CACHE PATH "Build directory for binaries")
mark_as_advanced(CMAKE_RUNTIME_OUTPUT_DIRECTORY)
endif()
endmacro()
# set names and paths of install directories
# the defaults in CMake are sub-ideal for historic reasons, lets make them more
# Unix-ish and portable.
#
macro(set_default_install_dirs)
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
include(GNUInstallDirs)
if(NOT CMAKE_INSTALL_CMAKEDIR)
set(CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/WarpX"
CACHE PATH "CMake config package location for installed targets")
if(WIN32)
set(CMAKE_INSTALL_LIBDIR Lib
CACHE PATH "Object code libraries")
set_property(CACHE CMAKE_INSTALL_CMAKEDIR PROPERTY VALUE "cmake")
endif()
mark_as_advanced(CMAKE_INSTALL_CMAKEDIR)
endif()
endif()
endmacro()
# change the default CMAKE_BUILD_TYPE
# the default in CMake is Debug for historic reasons
#
macro(set_default_build_type default_build_type)
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
set(CMAKE_CONFIGURATION_TYPES "Release;Debug;MinSizeRel;RelWithDebInfo")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE ${default_build_type}
CACHE STRING
"Choose the build type, e.g. Release, Debug, or RelWithDebInfo." FORCE)
set_property(CACHE CMAKE_BUILD_TYPE
PROPERTY STRINGS ${CMAKE_CONFIGURATION_TYPES})
endif()
if(NOT CMAKE_BUILD_TYPE IN_LIST CMAKE_CONFIGURATION_TYPES)
message(WARNING "CMAKE_BUILD_TYPE '${CMAKE_BUILD_TYPE}' is not one of "
"${CMAKE_CONFIGURATION_TYPES}. Is this a typo?")
endif()
endif()
endmacro()
# Set CXX
# Note: this is a bit legacy and one should use CMake TOOLCHAINS instead.
#
macro(set_cxx_warnings)
# On Windows, Clang -Wall aliases -Weverything; default is /W3
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND NOT WIN32)
# list(APPEND CMAKE_CXX_FLAGS "-fsanitize=address") # address, memory, undefined
# set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fsanitize=address")
# set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -fsanitize=address")
# set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -fsanitize=address")
# note: might still need a
# export LD_PRELOAD=libclang_rt.asan.so
# or on Debian 9 with Clang 6.0
# export LD_PRELOAD=/usr/lib/llvm-6.0/lib/clang/6.0.0/lib/linux/libclang_rt.asan-x86_64.so:
# /usr/lib/llvm-6.0/lib/clang/6.0.0/lib/linux/libclang_rt.ubsan_minimal-x86_64.so
# at runtime when used with symbol-hidden code (e.g. pybind11 module)
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Weverything")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wshadow -Woverloaded-virtual -Wextra-semi -Wunreachable-code")
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wshadow -Woverloaded-virtual -Wunreachable-code")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
# Warning C4503: "decorated name length exceeded, name was truncated"
# Symbols longer than 4096 chars are truncated (and hashed instead)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -wd4503")
# Yes, you should build against the same C++ runtime and with same
# configuration (Debug/Release). MSVC does inconvenient choices for their
# developers, so be it. (Our Windows-users use conda-forge builds, which
# are consistent.)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -wd4251")
endif ()
endmacro()
# Enables interprocedural optimization for a list of targets
#
function(enable_IPO all_targets_list)
include(CheckIPOSupported)
check_ipo_supported(RESULT is_IPO_available)
if(is_IPO_available)
foreach(tgt IN ITEMS ${all_targets_list})
set_target_properties(${tgt} PROPERTIES INTERPROCEDURAL_OPTIMIZATION TRUE)
endforeach()
else()
message(FATAL_ERROR "Interprocedural optimization is not available, set WarpX_IPO=OFF")
endif()
endfunction()
# Take an <imported_target> and expose it as INTERFACE target with
# WarpX::thirdparty::<propagated_name> naming and SYSTEM includes.
#
function(make_third_party_includes_system imported_target propagated_name)
add_library(WarpX::thirdparty::${propagated_name} INTERFACE IMPORTED)
target_link_libraries(WarpX::thirdparty::${propagated_name} INTERFACE ${imported_target})
if(TARGET ${imported_target})
get_target_property(imported_target_type ${imported_target} TYPE)
if(NOT imported_target_type STREQUAL INTERFACE_LIBRARY)
get_target_property(ALL_INCLUDES ${imported_target} INCLUDE_DIRECTORIES)
if(ALL_INCLUDES)
set_target_properties(WarpX::thirdparty::${propagated_name} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "")
target_include_directories(WarpX::thirdparty::${propagated_name} SYSTEM INTERFACE ${ALL_INCLUDES})
endif()
endif()
endif()
endfunction()
# Set a feature-based binary name for the WarpX executable and create a generic
# warpx symlink to it. Only sets options relevant for users (see summary).
#
function(set_warpx_binary_name)
set(warpx_bin_names)
if(WarpX_APP)
list(APPEND warpx_bin_names app)
endif()
if(WarpX_LIB)
list(APPEND warpx_bin_names shared)
endif()
foreach(tgt IN LISTS _ALL_TARGETS)
set_target_properties(${tgt} PROPERTIES OUTPUT_NAME "warpx")
if(WarpX_DIMS STREQUAL RZ)
set_property(TARGET ${tgt} APPEND_STRING PROPERTY OUTPUT_NAME ".RZ")
else()
set_property(TARGET ${tgt} APPEND_STRING PROPERTY OUTPUT_NAME ".${WarpX_DIMS}d")
endif()
if(WarpX_MPI)
set_property(TARGET ${tgt} APPEND_STRING PROPERTY OUTPUT_NAME ".MPI")
else()
set_property(TARGET ${tgt} APPEND_STRING PROPERTY OUTPUT_NAME ".NOMPI")
endif()
set_property(TARGET ${tgt} APPEND_STRING PROPERTY OUTPUT_NAME ".${WarpX_COMPUTE}")
if(WarpX_PRECISION STREQUAL "DOUBLE")
set_property(TARGET ${tgt} APPEND_STRING PROPERTY OUTPUT_NAME ".DP")
else()
set_property(TARGET ${tgt} APPEND_STRING PROPERTY OUTPUT_NAME ".SP")
endif()
if(WarpX_ASCENT)
set_property(TARGET ${tgt} APPEND_STRING PROPERTY OUTPUT_NAME ".ASCENT")
endif()
if(WarpX_OPENPMD)
set_property(TARGET ${tgt} APPEND_STRING PROPERTY OUTPUT_NAME ".OPMD")
endif()
if(WarpX_PSATD)
set_property(TARGET ${tgt} APPEND_STRING PROPERTY OUTPUT_NAME ".PSATD")
endif()
if(WarpX_EB)
set_property(TARGET ${tgt} APPEND_STRING PROPERTY OUTPUT_NAME ".EB")
endif()
if(WarpX_QED)
set_property(TARGET ${tgt} APPEND_STRING PROPERTY OUTPUT_NAME ".QED")
endif()
if(WarpX_QED_TABLE_GEN)
set_property(TARGET ${tgt} APPEND_STRING PROPERTY OUTPUT_NAME ".GENQEDTABLES")
endif()
if(WarpX_SENSEI)
set_property(TARGET ${tgt} APPEND_STRING PROPERTY OUTPUT_NAME ".SENSEI")
endif()
if(CMAKE_BUILD_TYPE MATCHES "Debug")
set_property(TARGET ${tgt} APPEND_STRING PROPERTY OUTPUT_NAME ".DEBUG")
endif()
endforeach()
if(WarpX_APP)
# alias to the latest build, because using the full name is often confusing
add_custom_command(TARGET app POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink
$<TARGET_FILE_NAME:app>
${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/warpx
)
endif()
if(WarpX_LIB)
# alias to the latest build; this is the one expected by Python bindings
if(WarpX_DIMS STREQUAL RZ)
set(lib_suffix "rz")
else()
set(lib_suffix "${WarpX_DIMS}d")
endif()
if(WIN32)
set(mod_ext "dll")
else()
set(mod_ext "so")
endif()
add_custom_command(TARGET shared POST_BUILD
COMMAND ${CMAKE_COMMAND} -E create_symlink
$<TARGET_FILE_NAME:shared>
$<TARGET_FILE_DIR:shared>/libwarpx.${lib_suffix}.${mod_ext}
)
endif()
endfunction()
# Set an MPI_TEST_EXE variable for test runs which runs num_ranks
# ranks. On some systems, you might need to use the a specific
# mpiexec wrapper, e.g. on Summit (ORNL) pass the hint
# -DMPIEXEC_EXECUTABLE=$(which jsrun) to run ctest.
#
function(configure_mpiexec num_ranks)
# OpenMPI root guard: https://github.com/open-mpi/ompi/issues/4451
if("$ENV{USER}" STREQUAL "root")
# calling even --help as root will abort and warn on stderr
execute_process(COMMAND ${MPIEXEC_EXECUTABLE} --help
ERROR_VARIABLE MPIEXEC_HELP_TEXT
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(${MPIEXEC_HELP_TEXT} MATCHES "^.*allow-run-as-root.*$")
set(MPI_ALLOW_ROOT --allow-run-as-root)
endif()
endif()
set(MPI_TEST_EXE
${MPIEXEC_EXECUTABLE}
${MPI_ALLOW_ROOT}
${MPIEXEC_NUMPROC_FLAG} ${num_ranks}
PARENT_SCOPE
)
endfunction()
# FUNCTION: get_source_version
#
# Retrieves source version info and sets internal cache variables
# ${NAME}_GIT_VERSION and ${NAME}_PKG_VERSION
#
function(get_source_version NAME SOURCE_DIR)
find_package(Git QUIET)
set(_tmp "")
# Try to inquire software version from git
if(EXISTS ${SOURCE_DIR}/.git AND ${GIT_FOUND})
execute_process(COMMAND git describe --abbrev=12 --dirty --always --tags
WORKING_DIRECTORY ${SOURCE_DIR}
OUTPUT_VARIABLE _tmp)
string( STRIP "${_tmp}" _tmp)
endif()
# Is there a CMake project version?
# For deployed releases that build from tarballs, this is what we want to pick
if(NOT _tmp AND ${NAME}_VERSION)
set(_tmp "${${NAME}_VERSION}-nogit")
endif()
set(${NAME}_GIT_VERSION "${_tmp}" CACHE INTERNAL "")
unset(_tmp)
endfunction ()
# Prints a summary of WarpX options at the end of the CMake configuration
#
function(warpx_print_summary)
message("")
message("WarpX build configuration:")
message(" Version: ${WarpX_VERSION} (${WarpX_GIT_VERSION})")
message(" C++ Compiler: ${CMAKE_CXX_COMPILER_ID} "
"${CMAKE_CXX_COMPILER_VERSION} "
"${CMAKE_CXX_COMPILER_WRAPPER}")
message(" ${CMAKE_CXX_COMPILER}")
message("")
message(" Installation prefix: ${CMAKE_INSTALL_PREFIX}")
message(" bin: ${CMAKE_INSTALL_BINDIR}")
message(" lib: ${CMAKE_INSTALL_LIBDIR}")
message(" include: ${CMAKE_INSTALL_INCLUDEDIR}")
message(" cmake: ${CMAKE_INSTALL_CMAKEDIR}")
if(WarpX_HAVE_PYTHON)
message(" python: ${CMAKE_INSTALL_PYTHONDIR}")
endif()
message("")
set(BLD_TYPE_UNKNOWN "")
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR AND
NOT CMAKE_BUILD_TYPE IN_LIST CMAKE_CONFIGURATION_TYPES)
set(BLD_TYPE_UNKNOWN " (unknown type, check warning)")
endif()
message(" Build type: ${CMAKE_BUILD_TYPE}${BLD_TYPE_UNKNOWN}")
set(LIB_TYPE "")
if(WarpX_LIB)
if(BUILD_SHARED_LIBS)
set(LIB_TYPE " (shared)")
else()
set(LIB_TYPE " (static)")
endif()
endif()
#message(" Testing: ${BUILD_TESTING}")
message(" Build options:")
message(" APP: ${WarpX_APP}")
message(" ASCENT: ${WarpX_ASCENT}")
message(" COMPUTE: ${WarpX_COMPUTE}")
message(" DIMS: ${WarpX_DIMS}")
message(" Embedded Boundary: ${WarpX_EB}")
message(" GPU clock timers: ${WarpX_GPUCLOCK}")
message(" IPO/LTO: ${WarpX_IPO}")
message(" LIB: ${WarpX_LIB}${LIB_TYPE}")
message(" MPI: ${WarpX_MPI}")
if(MPI)
message(" MPI (thread multiple): ${WarpX_MPI_THREAD_MULTIPLE}")
endif()
message(" PSATD: ${WarpX_PSATD}")
message(" PRECISION: ${WarpX_PRECISION}")
message(" OPENPMD: ${WarpX_OPENPMD}")
message(" QED: ${WarpX_QED}")
message(" QED table generation: ${WarpX_QED_TABLE_GEN}")
message(" SENSEI: ${WarpX_SENSEI}")
message("")
endfunction()
|