-
Notifications
You must be signed in to change notification settings - Fork 20
/
CMakeLists.txt
285 lines (237 loc) · 9.92 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
cmake_minimum_required (VERSION 3.20.3)
project (IPPL CXX)
set (IPPL_VERSION_MAJOR 3)
set (IPPL_VERSION_MINOR 0.2)
include(FetchContent)
set (IPPL_VERSION_NAME "V${IPPL_VERSION_MAJOR}.${IPPL_VERSION_MINOR}")
option(DOWNLOAD_EXTRACT_TIMESTAMP ON FORCE)
set (IPPL_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
if(NOT WIN32)
string(ASCII 27 Esc)
set(ColourReset "${Esc}[m")
set(Red "${Esc}[31m")
set(Green "${Esc}[32m")
set(Yellow "${Esc}[1;33m")
endif()
macro(remove_flag_from_target _target _flag)
get_target_property(_target_cxx_flags ${_target} COMPILE_OPTIONS)
if(_target_cxx_flags)
list(REMOVE_ITEM _target_cxx_flags ${_flag})
set_target_properties(${_target} PROPERTIES COMPILE_OPTIONS "${_target_cxx_flags}")
endif()
endmacro()
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
)
message(STATUS "${Yellow}CMAKE_BUILD_TYPE not set, defaulting to ${CMAKE_BUILD_TYPE} ${ColourReset}")
else ()
message (STATUS "${Green}Build type is: ${CMAKE_BUILD_TYPE}${ColourReset}")
endif()
if (${CMAKE_BUILD_TYPE} STREQUAL "Release")
add_definitions (-DNOPAssert)
endif ()
add_compile_options (-Wall)
add_compile_options (-Wunused)
add_compile_options (-Wextra)
#¼add_compile_options (-Werror)
# allow deprecated functions
add_compile_options (-Wno-deprecated-declarations)
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options (-Wno-deprecated-copy)
add_compile_options (-Wno-sign-compare)
endif()
option (USE_STATIC_LIBRARIES "Link with static libraries if available" ON)
if(NOT IPPL_PLATFORMS)
message(STATUS "${Yellow}IPPL_PLATFORMS flag is not set, defaulting to serial backend${ColourReset}")
set(IPPL_PLATFORMS "SERIAL")
endif()
#message(STATUS "IPPL_PLATFORMS flag is set to: ${IPPL_PLATFORMS}")
if(Ippl_PLATFORMS)
set(IPPL_PLATFORMS ${Ippl_PLATFORMS})
endif()
string(TOUPPER "${IPPL_PLATFORMS}" IPPL_PLATFORMS)
# Perform case distinction
if("${IPPL_PLATFORMS}" STREQUAL "CUDA")
message(STATUS "${Green}CUDA backend enabled${ColourReset}")
set(Kokkos_ENABLE_CUDA ON CACHE BOOL "Enable Kokkos CUDA Backend")
set(Heffte_ENABLE_CUDA ON CACHE BOOL "Set Heffte CUDA Backend")
elseif("${IPPL_PLATFORMS}" STREQUAL "OPENMP")
message(STATUS "${Green}OpenMP backend enabled${ColourReset}")
if(NOT Heffte_ENABLE_FFTW)
message(STATUS "${Yellow}Because Heffte_ENABLE_FFTW is not set defaulting to Stock with AVX${ColourReset}")
set(Heffte_ENABLE_AVX2 ON CACHE BOOL "Enable Heffte Stock backend lol")
else()
message(STATUS "${Green}Enabled FFTW${ColourReset}")
endif()
set(Kokkos_ENABLE_OPENMP ON CACHE BOOL "Enable Kokkos OpenMP Backend")
elseif("${IPPL_PLATFORMS}" STREQUAL "SERIAL")
message(STATUS "${Green}Serial backend enabled${ColourReset}")
if(NOT Heffte_ENABLE_FFTW)
message(STATUS "${Yellow}Because Heffte_ENABLE_FFTW is not set defaulting to Stock with AVX${ColourReset}")
set(Heffte_ENABLE_AVX2 ON CACHE BOOL "Enable Heffte Stock backend lol")
endif()
elseif("${IPPL_PLATFORMS}" STREQUAL "CUDA;OPENMP" OR "${IPPL_PLATFORMS}" STREQUAL "OPENMP;CUDA")
message(STATUS "${Green}CUDA and OpenMP backend enabled${ColourReset}")
set(Heffte_ENABLE_CUDA ON CACHE BOOL "Set Heffte CUDA Backend")
set(Kokkos_ENABLE_OPENMP ON CACHE BOOL "Enable Kokkos OpenMP Backend")
set(Kokkos_ENABLE_CUDA ON CACHE BOOL "Enable Kokkos CUDA Backend")
else()
message(FATAL_ERROR "Unknown or unsupported platform: ${IPPL_PLATFORMS}")
# Handle unknown or unsupported platform
endif()
if(NOT Kokkos_VERSION)
set(Kokkos_VERSION "4.1.00")
message(STATUS "${Green}Selecting default Kokkos version: ${Kokkos_VERSION} ${ColourReset}")
else()
message(STATUS "${Green}Selected Kokkos version: ${Kokkos_VERSION} ${ColourReset}")
endif()
find_package(Kokkos ${Kokkos_VERSION} QUIET)
if(NOT Kokkos_FOUND)
FetchContent_Declare(
kokkos
DOWNLOAD_EXTRACT_TIMESTAMP True
URL https://github.com/kokkos/kokkos/archive/refs/tags/${Kokkos_VERSION}.tar.gz
)
FetchContent_MakeAvailable(kokkos)
endif()
# Select flags.
set (CMAKE_CXX_STANDARD 20)
set (CMAKE_CUDA_EXTENSIONS OFF)
set (CMAKE_CXX_EXTENSIONS OFF)
set (CMAKE_CXX_STANDARD_REQUIRED ON)
set (CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINGO} -O3 -g ")
set (CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
#set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g")
if (NOT "${IPPL_PLATFORMS}" STREQUAL "CUDA" AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
# Use sanitizer flags for GCC or Clang only
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fsanitize=address,undefined")
endif ()
if ("${Kokkos_DEVICES}" MATCHES "CUDA")
set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -G")
endif()
# Suppress erroneous buffer overflow warnings when compiling under GCC 12
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND "${CMAKE_CXX_COMPILER_VERSION}" MATCHES "12*")
add_compile_options (-Wno-stringop-overflow)
add_compile_options (-Wno-array-bounds)
add_compile_options (-Wno-restrict)
endif()
# Resolve all library dependencies
set (CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMakeModules")
find_package (MPI REQUIRED)
include_directories(${MPI_INCLUDE_PATH})
link_directories(${MPI_LIBRARY_PATH})
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(USE_ALTERNATIVE_VARIANT "Use modified variant implementation (required for CUDA 12.2 + GCC 12.3.0)" OFF)
if (USE_ALTERNATIVE_VARIANT)
add_definitions (-DUSE_ALTERNATIVE_VARIANT)
endif()
option (ENABLE_FFT "Enable FFT transform" ON)
if (ENABLE_FFT)
add_definitions (-DENABLE_FFT)
if(NOT Heffte_VERSION)
set(Heffte_VERSION "MASTER")
message(STATUS "${Green}Selecting default Heffte version: MASTER (Master branch on ttps://github.com/icl-utk-edu/heffte) ${ColourReset}")
else()
message(STATUS "${Green}Selected Heffte version: ${Heffte_VERSION} ${ColourReset}")
endif()
if(Heffte_VERSION MATCHES "MASTER")
find_package (Heffte 2.2.0 QUIET)
else()
find_package (Heffte ${Heffte_VERSION} QUIET)
endif()
if(NOT Heffte_FOUND)
message(STATUS "Using FetchContent for Heffte")
if(Heffte_VERSION MATCHES "MASTER")
if(NOT HEFFTE_COMMIT_HASH)
set(HEFFTE_COMMIT_HASH "9eab7c0eb18e86acaccc2b5699b30e85a9e7bdda")
message(STATUS "${Yellow}Defaulting to Heffte commit: ${HEFFTE_COMMIT_HASH} ${ColourReset}")
else()
message(STATUS "${Green}Using Heffte commit: ${HEFFTE_COMMIT_HASH} ${ColourReset}")
endif()
FetchContent_Declare(
Heffte
GIT_REPOSITORY https://github.com/icl-utk-edu/heffte
GIT_TAG ${HEFFTE_COMMIT_HASH}
)
else()
FetchContent_Declare(
Heffte
DOWNLOAD_EXTRACT_TIMESTAMP True
URL https://github.com/icl-utk-edu/heffte/archive/refs/tags/v${Heffte_VERSION}.tar.gz
)
endif()
FetchContent_MakeAvailable(Heffte)
# Required to suppress warnings related to heffte
target_include_directories(Heffte SYSTEM PUBLIC "${Heffte_SOURCE_DIR}/include")
set(Heffte_DIR "${Heffte_SOURCE_DIR}")
remove_flag_from_target(Heffte "-Werror")
remove_flag_from_target(Heffte "-Wall")
remove_flag_from_target(Heffte "-Wextra")
endif()
message (STATUS "Found Heffte_DIR: ${Heffte_DIR}")
endif ()
option (ENABLE_SOLVERS "Enable IPPL solvers" ON)
add_subdirectory (src)
option (ENABLE_TESTS "Enable IPPL tests" OFF)
if (ENABLE_TESTS)
add_subdirectory (test)
endif ()
option (ENABLE_ALPINE "Enable Alpine" OFF)
if (ENABLE_ALPINE)
if (NOT ENABLE_SOLVERS)
message (FATAL_ERROR "Cannot enable Alpine since Solver not enabled (-DENABLE_SOLVERS=ON)!")
endif ()
if (NOT ENABLE_FFT)
message (FATAL_ERROR "Cannot enable Alpine since FFT not enabled (-DENABLE_FFT=ON)!")
endif ()
message (STATUS "Enable Alpine")
add_subdirectory (alpine)
endif ()
option (ENABLE_COSMOLOGY "Enable Cosmology" OFF)
if (ENABLE_COSMOLOGY)
if (NOT ENABLE_SOLVERS)
message (FATAL_ERROR "Cannot enable Cosmology since Solver not enabled (-DENABLE_SOLVERS=ON)!")
endif ()
if (NOT ENABLE_FFT)
message (FATAL_ERROR "Cannot enable Cosmology since FFT not enabled (-DENABLE_FFT=ON)!")
endif ()
message (STATUS "Enable Cosmology")
add_subdirectory (cosmology)
endif ()
option (ENABLE_UNIT_TESTS "Enable unit tests" OFF)
if (ENABLE_UNIT_TESTS)
if (NOT ENABLE_FFT)
message(WARNING "Enabling unit tests even though FFT not enabled (-DENABLE_FFT=ON)!")
endif ()
include(FetchContent)
include(GoogleTest)
enable_testing()
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/refs/tags/v1.14.0.zip
DOWNLOAD_EXTRACT_TIMESTAMP ON # policy hint for CMake > 3.24
)
# For Windows: Prevent overriding the parent project's compiler/linker settings
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(googletest)
add_subdirectory (unit_tests)
endif ()
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
)
# vi: set et ts=4 sw=4 sts=4:
# Local Variables:
# mode: cmake
# cmake-tab-width: 4
# indent-tabs-mode: nil
# require-final-newline: nil
# End: