-
Notifications
You must be signed in to change notification settings - Fork 82
/
CMakeLists.txt
280 lines (238 loc) · 10.1 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
############################ BASE ######################################
cmake_minimum_required (VERSION 3.20 FATAL_ERROR)
project(AMR-Wind CXX C)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE INTERNAL "")
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake")
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
include(amr-wind-utils)
########################## OPTIONS #####################################
#General options for the project
option(AMR_WIND_ENABLE_ALL_WARNINGS "Show most warnings for most compilers" ON)
option(AMR_WIND_ENABLE_CLANG_TIDY "Compile with clang-tidy static analysis" OFF)
option(AMR_WIND_ENABLE_CPPCHECK "Enable cppcheck static analysis target" OFF)
option(AMR_WIND_ENABLE_FCOMPARE "Enable building fcompare when not testing" OFF)
option(AMR_WIND_ENABLE_DOCUMENTATION "Enable documentation target" OFF)
#Enabling tests overrides the executable options
option(AMR_WIND_ENABLE_UNIT_TESTS "Enable unit testing" ON)
option(AMR_WIND_ENABLE_TESTS "Enable testing suite" OFF)
option(AMR_WIND_TEST_WITH_FCOMPARE "Check test plots against gold files" OFF)
option(AMR_WIND_SAVE_GOLDS "Provide a directory in which to save golds during testing" OFF)
option(AMR_WIND_ENABLE_FPE_TRAP_FOR_TESTS "Enable FPE trapping in tests" ON)
option(AMR_WIND_TEST_WITH_PYTHON "Enable testing relying on python, like postprocessing" OFF)
#Options for the executable
option(AMR_WIND_ENABLE_MPI "Enable MPI" OFF)
option(AMR_WIND_ENABLE_OPENMP "Enable OpenMP" OFF)
option(AMR_WIND_ENABLE_CUDA "Enable CUDA" OFF)
option(AMR_WIND_ENABLE_ROCM "Enable ROCm/HIP" OFF)
option(AMR_WIND_ENABLE_SYCL "Enable Intel OneAPI SyCL" OFF)
option(AMR_WIND_ENABLE_TINY_PROFILE "Enable AMReX TinyProfile support" OFF)
set(AMR_WIND_PRECISION "DOUBLE" CACHE STRING "Floating point precision SINGLE or DOUBLE")
# Third party libraries
option(AMR_WIND_USE_INTERNAL_AMREX "Add AMReX as subproject" ON)
option(AMR_WIND_USE_INTERNAL_AMREX_HYDRO "Add AMReX-Hydro as subproject" ON)
option(AMR_WIND_USE_INTERNAL_WAVES2AMR "Add Waves2AMR as subproject" ON)
option(AMR_WIND_ENABLE_HDF5 "Enable HDF5 library" OFF)
option(AMR_WIND_ENABLE_HDF5_ZFP "Enable ZFP compression in HDF5 library" OFF)
option(AMR_WIND_ENABLE_NETCDF "Enable NetCDF library" OFF)
option(AMR_WIND_ENABLE_MASA "Enable MASA library" OFF)
option(AMR_WIND_ENABLE_HELICS "Enable HELICS library" OFF)
option(AMR_WIND_ENABLE_HYPRE "Enable HYPRE integration" OFF)
option(AMR_WIND_ENABLE_OPENFAST "Enable OpenFAST integration" OFF)
option(AMR_WIND_ENABLE_ASCENT "Enable Ascent visualization library" OFF)
option(AMR_WIND_ENABLE_UMPIRE "Enable Umpire GPU memory pools" OFF)
option(AMR_WIND_ENABLE_W2A "Enable Waves2AMR library" OFF)
#Options for C++
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(AMR_WIND_ENABLE_CUDA)
enable_language(CUDA)
if(CMAKE_CUDA_COMPILER_VERSION VERSION_LESS "10.0")
message(FATAL_ERROR "Your nvcc version is ${CMAKE_CUDA_COMPILER_VERSION} which is unsupported."
"Please use CUDA toolkit version 10.0 or newer.")
endif()
endif()
if(AMR_WIND_ENABLE_ROCM)
find_package(HIP REQUIRED)
if(NOT DEFINED AMD_ARCH)
# Set default AMD architectures (based on Frontier)
set(AMD_ARCH "gfx90a")
endif()
endif()
if (AMR_WIND_ENABLE_UMPIRE)
set(CMAKE_PREFIX_PATH ${UMPIRE_DIR} ${CMAKE_PREFIX_PATH})
find_package(Umpire REQUIRED)
include_directories(SYSTEM ${UMPIRE_INCLUDE_DIRS})
endif()
if(AMR_WIND_TEST_WITH_FCOMPARE)
set(AMR_WIND_ENABLE_FCOMPARE ON)
endif()
if(CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
set(AMR_WIND_ENABLE_FPE_TRAP_FOR_TESTS OFF)
message(WARNING "Disabling FPE trapping for tests when using AppleClang.")
endif()
if(AMR_WIND_ENABLE_OPENFAST)
enable_language(Fortran)
endif()
########################### AMReX #####################################
init_amrex()
init_amrex_hydro()
########################## Waves2AMR ##################################
if (AMR_WIND_ENABLE_W2A)
# submodule for the code, not always compiled
init_waves2amr()
endif()
########################### AMR-Wind #####################################
# General information about machine, compiler, and build type
message(STATUS "AMR-Wind Information:")
message(STATUS "CMAKE_SYSTEM_NAME = ${CMAKE_SYSTEM_NAME}")
message(STATUS "CMAKE_CXX_COMPILER_ID = ${CMAKE_CXX_COMPILER_ID}")
message(STATUS "CMAKE_CXX_COMPILER_VERSION = ${CMAKE_CXX_COMPILER_VERSION}")
message(STATUS "CMAKE_BUILD_TYPE = ${CMAKE_BUILD_TYPE}")
include(set_rpath)
#Create target names
set(amr_wind_lib_name "amrwind_obj")
set(amr_wind_exe_name "amr_wind")
set(amr_wind_unit_test_exe_name "${amr_wind_exe_name}_unit_tests")
set(aw_api_lib "amrwind_api")
#Create main target executable
add_library(${amr_wind_lib_name} OBJECT)
add_library(${aw_api_lib})
add_executable(${amr_wind_exe_name})
init_code_checks()
if(CLANG_TIDY_EXE)
set_target_properties(${amr_wind_lib_name} ${aw_api_lib} ${amr_wind_exe_name}
PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_EXE};--config-file=${CMAKE_SOURCE_DIR}/.clang-tidy")
endif()
include(set_compile_flags)
if (AMR_WIND_ENABLE_W2A)
# Turn on the use of the library via bool, it has already been included above
target_compile_definitions(${amr_wind_lib_name} PUBLIC AMR_WIND_USE_W2A)
# Address FFTW dependencies
set(CMAKE_PREFIX_PATH ${FFTW_DIR} ${CMAKE_PREFIX_PATH})
include_directories(${FFTW_DIR}/include)
endif()
if(AMR_WIND_ENABLE_NETCDF)
set(CMAKE_PREFIX_PATH ${NETCDF_DIR} ${CMAKE_PREFIX_PATH})
find_package(NetCDF REQUIRED)
target_compile_definitions(${amr_wind_lib_name} PUBLIC AMR_WIND_USE_NETCDF)
target_link_libraries_system(${amr_wind_lib_name} PUBLIC NetCDF::NetCDF)
endif()
if(AMR_WIND_ENABLE_HDF5)
set(CMAKE_PREFIX_PATH ${HDF5_DIR} ${CMAKE_PREFIX_PATH})
target_compile_definitions(${amr_wind_lib_name} PUBLIC AMR_WIND_USE_HDF5)
endif()
if(AMR_WIND_ENABLE_HDF5_ZFP)
if(NOT AMR_WIND_ENABLE_HDF5)
message(FATAL_ERROR "HDF5 must be enabled to use ZFP compression in HDF5 plot files")
endif()
set(CMAKE_PREFIX_PATH ${H5Z_ZFP_DIR} ${CMAKE_PREFIX_PATH})
target_compile_definitions(${amr_wind_lib_name} PUBLIC AMR_WIND_USE_HDF5_ZFP)
endif()
if(AMR_WIND_ENABLE_MASA)
set(CMAKE_PREFIX_PATH ${MASA_DIR} ${CMAKE_PREFIX_PATH})
find_package(MASA REQUIRED)
target_compile_definitions(${amr_wind_lib_name} PUBLIC AMR_WIND_USE_MASA)
target_link_libraries(${amr_wind_lib_name} PUBLIC MASA::MASA)
endif()
if(AMR_WIND_ENABLE_OPENFAST)
set(CMAKE_PREFIX_PATH ${OPENFAST_DIR} ${CMAKE_PREFIX_PATH})
find_package(OpenFAST REQUIRED)
include(CheckIncludeFileCXX)
set(CMAKE_REQUIRED_INCLUDES "${OpenFAST_INCLUDE_DIRS}")
target_compile_definitions(${amr_wind_lib_name} PUBLIC AMR_WIND_USE_OPENFAST)
target_include_directories(${amr_wind_lib_name} PUBLIC ${OpenFAST_INCLUDE_DIRS})
target_link_libraries(${amr_wind_lib_name} PUBLIC ${OpenFAST_LIBRARIES})
endif()
if(AMR_WIND_ENABLE_ASCENT)
set(CMAKE_PREFIX_PATH ${ASCENT_DIR} ${CMAKE_PREFIX_PATH})
find_package(Ascent REQUIRED)
if(AMR_WIND_ENABLE_MPI)
target_link_libraries(${amr_wind_lib_name} PUBLIC ascent::ascent_mpi)
else()
target_link_libraries(${amr_wind_lib_name} PUBLIC ascent::ascent)
endif()
target_compile_definitions(${amr_wind_lib_name} PRIVATE AMR_WIND_USE_ASCENT)
endif()
# Link with HELICS module
if(AMR_WIND_ENABLE_HELICS)
set(CMAKE_PREFIX_PATH ${HELICS_DIR} ${CMAKE_PREFIX_PATH})
find_package(HELICS 3 REQUIRED)
target_include_directories(${amr_wind_lib_name} PUBLIC ${HELICS_INSTALL_DIR}/include)
target_link_libraries(${amr_wind_lib_name} PUBLIC HELICS::helicsCpp98)
target_compile_definitions(${amr_wind_lib_name} PRIVATE AMR_WIND_USE_HELICS)
endif()
if(AMR_WIND_TEST_WITH_PYTHON)
set(CMAKE_PREFIX_PATH ${PYTHON_DIR} ${CMAKE_PREFIX_PATH})
find_package(Python3 REQUIRED COMPONENTS Interpreter)
endif()
#Build amr-wind and link to amrex library
generate_version_info()
add_subdirectory(amr-wind)
if(AMR_WIND_ENABLE_CUDA)
set(awtargets "${amr_wind_lib_name};${amr_wind_exe_name}")
foreach(tgt IN LISTS awtargets)
set_cuda_build_properties(${tgt})
# get_target_property(AMR_WIND_SOURCES ${tgt} SOURCES)
# list(FILTER AMR_WIND_SOURCES INCLUDE REGEX "\\.cpp")
# set_source_files_properties(${AMR_WIND_SOURCES} PROPERTIES LANGUAGE CUDA)
endforeach()
endif()
if(AMR_WIND_ENABLE_UNIT_TESTS OR AMR_WIND_ENABLE_TESTS)
add_executable(${amr_wind_unit_test_exe_name})
if(CLANG_TIDY_EXE)
set_target_properties(${amr_wind_unit_test_exe_name}
PROPERTIES CXX_CLANG_TIDY "${CLANG_TIDY_EXE};--config-file=${CMAKE_SOURCE_DIR}/.clang-tidy")
endif()
add_subdirectory("submods/googletest")
add_subdirectory("unit_tests")
set_cuda_build_properties(${amr_wind_unit_test_exe_name})
# if(AMR_WIND_ENABLE_CUDA)
# get_target_property(UTEST_SOURCES ${amr_wind_unit_test_exe_name} SOURCES)
# set_source_files_properties(${UTEST_SOURCES} PROPERTIES LANGUAGE CUDA)
# set_target_properties(${amr_wind_unit_test_exe_name} PROPERTIES
# CUDA_SEPARABLE_COMPILATION ON)
# endif()
endif()
add_subdirectory(tools)
if(AMR_WIND_ENABLE_TESTS)
enable_testing()
include(CTest)
add_subdirectory(test)
endif()
if(AMR_WIND_ENABLE_DOCUMENTATION)
add_subdirectory(docs)
endif()
#Define what we want to be installed during a make install
install(
TARGETS ${amr_wind_exe_name}
${aw_api_lib} ${amr_wind_lib_name} buildInfo${amr_wind_lib_name}
EXPORT ${PROJECT_NAME}Targets
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib)
if(AMR_WIND_ENABLE_UNIT_TESTS OR AMR_WIND_ENABLE_TESTS)
install(
TARGETS ${amr_wind_unit_test_exe_name}
RUNTIME DESTINATION bin)
endif()
install(
DIRECTORY ${PROJECT_SOURCE_DIR}/amr-wind
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.H")
install(
EXPORT ${PROJECT_NAME}Targets
NAMESPACE ${PROJECT_NAME}::
DESTINATION lib/cmake/${PROJECT_NAME})
configure_package_config_file(
cmake/${PROJECT_NAME}Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
INSTALL_DESTINATION lib/cmake/${PROJECT_NAME})
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
DESTINATION lib/cmake/${PROJECT_NAME})
install(FILES
${PROJECT_SOURCE_DIR}/cmake/FindMASA.cmake
${PROJECT_SOURCE_DIR}/cmake/FindNetCDF.cmake
DESTINATION ${CMAKE_INSTALL_DATADIR}/cmake/Modules)