CMakeLists.txt 13.7 KB
Newer Older
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
#######################################################################
#                                                                     #
#  Copyright 2019 Max Planck Institute                                #
#                 for Dynamics and Self-Organization                  #
#                                                                     #
#  This file is part of bfps.                                         #
#                                                                     #
#  bfps 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.                             #
#                                                                     #
#  bfps 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 bfps.  If not, see <http://www.gnu.org/licenses/>       #
#                                                                     #
# Contact: Cristian.Lalescu@ds.mpg.de                                 #
#                                                                     #
#######################################################################



27
cmake_minimum_required(VERSION 3.10)
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
cmake_policy(VERSION 3.12)

if (DEFINED ENV{MPICXX})
    message(STATUS "Using CMAKE_CXX_COMPILER=MPICXX")
    set(CMAKE_CXX_COMPILER $ENV{MPICXX})
else()
    message(STATUS "MPICXX environment variable undefined, trying to find MPI")
    set(MPI_STATIC ON)
    find_package(MPI REQUIRED)
endif()

if (DEFINED ENV{MPICC})
    set(CMAKE_C_COMPILER $ENV{MPICC})
    message(STATUS "Using CMAKE_C_COMPILER=MPICC")
endif()

if (DEFINED ENV{CMAKE_INSTALL_PREFIX})
    set(CMAKE_INSTALL_PREFIX $ENV{CMAKE_INSTALL_PREFIX})
endif()
Cristian Lalescu's avatar
Cristian Lalescu committed
47

48
project(TurTLE)
49

50
execute_process(COMMAND python ${PROJECT_SOURCE_DIR}/get_version.py OUTPUT_VARIABLE TURTLE_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
51

52
53
project(TurTLE
        VERSION ${TURTLE_VERSION}
54
        LANGUAGES CXX)
55
56
57


set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/morse ${CMAKE_MODULE_PATH})
58
set(TURTLE_LIBS "")
59
60
61
62
63
64
65
66

#####################################################################################
## MPI

set(CMAKE_CXX_COMPILE_FLAGS "${CMAKE_CXX_COMPILE_FLAGS} ${MPI_CXX_COMPILE_OPTIONS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MPI_CXX_LINK_FLAGS}")
include_directories(${MPI_CXX_INCLUDE_DIRS})
add_definitions(${MPI_CXX_COMPILE_DEFINITIONS})
67
list(APPEND TURTLE_LIBS "${MPI_CXX_LIBRARIES}")
68
69
70
71
72
73
74

#####################################################################################
## CXX Standard

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# set(CMAKE_CXX_EXTENSIONS OFF)
75
76

#####################################################################################
77
78
79
## OpenMP

find_package(OpenMP REQUIRED)
80

81
82
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${OpenMP_EXE_LINKER_FLAGS}")
83
list(APPEND TURTLE_LIBS "${OpenMP_CXX_LIB_NAMES}")
84
85
86

#####################################################################################
## Extra flags
87

88
set(CMAKE_CXX_COMPILE_FLAGS "${CMAKE_CXX_COMPILE_FLAGS} $ENV{TURTLE_OPTIMIZATION_FLAGS} -Wall -g")
89
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_CXX_COMPILE_FLAGS}")
Cristian Lalescu's avatar
Cristian Lalescu committed
90

91
92
93
#####################################################################################
## HDF5

94
set(HDF5_STATIC ON)
95
96
if(NOT DEFINED ENV{HDF5_ROOT})
    message(WARNING "The environment variable HDF5_ROOT is undefined, this might cause trouble in finding the HDF5")
Cristian Lalescu's avatar
Cristian Lalescu committed
97
endif()
98

99
100
set(HDF5_PREFER_PARALLEL TRUE)
find_package(HDF5 REQUIRED)
101

102
103
104
105
message(STATUS "HDF5_C_INCLUDE_DIRS ${HDF5_C_INCLUDE_DIRS}")

include_directories(${HDF5_C_INCLUDE_DIRS})
add_definitions(${HDF5_C_DEFINITIONS})
106
list(APPEND TURTLE_LIBS "${HDF5_C_LIBRARIES}")
107

108
option(TURTLE_HDF5_USE_SZIP "Set to on to also link against SZIP" OFF)
109

110
111
112
113
if(TURTLE_HDF5_USE_SZIP)
    option(TURTLE_HDF5_SZIP_LIB_PATH "Additional lib path for SZIP" "")
    if(TURTLE_HDF5_SZIP_LIB_PATH)
        link_directories(${TURTLE_HDF5_SZIP_LIB_PATH})
114
    endif()
115
    list(APPEND TURTLE_LIBS "z")
116
117
118
119
120
endif()

#####################################################################################
## FFTW

121
set(FFTW_STATIC ON)
122
123
124
125
126
127
128
129
if(NOT DEFINED ENV{FFTW_DIR})
    message(WARNING "The environment variable FFTW_DIR is undefined, this might cause trouble in finding the FFTW")
endif()

find_package(FFTW REQUIRED OMP)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FFTW_CFLAGS_OTHER}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FFTW_LDFLAGS_OTHER}")
130
list(APPEND TURTLE_LIBS "${FFTW_LIBRARIES}")
131
132
133
134
135
136
137
include_directories(${FFTW_INCLUDE_DIRS})
link_directories(${FFTW_LIBRARY_DIRS})

find_package(FFTW REQUIRED OMP SIMPLE)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${FFTW_CFLAGS_OTHER}")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FFTW_LDFLAGS_OTHER}")
138
list(APPEND TURTLE_LIBS "${FFTW_LIBRARIES}")
139
140
include_directories(${FFTW_INCLUDE_DIRS})
link_directories(${FFTW_LIBRARY_DIRS})
141

142
# hack for FFTW MPI libs
143
144
145
find_library(
    FFTWF_MPI fftw3f_mpi
    HINTS ${FFTW_LIBRARY_DIRS})
146
set(TURTLE_LIBS ${FFTWF_MPI} ${TURTLE_LIBS})
147
148
149
find_library(
    FFTW_MPI fftw3_mpi
    HINTS ${FFTW_LIBRARY_DIRS})
150
set(TURTLE_LIBS ${FFTW_MPI} ${TURTLE_LIBS})
151
152


153
154
155
156
157
158
#####################################################################################
## Get the links and include from deps

get_property(ALL_INCLUDE_DIRS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY INCLUDE_DIRECTORIES)
get_property(ALL_LINK_DIRS DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} PROPERTY LINK_DIRECTORIES)

159
160
161
#####################################################################################
## Build the lib

162
include_directories(${PROJECT_SOURCE_DIR}/cpp)
Cristian Lalescu's avatar
Cristian Lalescu committed
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
#file(GLOB_RECURSE cpp_for_lib ${PROJECT_SOURCE_DIR}/*.cpp)
set(cpp_for_lib
    ${PROJECT_SOURCE_DIR}/cpp/full_code/code_base.cpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/direct_numerical_simulation.cpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/NSVE.cpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/joint_acc_vel_stats.cpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/test.cpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/filter_test.cpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/field_test.cpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/symmetrize_test.cpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/field_output_test.cpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/get_rfields.cpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/field_single_to_double.cpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/resize.cpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/NSVE_field_stats.cpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/native_binary_to_hdf5.cpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/postprocess.cpp
    ${PROJECT_SOURCE_DIR}/cpp/field.cpp
    ${PROJECT_SOURCE_DIR}/cpp/kspace.cpp
    ${PROJECT_SOURCE_DIR}/cpp/field_layout.cpp
    ${PROJECT_SOURCE_DIR}/cpp/hdf5_tools.cpp
    ${PROJECT_SOURCE_DIR}/cpp/fftw_tools.cpp
    ${PROJECT_SOURCE_DIR}/cpp/vorticity_equation.cpp
    ${PROJECT_SOURCE_DIR}/cpp/field_binary_IO.cpp
    ${PROJECT_SOURCE_DIR}/cpp/spline_n1.cpp
    ${PROJECT_SOURCE_DIR}/cpp/spline_n2.cpp
    ${PROJECT_SOURCE_DIR}/cpp/spline_n3.cpp
    ${PROJECT_SOURCE_DIR}/cpp/spline_n4.cpp
    ${PROJECT_SOURCE_DIR}/cpp/spline_n5.cpp
    ${PROJECT_SOURCE_DIR}/cpp/spline_n6.cpp
    ${PROJECT_SOURCE_DIR}/cpp/spline_n7.cpp
    ${PROJECT_SOURCE_DIR}/cpp/spline_n8.cpp
    ${PROJECT_SOURCE_DIR}/cpp/spline_n9.cpp
    ${PROJECT_SOURCE_DIR}/cpp/spline_n10.cpp
    ${PROJECT_SOURCE_DIR}/cpp/Lagrange_polys.cpp
    ${PROJECT_SOURCE_DIR}/cpp/scope_timer.cpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/test_interpolation.cpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/NSVEparticles.cpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/NSVEcomplex_particles.cpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/NSVEp_extra_sampling.cpp
    ${PROJECT_SOURCE_DIR}/cpp/particles/particles_inner_computer.cpp)
set(hpp_for_lib
    ${PROJECT_SOURCE_DIR}/cpp/full_code/code_base.hpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/direct_numerical_simulation.hpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/NSVE.hpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/joint_acc_vel_stats.hpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/test.hpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/filter_test.hpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/field_test.hpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/symmetrize_test.hpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/field_output_test.hpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/get_rfields.hpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/field_single_to_double.hpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/resize.hpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/NSVE_field_stats.hpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/native_binary_to_hdf5.hpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/postprocess.hpp
    ${PROJECT_SOURCE_DIR}/cpp/field.hpp
    ${PROJECT_SOURCE_DIR}/cpp/kspace.hpp
    ${PROJECT_SOURCE_DIR}/cpp/field_layout.hpp
    ${PROJECT_SOURCE_DIR}/cpp/hdf5_tools.hpp
    ${PROJECT_SOURCE_DIR}/cpp/fftw_tools.hpp
    ${PROJECT_SOURCE_DIR}/cpp/vorticity_equation.hpp
    ${PROJECT_SOURCE_DIR}/cpp/field_binary_IO.hpp
    ${PROJECT_SOURCE_DIR}/cpp/spline_n1.hpp
    ${PROJECT_SOURCE_DIR}/cpp/spline_n2.hpp
    ${PROJECT_SOURCE_DIR}/cpp/spline_n3.hpp
    ${PROJECT_SOURCE_DIR}/cpp/spline_n4.hpp
    ${PROJECT_SOURCE_DIR}/cpp/spline_n5.hpp
    ${PROJECT_SOURCE_DIR}/cpp/spline_n6.hpp
    ${PROJECT_SOURCE_DIR}/cpp/spline_n7.hpp
    ${PROJECT_SOURCE_DIR}/cpp/spline_n8.hpp
    ${PROJECT_SOURCE_DIR}/cpp/spline_n9.hpp
    ${PROJECT_SOURCE_DIR}/cpp/spline_n10.hpp
    ${PROJECT_SOURCE_DIR}/cpp/Lagrange_polys.hpp
    ${PROJECT_SOURCE_DIR}/cpp/scope_timer.hpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/test_interpolation.hpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/NSVEparticles.hpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/NSVEcomplex_particles.hpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/NSVEp_extra_sampling.hpp
    ${PROJECT_SOURCE_DIR}/cpp/particles/particles_inner_computer.hpp
    ${PROJECT_SOURCE_DIR}/cpp/particles/abstract_particles_input.hpp
    ${PROJECT_SOURCE_DIR}/cpp/particles/abstract_particles_output.hpp
    ${PROJECT_SOURCE_DIR}/cpp/particles/abstract_particles_system.hpp
    ${PROJECT_SOURCE_DIR}/cpp/particles/alltoall_exchanger.hpp
    ${PROJECT_SOURCE_DIR}/cpp/particles/env_utils.hpp
    ${PROJECT_SOURCE_DIR}/cpp/particles/lock_free_bool_array.hpp
    ${PROJECT_SOURCE_DIR}/cpp/particles/p2p_computer_empty.hpp
    ${PROJECT_SOURCE_DIR}/cpp/particles/p2p_computer.hpp
    ${PROJECT_SOURCE_DIR}/cpp/particles/p2p_distr_mpi.hpp
    ${PROJECT_SOURCE_DIR}/cpp/particles/p2p_tree.hpp
    ${PROJECT_SOURCE_DIR}/cpp/particles/particles_adams_bashforth.hpp
    ${PROJECT_SOURCE_DIR}/cpp/particles/particles_distr_mpi.hpp
    ${PROJECT_SOURCE_DIR}/cpp/particles/particles_field_computer.hpp
    ${PROJECT_SOURCE_DIR}/cpp/particles/particles_generic_interp.hpp
    ${PROJECT_SOURCE_DIR}/cpp/particles/particles_inner_computer_empty.hpp
    ${PROJECT_SOURCE_DIR}/cpp/particles/particles_input_hdf5.hpp
    ${PROJECT_SOURCE_DIR}/cpp/particles/particles_output_hdf5.hpp
    ${PROJECT_SOURCE_DIR}/cpp/particles/particles_output_mpiio.hpp
    ${PROJECT_SOURCE_DIR}/cpp/particles/particles_output_sampling_hdf5.hpp
    ${PROJECT_SOURCE_DIR}/cpp/particles/particles_sampling.hpp
    ${PROJECT_SOURCE_DIR}/cpp/particles/particles_system_builder.hpp
    ${PROJECT_SOURCE_DIR}/cpp/particles/particles_system.hpp
    ${PROJECT_SOURCE_DIR}/cpp/particles/particles_utils.hpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/main_code.hpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/codes_with_no_output.hpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/NSVE_no_output.hpp
    ${PROJECT_SOURCE_DIR}/cpp/full_code/NSVEparticles_no_output.hpp
    ${PROJECT_SOURCE_DIR}/cpp/base.hpp
    ${PROJECT_SOURCE_DIR}/cpp/fftw_interface.hpp
    ${PROJECT_SOURCE_DIR}/cpp/bfps_timer.hpp
    ${PROJECT_SOURCE_DIR}/cpp/omputils.hpp
    ${PROJECT_SOURCE_DIR}/cpp/shared_array.hpp
    ${PROJECT_SOURCE_DIR}/cpp/spline.hpp
    )
#file(GLOB_RECURSE hpp_for_lib ${PROJECT_SOURCE_DIR}/*.hpp)
280
LIST(APPEND source_files ${hpp_for_lib} ${cpp_for_lib})
Cristian Lalescu's avatar
Cristian Lalescu committed
281

Cristian Lalescu's avatar
Cristian Lalescu committed
282
add_library(TurTLE ${source_files})
283

Cristian Lalescu's avatar
Cristian Lalescu committed
284
target_link_libraries(TurTLE ${TURTLE_LIBS})
285

Cristian Lalescu's avatar
Cristian Lalescu committed
286
287
install(TARGETS TurTLE EXPORT TURTLE_EXPORT DESTINATION lib/ )
install(DIRECTORY ${PROJECT_SOURCE_DIR}/cpp/ DESTINATION include/TurTLE/ FILES_MATCHING PATTERN "*.h*")
288
289
290
291

#####################################################################################
## Export the configuration

Cristian Lalescu's avatar
Cristian Lalescu committed
292
configure_file(${PROJECT_SOURCE_DIR}/cmake/TurTLEConfig.cmake.in ${PROJECT_BINARY_DIR}/TurTLEConfig.cmake @ONLY)
293

Cristian Lalescu's avatar
Cristian Lalescu committed
294
install(FILES "${PROJECT_BINARY_DIR}/TurTLEConfig.cmake" DESTINATION lib/)
Cristian Lalescu's avatar
Cristian Lalescu committed
295
export(TARGETS TurTLE FILE "${PROJECT_BINARY_DIR}/TurTLELibraryDepends.cmake")
296
install(EXPORT TURTLE_EXPORT DESTINATION lib/)
297

298

299
300
#####################################################################################
## Install the python wrapper
301
# copy command
Cristian Lalescu's avatar
Cristian Lalescu committed
302
install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/TurTLE ${PROJECT_BINARY_DIR}/python/TurTLE/)")
303
if(EXISTS "${PROJECT_SOURCE_DIR}/host_info.py")
Cristian Lalescu's avatar
Cristian Lalescu committed
304
    install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/host_info.py ${PROJECT_BINARY_DIR}/python/TurTLE/)")
305
else()
Cristian Lalescu's avatar
Cristian Lalescu committed
306
    install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${PROJECT_SOURCE_DIR}/pc_host_info.py ${PROJECT_BINARY_DIR}/python/TurTLE/host_info.py)")
307
endif()
308
install(CODE "execute_process(COMMAND python ${PROJECT_SOURCE_DIR}/setup.py install --force --prefix=${CMAKE_INSTALL_PREFIX} WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/python/)")
309