forked from iPIC3D/iPIC3D-CPU
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
executable file
·256 lines (217 loc) · 6.6 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
cmake_minimum_required(VERSION 3.10)
project(iPic3D)
set(CMAKE_CXX_STANDARD 17)
cmake_policy(SET CMP0042 NEW)
set(CMAKE_BUILD_RPATH_USE_ORIGIN TRUE)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
macro(DP var)
message(NOTICE "${var} = '${${var}}'")
endmacro()
# First, do the site configuration
# This function globs for the existing configurations.
function(get_sites OUTVAR)
file(GLOB site_incs RELATIVE "${CMAKE_SOURCE_DIR}/cmake/sites" "${CMAKE_SOURCE_DIR}/cmake/sites/*.cmake")
set(sites "")
foreach(inc "${site_incs}")
string(REPLACE ".cmake" "" site "${inc}")
list(APPEND sites "${site}")
endforeach()
list(FIND sites "default" def_ind)
list(REMOVE_ITEM sites "default")
list(PREPEND sites "default")
set(${OUTVAR} "${sites}" PARENT_SCOPE)
endfunction()
get_sites(KNOWN_SITES)
# Set up cache var for which we are using
set(SITE "default" CACHE STRING "A predefined site configuration to use")
# Set the options for the UI
set_property(CACHE SITE PROPERTY STRINGS "${KNOWN_SITES}")
# Include it
include("${CMAKE_SOURCE_DIR}/cmake/sites/${SITE}.cmake")
# Use CMake default variable for this so add_library will
# automatically do the right thing.
option(BUILD_SHARED_LIBS "Use shared libraries if ON, static if OFF" ON)
option(USE_CATALYST "Use Catalyst adaptor" OFF)
option(USE_BATSRUS "Use BATSRUS flag" OFF)
option(USE_HDF5 "Use HDF5 library" OFF)
option(BENCH_MARK "Print tasks time" OFF)
option(USE_OPENMP "Use OpenMP in support loops" OFF) # must delete all cmake cache if you change this option
include(GNUInstallDirs)
# Find ParaView
if(USE_CATALYST)
find_package(ParaView 5.7 REQUIRED)
if (NOT TARGET ParaView::PythonCatalyst)
message(STATUS
"${CMAKE_PROJECT_NAME} requires ParaView to be built with Catalyst and "
"Python support enabled. Please rebuild ParaView (or point to a "
"different build of ParaView) with PARAVIEW_ENABLE_CATALYST and "
"PARAVIEW_ENABLE_PYTHON set to TRUE")
else()
add_library(iPICAdaptor ${CMAKE_SOURCE_DIR}/catalyst/Adaptor.cxx)
if (BUILD_SHARED_LIBS)
install(TARGETS iPICAdaptor)
endif()
target_link_libraries(iPICAdaptor PRIVATE stdc++fs ParaView::PythonCatalyst VTK::CommonDataModel Python3::Python)
# target_link_libraries(iPICAdaptor PRIVATE ParaView::PythonCatalyst VTK::CommonDataModel Python3::Python)
target_include_directories(iPICAdaptor INTERFACE ${CMAKE_SOURCE_DIR}/catalyst)
target_compile_definitions(iPICAdaptor INTERFACE USE_CATALYST)
endif()
endif()
# Find HDF5
if (USE_HDF5)
if(BUILD_SHARED_LIBS)
set(HDF5_USE_STATIC_LIBRARIES OFF)
else()
set(HDF5_USE_STATIC_LIBRARIES ON)
endif()
find_package(HDF5 COMPONENTS C HL REQUIRED)
if (NOT DEFINED HDF5_C_TARGET)
message(STATUS "Creating a proper target for HDF5")
#add_library(hdf5::hdf5 INTERFACE IMPORTED)
set_target_properties(hdf5::hdf5 PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "${HDF5_C_DEFINITIONS}"
INTERFACE_INCLUDE_DIRECTORIES "${HDF5_C_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "${HDF5_C_LIBRARIES}"
)
set(HDF5_C_TARGET hdf5::hdf5)
endif()
if (NOT DEFINED HDF5_C_HL_TARGET)
message(STATUS "Creating a proper target for HDF5 HL")
#add_library(hdf5::hdf5_hl INTERFACE IMPORTED)
set_target_properties(hdf5::hdf5_hl PROPERTIES
INTERFACE_LINK_LIBRARIES "hdf5::hdf5;${HDF5_C_HL_LIBRARIES}"
)
set(HDF5_C_HL_TARGET hdf5::hdf5_hl)
endif()
endif()
# Find MPI and OpenMP
find_package(MPI REQUIRED COMPONENTS CXX)
if(USE_OPENMP)
find_package(OpenMP REQUIRED COMPONENTS CXX)
endif()
#
# Source file list
#
file(
GLOB
src_files
ConfigFile/src/*.cpp
PSKOutput3D/*.cpp
bc/*.cpp
communication/*.cpp
fields/*.cpp
grids/*.cpp
inputoutput/*.cpp
mathlib/*.cpp
mpidata/*.cpp
particles/*.cpp
performances/*.cpp
processtopology/*.cpp
solvers/*.cpp
utility/*.cpp
main/*.cpp
)
add_library(
iPIC3Dlib
${src_files}
)
target_include_directories(
iPIC3Dlib
PUBLIC include
)
#
# Link external libraries
#
if(USE_OPENMP)
target_link_libraries(
iPIC3Dlib
PUBLIC MPI::MPI_CXX
PUBLIC OpenMP::OpenMP_CXX
PRIVATE ${HDF5_C_HL_TARGET}
)
else()
target_link_libraries(
iPIC3Dlib
PUBLIC MPI::MPI_CXX
PRIVATE ${HDF5_C_HL_TARGET}
)
endif()
if (USE_CATALYST)
target_link_libraries(
iPIC3Dlib
PUBLIC iPICAdaptor
PRIVATE stdc++fs
)
endif()
#
# Macro definitions
#
if(USE_BATSRUS)
target_compile_definitions(iPIC3Dlib PUBLIC BATSRUS)
message(" WARNING: BATSRUS flag is active.")
else()
message(" INFO: BATSRUS is not active.")
endif()
if(NOT USE_HDF5)
target_compile_definitions(iPIC3Dlib PUBLIC NO_HDF5)
endif()
if (BUILD_SHARED_LIBS)
install(TARGETS iPIC3Dlib)
endif()
#
# Executable declaration
#
# Particle solver
add_executable(
iPIC3D
iPIC3D.cpp
)
target_link_libraries(
iPIC3D
iPIC3Dlib
stdc++fs
)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
add_definitions(-DDEBUG_MODE)
endif()
if(BENCH_MARK)
target_compile_definitions(iPIC3Dlib PUBLIC LOG_TASKS_TOTAL_TIME)
target_compile_definitions(iPIC3D PUBLIC LOG_TASKS_TOTAL_TIME)
endif()
## to save the executable in the folder where the CMakeLists.txt file is, i.e. CMAKE_CURRENT_SOURCE_DIR
set_target_properties(iPIC3D PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
## debug releases have a _d appended to the executable
set_target_properties(iPIC3D PROPERTIES DEBUG_POSTFIX "_d")
# Here we do the RPATH stuff so the exe is relocatable.
# Make it a function to avoid variables leaking.
function(add_install_libdir_to_rpath tgt)
if(BUILD_SHARED_LIBS)
get_target_property(install_rpaths ${tgt} INSTALL_RPATH)
if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
list(APPEND install_rpaths "\$ORIGIN/../${CMAKE_INSTALL_LIBDIR}")
endif()
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
list(APPEND install_rpaths "@loader_path/../${CMAKE_INSTALL_LIBDIR}")
endif()
list(REMOVE_DUPLICATES install_rpaths)
set_target_properties(${tgt}
PROPERTIES INSTALL_RPATH "${install_rpaths}"
)
endif()
endfunction()
add_install_libdir_to_rpath(iPIC3D)
install(TARGETS iPIC3D)
add_subdirectory(inputfiles)
message("Which system am I compiling for:")
message("MYHOSTNAME is ${myhostname}")
message("CMAKE_SYSTEM_PROCESSOR is ${CMAKE_SYSTEM_PROCESSOR}")
message("Compiler & compiler flags:")
message("CMAKE_CXX_COMPILER is ${CMAKE_CXX_COMPILER}")
message("CMAKE_CXX_FLAGS is ${CMAKE_CXX_FLAGS}")
message("HDF5_INCLUDE_DIRS is ${HDF5_INCLUDE_DIRS}")
message("HDF5_LIBRARIES is ${HDF5_LIBRARIES}")
message("HDF5_HL_LIBRARIES is ${HDF5_HL_LIBRARIES}")
message("MPI_LIBRARIES is ${MPI_LIBRARIES}")