1
- # Set default project to unknown
2
- if (NOT PROJECT)
3
- message (STATUS "Setting CCPP project to 'unknown' as none was specified." )
4
- set (PROJECT "Unknown" )
5
- endif (NOT PROJECT)
6
-
7
- #------------------------------------------------------------------------------
8
- cmake_minimum_required (VERSION 3.0)
1
+ cmake_minimum_required (VERSION 3.3)
9
2
10
3
project (ccpp_physics
11
4
VERSION 5.0.0
12
5
LANGUAGES Fortran)
13
6
14
- # Use rpaths on MacOSX
15
- set (CMAKE_MACOSX_RPATH 1)
16
- if (POLICY CMP0042)
17
- cmake_policy (SET CMP0042 NEW)
18
- endif (POLICY CMP0042)
19
-
20
- # CMP0057: Support new IN_LIST if() operator
21
- if (POLICY CMP0057)
22
- cmake_policy (SET CMP0057 NEW)
23
- endif (POLICY CMP0057)
24
-
25
7
#------------------------------------------------------------------------------
26
8
set (PACKAGE "ccpp-physics" )
27
9
set (AUTHORS "Grant Firl" "Dom Heinzeller" "Man Zhang" "Laurie Carson" )
28
10
29
11
#------------------------------------------------------------------------------
30
12
# Set OpenMP flags for C/C++/Fortran
31
13
if (OPENMP)
32
- include (detect_openmp)
33
- detect_openmp()
34
- message (STATUS "Enable OpenMP support" )
35
- else (OPENMP)
36
- message (STATUS "Disable OpenMP support" )
14
+ find_package (OpenMP REQUIRED)
37
15
endif ()
38
16
39
17
#------------------------------------------------------------------------------
40
18
# Set a default build type if none was specified
41
19
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES )
42
20
message (STATUS "Setting build type to 'Release' as none was specified." )
43
21
set (CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE)
44
-
45
22
# Set the possible values of build type for cmake-gui
46
23
set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Bitforbit" "Release" "Coverage" )
47
24
endif ()
48
25
26
+ #------------------------------------------------------------------------------
27
+ # Pass debug/release flag to Fortran files for preprocessor
28
+ if (CMAKE_BUILD_TYPE STREQUAL "Debug" )
29
+ add_definitions (-DDEBUG)
30
+ endif ()
31
+
49
32
#------------------------------------------------------------------------------
50
33
# Request a static build
51
34
option (BUILD_SHARED_LIBS "Build a shared library" OFF )
@@ -54,10 +37,10 @@ option(BUILD_SHARED_LIBS "Build a shared library" OFF)
54
37
# Set the sources: physics type definitions
55
38
set (TYPEDEFS $ENV{CCPP_TYPEDEFS} )
56
39
if (TYPEDEFS)
57
- message (STATUS "Got CCPP TYPEDEFS from environment variable: ${TYPEDEFS} " )
40
+ message (STATUS "Got CCPP TYPEDEFS from environment variable" )
58
41
else (TYPEDEFS)
59
42
include (${CMAKE_CURRENT_BINARY_DIR} /CCPP_TYPEDEFS.cmake)
60
- message (STATUS "Got CCPP TYPEDEFS from cmakefile include file: ${TYPEDEFS} " )
43
+ message (STATUS "Got CCPP TYPEDEFS from cmakefile include file" )
61
44
endif (TYPEDEFS)
62
45
63
46
# Generate list of Fortran modules from the CCPP type
@@ -70,33 +53,28 @@ endforeach()
70
53
# Set the sources: physics schemes
71
54
set (SCHEMES $ENV{CCPP_SCHEMES} )
72
55
if (SCHEMES)
73
- message (STATUS "Got CCPP SCHEMES from environment variable: ${SCHEMES} " )
56
+ message (STATUS "Got CCPP SCHEMES from environment variable" )
74
57
else (SCHEMES)
75
58
include (${CMAKE_CURRENT_BINARY_DIR} /CCPP_SCHEMES.cmake)
76
- message (STATUS "Got CCPP SCHEMES from cmakefile include file: ${SCHEMES} " )
59
+ message (STATUS "Got CCPP SCHEMES from cmakefile include file" )
77
60
endif (SCHEMES)
78
61
79
62
# Set the sources: physics scheme caps
80
63
set (CAPS $ENV{CCPP_CAPS} )
81
64
if (CAPS)
82
- message (STATUS "Got CCPP CAPS from environment variable: ${CAPS} " )
65
+ message (STATUS "Got CCPP CAPS from environment variable" )
83
66
else (CAPS)
84
67
include (${CMAKE_CURRENT_BINARY_DIR} /CCPP_CAPS.cmake)
85
- message (STATUS "Got CCPP CAPS from cmakefile include file: ${CAPS} " )
68
+ message (STATUS "Got CCPP CAPS from cmakefile include file" )
86
69
endif (CAPS)
87
70
88
- # Create empty lists for schemes with special compiler optimization flags
89
- set (SCHEMES_SFX_OPT "" )
90
- # Create empty lists for schemes with special floating point precision flags
91
- set (SCHEMES_SFX_PREC "" )
92
- # Create a duplicate of the SCHEMES list for handling floating point precision flags
93
- set (SCHEMES2 ${SCHEMES} )
94
-
95
71
# Schemes and caps from the CCPP code generator use full paths with symlinks
96
72
# resolved, we need to do the same here for the below logic to work
97
73
get_filename_component (FULL_PATH_TO_CMAKELISTS CMakeLists.txt REALPATH BASE_DIR ${LOCAL_CURRENT_SOURCE_DIR} )
98
74
get_filename_component (LOCAL_CURRENT_SOURCE_DIR ${FULL_PATH_TO_CMAKELISTS} DIRECTORY )
99
75
76
+ #------------------------------------------------------------------------------
77
+
100
78
# List of files that need to be compiled without OpenMP
101
79
set (SCHEMES_OPENMP_OFF ${LOCAL_CURRENT_SOURCE_DIR} /physics/rte-rrtmgp/rrtmgp/mo_gas_optics.F90
102
80
${LOCAL_CURRENT_SOURCE_DIR} /physics/rte-rrtmgp/rrtmgp/mo_rrtmgp_constants.F90
@@ -110,7 +88,6 @@ set(SCHEMES_OPENMP_OFF ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rrtmgp/mo_
110
88
${LOCAL_CURRENT_SOURCE_DIR} /physics/rte-rrtmgp/tests/mo_testing_io.F90
111
89
${LOCAL_CURRENT_SOURCE_DIR} /physics/rte-rrtmgp/tests/clear_sky_regression.F90
112
90
${LOCAL_CURRENT_SOURCE_DIR} /physics/rte-rrtmgp/extensions/mo_rrtmgp_clr_all_sky.F90
113
- ${LOCAL_CURRENT_SOURCE_DIR} /physics/rte-rrtmgp/extensions/mo_fluxes_byband_kernels.F90
114
91
${LOCAL_CURRENT_SOURCE_DIR} /physics/rte-rrtmgp/extensions/mo_fluxes_byband.F90
115
92
${LOCAL_CURRENT_SOURCE_DIR} /physics/rte-rrtmgp/extensions/solar_variability/mo_solar_variability.F90
116
93
${LOCAL_CURRENT_SOURCE_DIR} /physics/rte-rrtmgp/extensions/mo_heating_rates.F90
@@ -140,113 +117,52 @@ set(SCHEMES_OPENMP_OFF ${LOCAL_CURRENT_SOURCE_DIR}/physics/rte-rrtmgp/rrtmgp/mo_
140
117
${LOCAL_CURRENT_SOURCE_DIR} /physics/rte-rrtmgp/rte/mo_rte_kind.F90
141
118
${LOCAL_CURRENT_SOURCE_DIR} /physics/rte-rrtmgp/rte/mo_optical_props.F90)
142
119
143
- #------------------------------------------------------------------------------
144
- if (${CMAKE_Fortran_COMPILER_ID} STREQUAL "GNU" )
145
-
146
- if (PROJECT STREQUAL "CCPP-FV3" )
147
- # Set 32-bit floating point precision flags for certain files
148
- # that are executed in the dynamics (fast physics part)
149
- if (DYN32)
150
- if (${LOCAL_CURRENT_SOURCE_DIR} /physics/gfdl_fv_sat_adj.F90 IN_LIST SCHEMES)
151
- # Reduce floating point precision from 64-bit to 32-bit, if necessary
152
- set (CMAKE_Fortran_FLAGS_PREC32 ${CMAKE_Fortran_FLAGS_DEFAULT_PREC} )
153
- string (REPLACE "-fdefault-real-8" ""
154
- CMAKE_Fortran_FLAGS_PREC32 "${CMAKE_Fortran_FLAGS_PREC32} " )
155
- string (REPLACE "-fdefault-double-8" ""
156
- CMAKE_Fortran_FLAGS_PREC32 "${CMAKE_Fortran_FLAGS_PREC32} " )
157
- SET_PROPERTY (SOURCE ${LOCAL_CURRENT_SOURCE_DIR} /physics/gfdl_fv_sat_adj.F90
158
- APPEND_STRING PROPERTY COMPILE_FLAGS " ${CMAKE_Fortran_FLAGS_PREC32} ${OpenMP_Fortran_FLAGS} " )
159
- # Add all of the above files to the list of schemes with special floating point precision flags
160
- list (APPEND SCHEMES_SFX_PREC ${LOCAL_CURRENT_SOURCE_DIR} /physics/gfdl_fv_sat_adj.F90)
161
- endif ()
162
- endif ()
120
+ # List of files that need to be compiled with different precision
121
+ set (SCHEMES_DYNAMICS)
163
122
164
- # Remove files with special floating point precision flags from list
165
- # of files with standard floating point precision flags
166
- if (SCHEMES_SFX_PREC)
167
- list (REMOVE_ITEM SCHEMES2 ${SCHEMES_SFX_PREC} )
168
- endif ()
169
-
170
- if (PROJECT STREQUAL "CCPP-FV3" )
171
- # Remove files that need to be compiled without OpenMP from list
172
- # of files with standard compiler flags, and assign no-OpenMP flags
173
- if (SCHEMES_OPENMP_OFF)
174
- list (REMOVE_ITEM SCHEMES2 ${SCHEMES_OPENMP_OFF} )
175
- endif ()
176
- # Assign standard floating point precision flags to all remaining schemes and caps
177
- SET_PROPERTY (SOURCE ${SCHEMES_OPENMP_OFF}
178
- APPEND_STRING PROPERTY COMPILE_FLAGS " ${CMAKE_Fortran_FLAGS_DEFAULT_PREC} " )
179
- endif ()
180
-
181
- # Assign standard floating point precision flags to all remaining schemes and caps
182
- SET_PROPERTY (SOURCE ${SCHEMES2} ${CAPS}
183
- APPEND_STRING PROPERTY COMPILE_FLAGS " ${CMAKE_Fortran_FLAGS_DEFAULT_PREC} ${OpenMP_Fortran_FLAGS} " )
184
-
185
- endif (PROJECT STREQUAL "CCPP-FV3" )
186
-
187
- elseif (${CMAKE_Fortran_COMPILER_ID} STREQUAL "Intel" )
188
- # Adjust settings for bit-for-bit reproducibility of NEMSfv3gfs
189
- if (PROJECT STREQUAL "CCPP-FV3" )
190
-
191
- if (${LOCAL_CURRENT_SOURCE_DIR} /physics/module_sf_mynn.F90 IN_LIST SCHEMES)
192
- # Reduce optimization for module_sf_mynn.F90 (to avoid an apparent compiler bug with Intel 18 on Hera)
193
- SET_SOURCE_FILES_PROPERTIES (${LOCAL_CURRENT_SOURCE_DIR} /physics/module_sf_mynn.F90
194
- PROPERTIES COMPILE_FLAGS "${CMAKE_Fortran_FLAGS_OPT} -O1" )
195
- list (APPEND SCHEMES_SFX_OPT ${LOCAL_CURRENT_SOURCE_DIR} /physics/module_sf_mynn.F90)
196
- endif ()
197
-
198
- # Remove files with special compiler flags from list of files with standard compiler flags
199
- if (SCHEMES_SFX_OPT)
200
- list (REMOVE_ITEM SCHEMES ${SCHEMES_SFX_OPT} )
201
- endif (SCHEMES_SFX_OPT)
202
- # Assign standard compiler flags to all remaining schemes and caps
203
- SET_SOURCE_FILES_PROPERTIES (${SCHEMES} ${CAPS}
204
- PROPERTIES COMPILE_FLAGS "${CMAKE_Fortran_FLAGS_OPT} " )
205
-
206
- # Set 32-bit floating point precision flags for certain files
207
- # that are executed in the dynamics (fast physics part)
208
- if (DYN32)
209
- if (${LOCAL_CURRENT_SOURCE_DIR} /physics/gfdl_fv_sat_adj.F90 IN_LIST SCHEMES)
210
- # Reduce floating point precision from 64-bit to 32-bit, if necessary
211
- set (CMAKE_Fortran_FLAGS_PREC32 ${CMAKE_Fortran_FLAGS_DEFAULT_PREC} )
212
- string (REPLACE "-real-size 64" "-real-size 32"
213
- CMAKE_Fortran_FLAGS_PREC32 "${CMAKE_Fortran_FLAGS_PREC32} " )
214
- SET_PROPERTY (SOURCE ${LOCAL_CURRENT_SOURCE_DIR} /physics/gfdl_fv_sat_adj.F90
215
- APPEND_STRING PROPERTY COMPILE_FLAGS " ${CMAKE_Fortran_FLAGS_PREC32} ${OpenMP_Fortran_FLAGS} " )
216
- # Add all of the above files to the list of schemes with special floating point precision flags
217
- list (APPEND SCHEMES_SFX_PREC ${LOCAL_CURRENT_SOURCE_DIR} /physics/gfdl_fv_sat_adj.F90)
218
- endif ()
219
- endif ()
123
+ if (${LOCAL_CURRENT_SOURCE_DIR} /physics/gfdl_fv_sat_adj.F90 IN_LIST SCHEMES)
124
+ list (APPEND SCHEMES_DYNAMICS ${LOCAL_CURRENT_SOURCE_DIR} /physics/gfdl_fv_sat_adj.F90)
125
+ endif ()
220
126
221
- # Remove files with special floating point precision flags from list
222
- # of files with standard floating point precision flags flags
223
- if (SCHEMES_SFX_PREC)
224
- list (REMOVE_ITEM SCHEMES2 ${SCHEMES_SFX_PREC} )
225
- endif (SCHEMES_SFX_PREC)
127
+ # Remove files that need to be compiled with different precision
128
+ # of files with standard compiler flags, and assign OpenMP flags
129
+ if (SCHEMES_DYNAMICS)
130
+ SET_PROPERTY (SOURCE ${SCHEMES_DYNAMICS}
131
+ APPEND_STRING PROPERTY COMPILE_FLAGS " ${CMAKE_Fortran_FLAGS_DYNAMICS} ${OpenMP_Fortran_FLAGS} " )
132
+ list (REMOVE_ITEM SCHEMES ${SCHEMES_DYNAMICS} )
133
+ endif ()
226
134
227
- # Remove files that need to be compiled without OpenMP from list
228
- # of files with standard compiler flags, and assign no-OpenMP flags
229
- if (SCHEMES_OPENMP_OFF)
230
- list (REMOVE_ITEM SCHEMES2 ${SCHEMES_OPENMP_OFF} )
231
- # Assign standard floating point precision flags to all remaining schemes and caps
232
- SET_PROPERTY (SOURCE ${SCHEMES_OPENMP_OFF}
233
- APPEND_STRING PROPERTY COMPILE_FLAGS " ${CMAKE_Fortran_FLAGS_DEFAULT_PREC} " )
234
- endif ()
135
+ # Remove files that need to be compiled without OpenMP from list
136
+ # of files with standard compiler flags, and assign no-OpenMP flags
137
+ if (SCHEMES_OPENMP_OFF)
138
+ SET_PROPERTY (SOURCE ${SCHEMES_OPENMP_OFF}
139
+ APPEND_STRING PROPERTY COMPILE_FLAGS " ${CMAKE_Fortran_FLAGS_PHYSICS} " )
140
+ list (REMOVE_ITEM SCHEMES ${SCHEMES_OPENMP_OFF} )
141
+ endif ()
235
142
236
- # Assign standard floating point precision flags to all remaining schemes and caps
237
- SET_PROPERTY (SOURCE ${SCHEMES2 } ${CAPS}
238
- APPEND_STRING PROPERTY COMPILE_FLAGS " ${CMAKE_Fortran_FLAGS_DEFAULT_PREC } ${OpenMP_Fortran_FLAGS} " )
143
+ # Assign standard floating point precision flags to all remaining schemes and caps
144
+ SET_PROPERTY (SOURCE ${SCHEMES } ${CAPS}
145
+ APPEND_STRING PROPERTY COMPILE_FLAGS " ${CMAKE_Fortran_FLAGS_PHYSICS } ${OpenMP_Fortran_FLAGS} " )
239
146
240
- endif (PROJECT STREQUAL "CCPP-FV3" )
147
+ # Reduce optimization for module_sf_mynn.F90 (to avoid an apparent compiler bug with Intel 18 on Hera)
148
+ if (${LOCAL_CURRENT_SOURCE_DIR} /physics/module_sf_mynn.F90 IN_LIST SCHEMES AND
149
+ (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "Bitforbit" ) AND
150
+ ${CMAKE_Fortran_COMPILER_ID} STREQUAL "Intel" )
151
+ SET_SOURCE_FILES_PROPERTIES (${LOCAL_CURRENT_SOURCE_DIR} /physics/module_sf_mynn.F90
152
+ APPEND_STRING PROPERTY COMPILE_FLAGS " ${CMAKE_Fortran_FLAGS_PHYSICS} ${OpenMP_Fortran_FLAGS} -O1" )
153
+ endif ()
241
154
242
- else ()
243
- message ("CMAKE_Fortran_COMPILER full path: " ${CMAKE_Fortran_COMPILER} )
244
- message ("Fortran compiler: " ${CMAKE_Fortran_COMPILER_ID} )
245
- message (FATAL_ERROR "This program has only been compiled with gfortran and ifort. If another compiler is needed, the appropriate flags must be added in ${GFS_PHYS_SRC} /CMakeLists.txt" )
155
+ # Reduce optimization for mo_gas_optics_kernels.F90 (to avoid an apparent compiler bug with Intel 19+)
156
+ if (${LOCAL_CURRENT_SOURCE_DIR} /physics/rte-rrtmgp/rrtmgp/kernels/mo_gas_optics_kernels.F90 IN_LIST SCHEMES_OPENMP_OFF AND
157
+ (CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "Bitforbit" ) AND
158
+ ${CMAKE_Fortran_COMPILER_ID} STREQUAL "Intel" )
159
+ SET_SOURCE_FILES_PROPERTIES (${LOCAL_CURRENT_SOURCE_DIR} /physics/rte-rrtmgp/rrtmgp/kernels/mo_gas_optics_kernels.F90
160
+ APPEND_STRING PROPERTY COMPILE_FLAGS " ${CMAKE_Fortran_FLAGS_PHYSICS} -O1" )
246
161
endif ()
247
162
248
163
#------------------------------------------------------------------------------
249
- add_library (ccpp_physics STATIC ${SCHEMES} ${SCHEMES_SFX_OPT} ${CAPS} )
164
+
165
+ add_library (ccpp_physics STATIC ${SCHEMES} ${SCHEMES_OPENMP_OFF} ${SCHEMES_DYNAMICS} ${CAPS} )
250
166
# Generate list of Fortran modules from defined sources
251
167
foreach (source_f90 ${CAPS} )
252
168
get_filename_component (tmp_source_f90 ${source_f90} NAME )
@@ -263,20 +179,18 @@ target_include_directories(ccpp_physics PUBLIC
263
179
264
180
target_link_libraries (ccpp_physics PUBLIC w3nco::w3nco_d NetCDF::NetCDF_Fortran)
265
181
266
- if (PROJECT STREQUAL "CCPP-FV3" )
267
- # Define where to install the library
268
- install (TARGETS ccpp_physics
269
- EXPORT ccpp_physics-targets
270
- ARCHIVE DESTINATION lib
271
- LIBRARY DESTINATION lib
272
- RUNTIME DESTINATION lib
273
- )
274
- # Export our configuration
275
- install (EXPORT ccpp_physics-targets
276
- FILE ccpp_physics-config.cmake
277
- DESTINATION lib/cmake
278
- )
279
- # Define where to install the C headers and Fortran modules
280
- #install(FILES ${HEADERS_C} DESTINATION include)
281
- install (FILES ${MODULES_F90} DESTINATION include )
282
- endif (PROJECT STREQUAL "CCPP-FV3" )
182
+ # Define where to install the library
183
+ install (TARGETS ccpp_physics
184
+ EXPORT ccpp_physics-targets
185
+ ARCHIVE DESTINATION lib
186
+ LIBRARY DESTINATION lib
187
+ RUNTIME DESTINATION lib
188
+ )
189
+ # Export our configuration
190
+ install (EXPORT ccpp_physics-targets
191
+ FILE ccpp_physics-config.cmake
192
+ DESTINATION lib/cmake
193
+ )
194
+ # Define where to install the C headers and Fortran modules
195
+ #install(FILES ${HEADERS_C} DESTINATION include)
196
+ install (FILES ${MODULES_F90} DESTINATION include )
0 commit comments