-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
198 lines (171 loc) · 7.3 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
############################ BASE ######################################
cmake_minimum_required (VERSION 3.14 FATAL_ERROR)
project(ERF-AMRWind CXX C)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/CMake")
include(CMakePackageConfigHelpers)
########################## OPTIONS #####################################
#General options for all executables in the project
set(ERF_HOME "${CMAKE_SOURCE_DIR}/../ERF" CACHE STRING "Path to ERF root directory")
set(AMRWIND_HOME "${CMAKE_SOURCE_DIR}/../amr-wind" CACHE STRING "Path to AMR-Wind root directory")
set(ERF_DIM "3" CACHE STRING "Number of physical dimensions")
option(ERF_ENABLE_DOCUMENTATION "Build documentation" OFF)
option(ERF_ENABLE_ALL_WARNINGS "Enable all compiler warnings" OFF)
option(ERF_ENABLE_TESTS "Enable regression and unit tests" OFF)
option(ERF_USE_INTERNAL_AMREX "Add AMReX as subproject" ON)
option(DRIVER_USE_INTERNAL_AMRWIND "Use AMRWIND_HOME to install files directly" ON)
option(DRIVER_USE_INTERNAL_ERF "Use ERF_HOME to install files directly" ON)
option(ERF_ENABLE_NETCDF "Enable NetCDF IO" OFF)
option(ERF_ENABLE_HDF5 "Enable HDF5 IO" ${ERF_ENABLE_NETCDF})
option(ERF_ENABLE_FCOMPARE "Enable building fcompare when not testing" OFF)
set(ERF_PRECISION "DOUBLE" CACHE STRING "Floating point precision SINGLE or DOUBLE")
option(ERF_ENABLE_MOISTURE "Enable Full Moisture" OFF)
option(ERF_ENABLE_WARM_NO_PRECIP "Enable Warm Moisture" OFF)
option(ERF_ENABLE_RRTMGP "Enable RTE-RRTMGP Radiation" OFF)
option(ERF_ENABLE_MULTIBLOCK "Enable MutliBlock code" ON)
#Options for performance
option(ERF_ENABLE_MPI "Enable MPI" OFF)
option(ERF_ENABLE_OPENMP "Enable OpenMP" OFF)
option(ERF_ENABLE_CUDA "Enable CUDA" OFF)
option(ERF_ENABLE_HIP "Enable HIP" OFF)
option(ERF_ENABLE_SYCL "Enable SYCL" OFF)
#Options for C++
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(ERF_ENABLE_CUDA)
enable_language(CUDA)
if(CMAKE_CUDA_COMPILER_VERSION VERSION_LESS "11.0")
message(FATAL_ERROR "Your nvcc version is ${CMAKE_CUDA_COMPILER_VERSION} which is unsupported."
"Please use CUDA toolkit version 11.0 or newer.")
endif()
endif()
if(NOT ERF_DIM EQUAL 3)
message(FATAL_ERROR "ERF is only supported in 3D.")
endif()
# Configure measuring code coverage in tests
option(CODECOVERAGE "Enable code coverage profiling" OFF)
if(CODECOVERAGE)
# Only supports GNU
if(NOT CMAKE_CXX_COMPILER_ID MATCHES GNU)
message(WARNING "CODECOVERAGE is only support with GNU Compilers. The current C++ compiler is ${CMAKE_CXX_COMPILER_ID}")
endif()
if(NOT CMAKE_C_COMPILER_ID MATCHES GNU)
message(WARNING "CODECOVERAGE is only support with GNU Compilers. The current C compiler is ${CMAKE_C_COMPILER_ID}")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --coverage")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} --coverage")
endif()
########################### AMReX and Hydro #####################################
set(AMREX_SUBMOD_LOCATION "${ERF_HOME}/Submodules/AMReX")
include(${CMAKE_SOURCE_DIR}/CMake/SetAmrexOptions.cmake)
list(APPEND CMAKE_MODULE_PATH "${AMREX_SUBMOD_LOCATION}/Tools/CMake")
set(AMREX_HYDRO_SUBMOD_LOCATION "${AMRWIND_HOME}/submods/AMReX-Hydro")
include(${CMAKE_SOURCE_DIR}/CMake/set_amrex_hydro_options.cmake)
list(APPEND CMAKE_MODULE_PATH "${AMREX_HYDRO_SUBMOD_LOCATION}/Tools/CMake")
########################### AMReX and Hydro #####################################
if (${ERF_USE_INTERNAL_AMREX})
add_subdirectory(${AMREX_SUBMOD_LOCATION} amrex)
else()
set(CMAKE_PREFIX_PATH ${AMREX_DIR} ${CMAKE_PREFIX_PATH})
list(APPEND AMREX_COMPONENTS
"3D" "PIC" "PARTICLES" "PDOUBLE" "DOUBLE" "LSOLVERS")
if (ERF_ENABLE_MPI)
list(APPEND AMREX_COMPONENTS "MPI")
endif()
if (ERF_ENABLE_OPENMP)
list(APPEND AMREX_COMPONENTS "OMP")
endif()
if (ERF_ENABLE_CUDA)
list(APPEND AMREX_COMPONENTS "CUDA")
endif()
if (ERF_ENABLE_SYCL)
list(APPEND AMREX_COMPONENTS "SYCL")
endif()
if (ERF_ENABLE_ROCM)
list(APPEND AMREX_COMPONENTS "HIP")
endif()
if (ERF_ENABLE_HYPRE)
list(APPEND AMREX_COMPONENTS "HYPRE")
endif()
if (ERF_ENABLE_TINY_PROFILE)
list(APPEND AMREX_COMPONENTS "TINY_PROFILE")
endif()
separate_arguments(AMREX_COMPONENTS)
find_package(AMReX CONFIG REQUIRED
COMPONENTS ${AMREX_COMPONENTS})
message(STATUS "Found AMReX = ${AMReX_DIR}")
set(FCOMPARE_EXE ${AMReX_DIR}/../../../bin/amrex_fcompare
CACHE INTERNAL "Path to fcompare executable for regression tests")
endif()
if (${AMRWIND_USE_INTERNAL_AMREX_HYDRO})
add_subdirectory(${AMREX_HYDRO_SUBMOD_LOCATION} amrex-hydro)
else()
find_package(AMReX-Hydro CONFIG REQUIRED)
message(STATUS "Found AMReX-Hydro = ${AMReX-Hydro_DIR}")
endif()
########################## NETCDF ##################################
if(ERF_ENABLE_NETCDF)
set(CMAKE_PREFIX_PATH ${NETCDF_DIR} ${CMAKE_PREFIX_PATH})
## set(NETCDF_CXX "YES")
find_package (NetCDF REQUIRED)
if(NETCDF_FOUND)
message(STATUS "Found NetCDF, NETCDF_DIR = ${NETCDF_DIR}")
endif()
endif()
########################### RRTMGP #################################
if(ERF_ENABLE_RRTMGP)
message(STATUS "Building RRTMGP/YAKL...")
# YAKL_ARCH can be CUDA, HIP, SYCL, OPENMP45, or empty
if(ERF_ENABLE_CUDA)
set(YAKL_ARCH "CUDA")
# CUDA_FLAGS is set the same as ERF_CUDA_FLAGS
string(APPEND YAKL_CUDA_FLAGS " -arch sm_70")
if(ENABLE_CUDA_FASTMATH)
string(APPEND YAKL_CUDA_FLAGS " --use_fast_math")
endif()
set_cuda_architectures(AMReX_CUDA_ARCH)
elseif(ERF_ENABLE_SYCL)
set(YAKL_ARCH "SYCL")
# SYCL_FLAGS is set through Macros.cmake / config_compilers.xml
string(APPEND YAKL_SYCL_FLAGS " -fsycl")
elseif(ERF_ENABLE_HIP)
set(YAKL_ARCH "HIP")
# SYCL_FLAGS is set through Macros.cmake / config_compilers.xml
string(APPEND YAKL_HIP_FLAGS " -D__HIP_ROCclr__ -D__HIP_ARCH_GFX90A__=1 --rocm-path=${ROCM_PATH} --offload-arch=gfx90a -x hip")
else()
# For CPU C++ compilers duplicate flags are fine, the last ones win typically
set(YAKL_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(YAKL_ARCH "")
endif()
# Build YAKL as a static library
# YAKL_HOME is YAKL's source directlry
set(YAKL_HOME ${CMAKE_SOURCE_DIR}/Submodules/YAKL)
# YAKL_BIN is where we're placing the YAKL library
set(YAKL_BIN ${CMAKE_BINARY_DIR}/yakl)
# Build the YAKL static library
add_subdirectory(${YAKL_HOME} ${YAKL_BIN})
# Build the static rrtmgp library
set(RRTMGP_BIN ${CMAKE_BINARY_DIR}/rrtmgp)
add_subdirectory(${CMAKE_SOURCE_DIR}/Submodules/RRTMGP/cpp ${RRTMGP_BIN})
endif()
########################### ERF #####################################
if(ERF_ENABLE_MPI)
find_package(MPI REQUIRED)
endif()
# General information about machine, compiler, and build type
message(STATUS "ERF 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}")
# Turn on rpath stuff
include(${CMAKE_SOURCE_DIR}/CMake/SetRpath.cmake)
#Build erf executables and intermediate object library and link to amrex library
add_subdirectory(Exec)
if(ERF_ENABLE_TESTS)
include(CTest)
add_subdirectory(Tests)
endif()
if(ERF_ENABLE_DOCUMENTATION)
add_subdirectory(Docs)
endif()