1- cmake_minimum_required (VERSION 3.10 )
1+ cmake_minimum_required (VERSION 3.18 )
22
33project (ccpp_physics
44 VERSION 5.0.0
55 LANGUAGES Fortran )
66
77#------------------------------------------------------------------------------
88set (PACKAGE "ccpp-physics" )
9- set (AUTHORS "Grant Firl" "Dustin Swales" "Man Zhang" "Mike Kavulich" )
9+ set (AUTHORS "Grant Firl" "Dustin Swales" "Dom Heinzeller" "Man Zhang" "Mike Kavulich" )
10+
11+ include (GNUInstallDirs )
1012
1113#------------------------------------------------------------------------------
1214# Set MPI flags for Fortran with MPI F08 interface
@@ -17,7 +19,7 @@ endif()
1719
1820#------------------------------------------------------------------------------
1921# Set OpenMP flags for C/C++/Fortran
20- if (OPENMP)
22+ if (OPENMP)
2123 find_package (OpenMP REQUIRED )
2224endif ()
2325
@@ -51,12 +53,6 @@ else(TYPEDEFS)
5153endif (TYPEDEFS )
5254list (REMOVE_DUPLICATES TYPEDEFS)
5355
54- # Generate list of Fortran modules from the CCPP type
55- # definitions that need need to be installed
56- foreach (typedef_module ${TYPEDEFS} )
57- list (APPEND MODULES_F90 ${CMAKE_CURRENT_BINARY_DIR } /${typedef_module} )
58- endforeach ()
59-
6056#------------------------------------------------------------------------------
6157# Set the sources: physics schemes
6258set (SCHEMES $ENV{CCPP_SCHEMES} )
@@ -137,7 +133,21 @@ endif()
137133
138134# Assign standard floating point precision flags to all remaining schemes and caps
139135SET_PROPERTY (SOURCE ${SCHEMES} ${CAPS}
140- APPEND_STRING PROPERTY COMPILE_FLAGS " ${CMAKE_Fortran_FLAGS_PHYSICS} ${OpenMP_Fortran_FLAGS} " )
136+ APPEND_STRING PROPERTY COMPILE_FLAGS " ${CMAKE_Fortran_FLAGS_PHYSICS} " )
137+ if (OPENMP)
138+ SET_PROPERTY (SOURCE ${SCHEMES} ${CAPS}
139+ APPEND_STRING PROPERTY COMPILE_FLAGS " ${OpenMP_Fortran_FLAGS} " )
140+ endif ()
141+
142+ # For CAPS, remove bounds checks with Intel Classic (ifort), Intel LLVM (ifx),
143+ # and GNU (gfortran) to avoid the compilation being killed or taking forever
144+ if (${CMAKE_Fortran_COMPILER_ID} STREQUAL "Intel" OR ${CMAKE_Fortran_COMPILER_ID} STREQUAL "IntelLLVM" )
145+ set_PROPERTY (SOURCE ${CAPS}
146+ APPEND_STRING PROPERTY COMPILE_FLAGS " -check nobounds" )
147+ elseif (${CMAKE_Fortran_COMPILER_ID} STREQUAL "GNU" )
148+ set_PROPERTY (SOURCE ${CAPS}
149+ APPEND_STRING PROPERTY COMPILE_FLAGS " -fcheck=no-bounds" )
150+ endif ()
141151
142152# Lower optimization for certain schemes when compiling with Intel in Release mode
143153if (CMAKE_BUILD_TYPE STREQUAL "Release" AND (${CMAKE_Fortran_COMPILER_ID} STREQUAL "Intel" OR ${CMAKE_Fortran_COMPILER_ID} STREQUAL "IntelLLVM" ))
@@ -171,21 +181,19 @@ endif()
171181
172182#------------------------------------------------------------------------------
173183
184+ set (CMAKE_Fortran_MODULE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR } /${CMAKE_INSTALL_INCLUDEDIR} )
185+
174186add_library (ccpp_physics STATIC ${SCHEMES} ${SCHEMES_OPENMP_OFF} ${SCHEMES_DYNAMICS} ${CAPS} )
175- # Generate list of Fortran modules from defined sources
176- foreach (source_f90 ${CAPS} )
177- get_filename_component (tmp_source_f90 ${source_f90} NAME )
178- string (REGEX REPLACE ".F90" ".mod" tmp_module_f90 ${tmp_source_f90} )
179- string (TOLOWER ${tmp_module_f90} module_f90)
180- list (APPEND MODULES_F90 ${CMAKE_CURRENT_BINARY_DIR } /${module_f90} )
181- endforeach ()
182187
183188set_target_properties (ccpp_physics PROPERTIES VERSION ${PROJECT_VERSION }
184189 SOVERSION ${PROJECT_VERSION_MAJOR } )
185190
186191target_include_directories (ccpp_physics PUBLIC
187- $<BUILD_INTERFACE :${CMAKE_CURRENT_BINARY_DIR } >)
192+ INTERFACE $<BUILD_INTERFACE :${CMAKE_CURRENT_BINARY_DIR } /${CMAKE_INSTALL_INCLUDEDIR} >
193+ $<INSTALL_INTERFACE :${CMAKE_INSTALL_INCLUDEDIR} >
194+ )
188195
196+ target_link_libraries (ccpp_physics PRIVATE MPI::MPI_Fortran )
189197target_link_libraries (ccpp_physics PUBLIC w3emc::w3emc_d
190198 sp::sp_d
191199 NetCDF::NetCDF_Fortran )
@@ -202,6 +210,5 @@ install(EXPORT ccpp_physics-targets
202210 FILE ccpp_physics-config.cmake
203211 DESTINATION lib/cmake
204212)
205- # Define where to install the C headers and Fortran modules
206- #install(FILES ${HEADERS_C} DESTINATION include)
207- install (FILES ${MODULES_F90} DESTINATION include)
213+
214+ install (DIRECTORY ${CMAKE_Fortran_MODULE_DIRECTORY } / DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} )
0 commit comments