-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
327 lines (273 loc) · 11.5 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
cmake_minimum_required (VERSION 3.12)
cmake_policy(VERSION 3.12)
project (OPAL VERSION 2022.1.0)
set (PROJECT_BUGREPORT [email protected])
string (REGEX REPLACE "\\.([0-9])\\." ".0\\1." PACKAGE_VERSION ${PROJECT_VERSION})
string (REGEX REPLACE "\\.([0-9])$" ".0\\1" PACKAGE_VERSION ${PACKAGE_VERSION})
string (REGEX REPLACE "\\." "" PACKAGE_VERSION ${PACKAGE_VERSION})
message (STATUS PACKAGE_VERSION=${PACKAGE_VERSION})
if (NOT CMAKE_CONFIGURATION_TYPES AND NOT CMAKE_BUILD_TYPE)
set (CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
FORCE
)
endif ()
cmake_host_system_information (RESULT HOSTNAME QUERY HOSTNAME)
message (STATUS "Build type is: " ${CMAKE_BUILD_TYPE})
message (STATUS "Host OS System: ${CMAKE_HOST_SYSTEM}")
message (STATUS "Hostname: ${HOSTNAME}")
# Select flags.
set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O3 -g ")
set (CMAKE_CXX_FLAGS_RELEASE "-O3")
set (CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
string(TOUPPER "${CMAKE_BUILD_TYPE}" uppercase_CMAKE_BUILD_TYPE)
if (uppercase_CMAKE_BUILD_TYPE MATCHES "^(DEBUG|RELWITHDEBINFO)$")
option (BUILD_FOR_PRODUCTION "Disable all assertion checks; Only use for production" OFF)
else()
option (BUILD_FOR_PRODUCTION "Disable all assertion checks; Only use for production" ON)
endif()
# Resolve all library dependencies
set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeModules")
find_package (MPI REQUIRED)
message (STATUS "The C++ compiler identification is: ${CMAKE_CXX_COMPILER_ID}")
message (STATUS "The C++ compiler version is: ${CMAKE_CXX_COMPILER_VERSION}")
message (STATUS "The MPI C++ compiler is: ${MPI_CXX_COMPILER}")
message (STATUS "The underlying C++ compiler is: ${CMAKE_CXX_COMPILER}")
option (ENABLE_OpenMP "Use hybrid parallelism MPI-OpenMP" OFF)
set (CMAKE_CXX_STANDARD 17)
set (CMAKE_CXX_STANDARD_REQUIRED ON)
set (CMAKE_CXX_EXTENSIONS OFF)
# Disable compile time assert (used by IPPL)
add_definitions (-DNOCTAssert)
add_compile_options (-Wall)
add_compile_options (-Wunused)
add_compile_options (-Wextra)
add_compile_options (-funroll-loops)
add_compile_options (-fstrict-aliasing)
# TODO(e-carlin): Why do I have to hardcode these paths?
set(Python_EXECUTABLE "/home/vagrant/.pyenv/shims/python3")
find_package(Python COMPONENTS Interpreter Development REQUIRED)
option (WILL_BUILD_STATIC_LIBRARY "Building static library" ON)
if (BUILD_OPAL_PYTHON)
option (WILL_BUILD_SHARED_LIBRARY "Building python hooks - requires dynamic libs" ON)
find_package (Python3 COMPONENTS Development REQUIRED)
endif ()
if (${WILL_BUILD_SHARED_LIBRARY})
add_compile_options ( -fPIC)
# force OPAL to link to shared libraries
if (UNIX)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".so")
elseif (APPLE)
set(CMAKE_FIND_LIBRARY_SUFFIXES ".dylib")
else()
MESSAGE(FATAL_ERROR "Operating system not APPLE or UNIX - quitting")
endif()
endif ()
# compiler dependent flags
message (STATUS "The underlying C++ compiler ID is: ${CMAKE_CXX_COMPILER_ID}")
if ( ${CMAKE_CXX_COMPILER_ID} STREQUAL "Intel" )
add_compile_options ("-diag-disable 383")
add_compile_options ("-diag-disable 981")
if (ENABLE_OpenMP)
add_compile_options (-openmp)
add_link_options (-openmp)
endif ()
elseif (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
add_compile_options (-Warray-bounds-pointer-arithmetic)
# Increase template depth for boost
add_compile_options (-ftemplate-depth=1024)
# get rid of linking warning with boost. Looks like that boost
# is using this visibility setting.
add_compile_options (-fvisibility=hidden)
add_compile_options (-fvisibility-inlines-hidden)
if (ENABLE_OpenMP)
if (CMAKE_HOST_APPLE)
message(FATAL_ERROR "Apple Clang does not support OpenMP!")
else ()
add_compile_options (-fopenmp)
add_link_options (-fopenmp)
endif ()
endif ()
elseif (${CMAKE_CXX_COMPILER_ID} MATCHES "GNU")
# An error in Trilinos/12.18.1 causes
# -Waggressive-loop-optimizations with -O3 optimization.
# See issue 587 and corresponding merge request 415.
# Clang does not support this flag!
add_compile_options (-fno-aggressive-loop-optimizations)
if (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS "4.7.3")
message (FATAL_ERROR "To build OPAL you need GCC version 4.7.3 or greater")
endif ()
# Warning flags
if (ENABLE_OpenMP)
add_compile_options (-fopenmp)
add_link_options (-fopenmp)
endif ()
# Enables extra error checking in the form of precondition assertion, such
# as bounds checking and null pointer checks when dereferencing smart pointers
if (NOT ${BUILD_FOR_PRODUCTION})
add_compile_options(-Wp,-D_GLIBCXX_ASSERTIONS)
endif()
enable_language (Fortran OPTIONAL)
else ()
message (STATUS "Unknown C++ compiler. Please use the GNU or Intel compiler, if you are having problems.")
endif ()
message (STATUS "Fortran compilers: ${CMAKE_Fortran_COMPILER_NAMES}")
if (CMAKE_Fortran_COMPILER)
message (STATUS "The Fortran compiler identification is: ${CMAKE_Fortran_COMPILER_ID}")
message (STATUS "The Fortran compiler version is: ${CMAKE_Fortran_COMPILER_VERSION}")
message (STATUS "The Fortran compiler is: ${CMAKE_Fortran_COMPILER}")
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
set (Fortran_LIBS "-lgfortran")
endif ()
# See issue 587 and corresponding merge request 415.
else ()
message (STATUS "No Fortran compiler found (optional)")
if (ENABLE_AMR)
message (FATAL_ERROR "AMR is enabled but no Fortran compiler found!")
endif ()
endif ()
find_package (H5Hut REQUIRED)
if (NOT ${WILL_BUILD_SHARED_LIBRARY})
set (HDF5_USE_STATIC_LIBRARIES ON)
endif ()
set (HDF5_PREFER_PARALLEL ON)
find_package (HDF5 REQUIRED)
if(UNIX AND NOT APPLE)
set (HDF5_LIBRARIES ${HDF5_LIBRARIES} ${CMAKE_DL_LIBS} rt z)
endif ()
message (STATUS "Found HDF5 libraries: ${HDF5_LIBRARIES}")
find_package (GSL REQUIRED)
message (STATUS "Found gsl libraries: ${GSL_LIBRARIES}")
set (BOOSTROOT $ENV{BOOST_DIR})
if (NOT ${WILL_BUILD_SHARED_LIBRARY})
set (Boost_USE_STATIC_LIBS ON)
endif ()
set (Boost_USE_MULTITHREADED ON)
set (Boost_USE_STATIC_RUNTIME OFF)
set (Boost_LIBS chrono filesystem iostreams regex serialization system timer)
find_package (Boost 1.66.0
REQUIRED COMPONENTS ${Boost_LIBS})
if(UNIX AND NOT APPLE)
set (Boost_LIBRARIES ${Boost_LIBRARIES} rt)
endif ()
message (STATUS "Found Boost include dirs: ${Boost_INCLUDE_DIRS}")
message (STATUS "Found Boost library dirs: ${Boost_LIBRARY_DIRS}")
message (STATUS "Found Boost libraries: ${Boost_LIBRARIES}")
include_directories (SYSTEM ${Boost_INCLUDE_DIRS})
# Handle options
option (BUILD_OPAL_UNIT_TESTS "Unit tests" OFF)
if (BUILD_OPAL_UNIT_TESTS)
find_package (GTest REQUIRED HINT $ENV{GTEST_PREFIX})
add_definitions (-DWITH_UNIT_TESTS)
endif ()
option (ENABLE_AMR "Enable AMReX based AMR solver" OFF)
if (ENABLE_AMR)
message (STATUS "Enable AMR_SOLVER " ${ENABLE_AMR})
enable_language (Fortran)
find_package (AMReX CONFIG REQUIRED
HINTS $ENV{AMREX_HOME}/cmake $ENV{AMREX_DIR}/cmake $ENV{AMREX_PREFIX}/cmake)
message (STATUS "Found AMReX include dir: ${AMREX_INCLUDE_DIR}")
message (STATUS "Found AMReX library dir: ${AMREX_LIBRARY_DIR}")
message (STATUS "Found AMReX libraries: ${AMREX_LIBRARIES}")
message (STATUS "Found AMReX Fortran links: ${AMREX_EXTRA_Fortran_LINK_LINE}")
echo_amrex_config_options()
add_definitions(${AMREX_DEFINES})
add_definitions(-DENABLE_AMR)
endif ()
option (ENABLE_AMR_MG_SOLVER "Enable AMR MG solver" OFF)
option (ENABLE_SAAMG_SOLVER "Enable iterative SA-AMG-PCG self field solver" OFF)
if (ENABLE_SAAMG_SOLVER OR ENABLE_AMR_MG_SOLVER)
#
# :FIXME: We have to add checks whether the required Trilinos modules
# are available. If there are problems of any kind with this
# configuration, either fix it in a general way or build your
# Trilinos. Host specific should be avoided in almost any case.
message (STATUS "Enable SAAMG_SOLVER: " ${ENABLE_SAAMG_SOLVER})
message (STATUS "Enable AMR_MG_SOLVER: " ${ENABLE_AMR_MG_SOLVER})
find_package (Trilinos REQUIRED HINTS $ENV{TRILINOS_PREFIX} $ENV{TRILINOS_DIR} $ENV{TRILINOS})
message (STATUS "Found Trilinos: ${Trilinos_DIR}")
message (STATUS " Trilinos version: ${Trilinos_VERSION}")
message (STATUS " Trilinos package list: ${Trilinos_PACKAGE_LIST}")
message (STATUS " Trilinos libraries: ${Trilinos_LIBRARIES}")
message (STATUS " Trilinos TPL libraries: ${Trilinos_TPL_LIBRARIES}")
if (NOT ${MPI_CXX_COMPILER} STREQUAL ${Trilinos_CXX_COMPILER} )
message (WARNING "Compiler mismatch:")
message (WARNING " Trilinos was compiled with:")
message (WARNING " ${Trilinos_C_COMPILER}")
message (WARNING " ${Trilinos_CXX_COMPILER}")
message (WARNING " ${Trilinos_Fortran_COMPILER}")
message (WARNING " You are using:")
message (WARNING " ${CMAKE_C_COMPILER}")
message (WARNING " ${CMAKE_CXX_COMPILER}")
message (WARNING " ${CMAKE_Fortran_COMPILER}")
message (FATAL_ERROR "")
endif ()
endif ()
option (ENABLE_OPAL_FEL "Enable OPAL FEL" OFF)
if (ENABLE_OPAL_FEL)
message (STATUS "Enable OPAL FEL: " ${ENABLE_OPAL_FEL})
find_package (MITHRA MODULE REQUIRED)
add_definitions (-DENABLE_OPAL_FEL)
endif()
option (DBG_SCALARFIELD "Enable dump of scalar field rho_m" OFF)
if (DBG_SCALARFIELD)
message (STATUS "Write scalar rho_m field is enabled ")
add_definitions (-DDBG_SCALARFIELD)
endif ()
option (DBG_STENCIL "Dump stencil of iterative solver in matlab format" OFF)
if (DBG_STENCIL)
message (STATUS "Write stencil is enabled ")
add_definitions(-DDBG_STENCIL)
endif ()
option (NO_FIELD_ASSIGN_OPTIMIZATION "Disable compiler optimization of IPPL field assignment" OFF)
if (NO_FIELD_ASSIGN_OPTIMIZATION)
message (STATUS "Compiler will not try to optimize field assignment")
add_definitions(-DdontOPTIMIZE_FIELD_ASSIGNMENT)
endif ()
option (ENABLE_DOXYDOC "compile Doxygen documentation" OFF)
if (ENABLE_DOXYDOC)
find_package(Doxygen REQUIRED)
configure_file (${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in
${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY
)
add_custom_target (doxydoc
${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM
)
endif ()
add_custom_target(always_rebuild ALL
DEPENDS
src/OPALrevision.h
)
add_custom_command(
OUTPUT src/OPALrevision.h
COMMAND ./gen_OPALrevision
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
DEPENDS
always_rebuild
)
add_subdirectory (ippl)
add_subdirectory (optimizer)
add_subdirectory (src)
add_subdirectory (tools)
if (BUILD_OPAL_UNIT_TESTS)
add_subdirectory (tests)
endif ()
# make variables visible in other CMakeLists files
set (OPAL_CXX_FLAGS ${OPAL_CXX_FLAGS}
CACHE INTERNAL "" FORCE
)
set (OPAL_LIBS ${OPAL_LIBS}
CACHE INTERNAL "" FORCE
)
# configure file
configure_file (
${CMAKE_CURRENT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config_install.cmake
)
install (
FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config_install.cmake
DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/cmake/${PROJECT_NAME}"
RENAME ${PROJECT_NAME}Config.cmake
)