-
Notifications
You must be signed in to change notification settings - Fork 7
/
CMakeLists.txt
256 lines (217 loc) · 9.69 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
cmake_minimum_required(VERSION 3.18)
# CMake version compatibility
#[==============================================================================[
# Basic project definition #
#]==============================================================================]
project(ACCESS-OM3 VERSION "0.2.0"
HOMEPAGE_URL https://github.com/COSIMA/access-om3
DESCRIPTION "Global coupled ocean - sea ice - wave model"
LANGUAGES C Fortran)
#[==============================================================================[
# Options #
#]==============================================================================]
# Configurations to build
list(APPEND KnownConfigurations MOM6 CICE6 WW3 MOM6-CICE6 CICE6-WW3 MOM6-WW3 MOM6-CICE6-WW3)
option(OM3_ENABLE_MOM6 "Build MOM6 configuration" OFF)
option(OM3_ENABLE_CICE6 "Build CICE6 configuration" OFF)
option(OM3_ENABLE_WW3 "Build WW3 configuration" OFF)
option(OM3_ENABLE_MOM6-WW3 "Build MOM6-WW3 configuration" OFF)
option(OM3_ENABLE_MOM6-CICE6 "Build MOM6-CICE6 configuration" ON)
option(OM3_ENABLE_CICE6-WW3 "Build CICE6-WW3 configuration" ON)
option(OM3_ENABLE_MOM6-CICE6-WW3 "Build MOM6-CICE6-WW3 configuration" ON)
message(STATUS "Configurations")
message(STATUS " - MOM6 ${OM3_ENABLE_MOM6}")
message(STATUS " - CICE6 ${OM3_ENABLE_CICE6}")
message(STATUS " - WW3 ${OM3_ENABLE_WW3}")
message(STATUS " - MOM6-WW3 ${OM3_ENABLE_MOM6-WW3}")
message(STATUS " - MOM6-CICE6 ${OM3_ENABLE_MOM6-CICE6}")
message(STATUS " - CICE6-WW3 ${OM3_ENABLE_CICE6-WW3}")
message(STATUS " - MOM6-CICE6-WW3 ${OM3_ENABLE_MOM6-CICE6-WW3}")
# Build options
option(OM3_BIN_INSTALL "Instal ACCESS-OM3 executables" ${PROJECT_IS_TOP_LEVEL})
option(OM3_LIB_INSTALL "Instal ACCESS-OM3 libraries" OFF)
option(OM3_OPENMP "Enable OpenMP threading" OFF)
option(OM3_MOM_SYMMETRIC "Use symmetric memory" OFF)
set(OM3_CICE_IO "PIO" CACHE STRING "CICE OPTIONS: Choose IO options.")
set_property(CACHE OM3_CICE_IO PROPERTY STRINGS "NetCDF" "PIO" "Binary")
message(STATUS "Build options")
message(STATUS " - OM3_BIN_INSTALL ${OM3_BIN_INSTALL}")
message(STATUS " - OM3_LIB_INSTALL ${OM3_LIB_INSTALL}")
message(STATUS " - OM3_OPENMP ${OM3_OPENMP}")
message(STATUS " - OM3_MOM_SYMMETRIC ${OM3_MOM_SYMMETRIC}")
message(STATUS " - OM3_CICE_IO ${OM3_CICE_IO}")
#[==============================================================================[
# Project configuration #
#]==============================================================================]
list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
include(GNUInstallDirs)
if(OM3_LIB_INSTALL)
include(CMakePackageConfigHelpers)
endif()
# Include some custom cmake modules
include(FortranLib)
include(AddPatchedSource)
## Configure project variables
# Do not build components that are not going to be used
if(OM3_ENABLE_MOM6 OR OM3_ENABLE_MOM6-CICE6 OR OM3_ENABLE_MOM6-WW3 OR OM3_ENABLE_MOM6-CICE6-WW3)
set(OM3_BUILD_MOM6 ON)
else()
set(OM3_BUILD_MOM6 OFF)
endif()
if(OM3_ENABLE_CICE6 OR OM3_ENABLE_MOM6-CICE6 OR OM3_ENABLE_CICE6-WW3 OR OM3_ENABLE_MOM6-CICE6-WW3)
set(OM3_BUILD_CICE6 ON)
else()
set(OM3_BUILD_CICE6 OFF)
endif()
if(OM3_ENABLE_WW3 OR OM3_ENABLE_MOM6-WW3 OR OM3_ENABLE_CICE6-WW3 OR OM3_ENABLE_MOM6-CICE6-WW3)
set(OM3_BUILD_WW3 ON)
else()
set(OM3_BUILD_WW3 OFF)
endif()
message(STATUS "Components to build")
message(STATUS " - OM3_BUILD_MOM6 ${OM3_BUILD_MOM6}")
message(STATUS " - OM3_BUILD_CICE6 ${OM3_BUILD_CICE6}")
message(STATUS " - OM3_BUILD_WW3 ${OM3_BUILD_WW3}")
# Common compiler flags and definitions
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fbacktrace -fconvert=big-endian -ffree-line-length-none -ffixed-line-length-none")
if(${CMAKE_Fortran_COMPILER_VERSION} VERSION_GREATER_EQUAL 10)
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fallow-argument-mismatch")
endif()
set(CMAKE_Fortran_FLAGS_RELEASE "-O")
set(CMAKE_Fortran_FLAGS_DEBUG "-g -Wall -Og -ffpe-trap=zero,overflow -fcheck=bounds")
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -qno-opt-dynamic-align -convert big_endian -assume byterecl -ftz -traceback -assume realloc_lhs -fp-model source")
set(CMAKE_Fortran_FLAGS_RELEASE "-O2 -debug minimal")
set(CMAKE_Fortran_FLAGS_DEBUG "-O0 -g -check uninit -check bounds -check pointers -fpe0 -check noarg_temp_created")
else()
message(WARNING "Fortran compiler with ID ${CMAKE_Fortran_COMPILER_ID} will be used with CMake default options")
endif()
if(CMAKE_C_COMPILER_ID MATCHES "GNU")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
set(CMAKE_C_FLAGS_RELEASE "-O")
set(CMAKE_C_FLAGS_DEBUG "-g -Wall -Og -fbacktrace -ffpe-trap=invalid,zero,overflow -fcheck=bounds")
elseif(CMAKE_C_COMPILER_ID MATCHES "Intel")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -traceback -qno-opt-dynamic-align -fp-model precise -std=gnu99")
set(CMAKE_C_FLAGS_RELEASE "-O2 -debug minimal")
set(CMAKE_C_FLAGS_DEBUG "-O0 -g")
else()
message(WARNING "C compiler with ID ${CMAKE_C_COMPILER_ID} will be used with CMake default options")
endif()
add_compile_definitions(
CESMCOUPLED
)
## Fortran modules path; currently this is simply set to be the include dir
set(CMAKE_INSTALL_MODULEDIR ${CMAKE_INSTALL_INCLUDEDIR}
CACHE STRING
"Fortran module installation path (Not a cmake native variable)"
)
#[==============================================================================[
# External packages #
#]==============================================================================]
# Find dependencies
find_package(MPI REQUIRED)
if(OM3_OPENMP)
find_package(OpenMP REQUIRED)
endif()
find_package(FoX 4.1.2 REQUIRED)
find_package(NetCDF 4.7.3 REQUIRED Fortran)
find_package(ESMF 8.3.0 MODULE REQUIRED)
find_package(fms COMPONENTS R8 REQUIRED)
find_package(PIO 2.5.3 REQUIRED COMPONENTS C Fortran)
#[==============================================================================[
# Main definitions #
#]==============================================================================]
# Some code shared by several components
add_subdirectory(share)
## Components
# Data component (CDEPS)
add_subdirectory(CDEPS)
# Ocean component (MOM6)
if(OM3_BUILD_MOM6)
add_subdirectory(MOM6)
endif()
# Sea-ice component (CICE6)
if(OM3_BUILD_CICE6)
add_subdirectory(CICE)
endif()
# Wave component (WW3)
if(OM3_BUILD_WW3)
add_subdirectory(WW3)
endif()
# Mediator component (CMEPS)
add_subdirectory(CMEPS)
# Add executable for each enabled configuration
foreach(CONF IN LISTS KnownConfigurations)
if(NOT OM3_ENABLE_${CONF})
continue()
endif()
set(ComponentsTargets "")
if(OM3_${CONF} MATCHES MOM6)
list(APPEND ComponentsTargets AccessOM3::mom6)
else()
list(APPEND ComponentsTargets AccessOM3::cdeps_docn)
endif()
if(OM3_${CONF} MATCHES CICE6)
list(APPEND ComponentsTargets AccessOM3::cice)
else()
list(APPEND ComponentsTargets AccessOM3::cdeps_dice)
endif()
if(OM3_${CONF} MATCHES WW3)
list(APPEND ComponentsTargets AccessOM3::ww3)
else()
list(APPEND ComponentsTargets AccessOM3::cdeps_dwav)
endif()
# We use the CESM driver from CMEPS
add_fortran_library(OM3_cesm_driver_${CONF} mod/OM3_cesm_driver_${CONF} STATIC
CMEPS/CMEPS/cesm/driver/esm.F90
CMEPS/CMEPS/cesm/driver/ensemble_driver.F90
CMEPS/CMEPS/cesm/driver/esm_time_mod.F90
)
target_link_libraries(OM3_cesm_driver_${CONF}
PUBLIC esmf
PRIVATE ${ComponentsTargets} AccessOM3::cdeps_drof AccessOM3::cdeps_datm AccessOM3::cmeps AccessOM3::nuopc_cap_share AccessOM3::share AccessOM3::timing
)
target_compile_definitions(OM3_cesm_driver_${CONF} PRIVATE MED_PRESENT
ATM_PRESENT
ICE_PRESENT
OCN_PRESENT
WAV_PRESENT
ROF_PRESENT
$<$<CONFIG:Debug>:DEBUG>
)
add_executable(OM3_${CONF} CMEPS/CMEPS/cesm/driver/esmApp.F90)
target_link_libraries(OM3_${CONF} PRIVATE OM3_cesm_driver_${CONF} AccessOM3::share esmf)
set_target_properties(OM3_${CONF} PROPERTIES
LINKER_LANGUAGE Fortran
OUTPUT_NAME access-om3-${CONF}
)
endforeach()
#[==============================================================================[
# Install or Export #
#]==============================================================================]
## Installs
# Note that the installation of some components is done in the corresponding subdirectory
# OM3 executables
if(OM3_BIN_INSTALL)
foreach(CONF IN LISTS KnownConfigurations)
if(NOT OM3_ENABLE_${CONF})
continue()
endif()
install(TARGETS OM3_${CONF}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
endforeach()
endif()
# Libraries
if(OM3_LIB_INSTALL)
configure_package_config_file(
cmake/AccessOM3Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/AccessOM3Config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/AccessOM3
)
install(FILES ${CMAKE_SOURCE_DIR}/cmake/FindFoX.cmake ${CMAKE_CURRENT_BINARY_DIR}/AccessOM3Config.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/AccessOM3
COMPONENT AccessOM3_Development
)
endif()