From 1b7a84a062361a41c05eefe58f9175db3574e74f Mon Sep 17 00:00:00 2001 From: Michael Duda Date: Mon, 11 Nov 2019 19:30:26 -0700 Subject: [PATCH] Introduce CMake build for init_atmosphere and atmosphere cores This commit introduces a CMake build capability for the MPAS init_atmosphere and atmosphere cores, with support for the GNU, Intel, and NVHPC compilers. The following must be defined: * MPAS_CORE : Either 'init_atmosphere' or 'atmophere' * MPAS_COMPILER : One of 'gnu', 'intel', or 'nvhpc' Optionally, MPAS_PRECISION can be specified as 'single' or 'double', with builds defaulting to double-precision reals. Acknowledgements: Miles Curry and Maryam Abdi-Oskouei both contributed to the development of this capability. --- CMakeLists.txt | 143 ++++++++++++ cmake/FindNetCDF.cmake | 205 ++++++++++++++++++ cmake/FindPIO.cmake | 43 ++++ cmake/FindPNETCDF.cmake | 16 ++ src/CMakeLists.txt | 11 + src/core_atmosphere/CMakeLists.txt | 74 +++++++ .../diagnostics/CMakeLists.txt | 10 + src/core_atmosphere/dynamics/CMakeLists.txt | 5 + src/core_atmosphere/physics/CMakeLists.txt | 39 ++++ .../physics/physics_mmm/CMakeLists.txt | 10 + .../physics/physics_wrf/CMakeLists.txt | 38 ++++ src/core_init_atmosphere/CMakeLists.txt | 85 ++++++++ src/driver/CMakeLists.txt | 4 + src/external/CMakeLists.txt | 3 + src/external/SMIOL/CMakeLists.txt | 13 ++ src/external/esmf_time_f90/CMakeLists.txt | 24 ++ src/external/ezxml/CMakeLists.txt | 8 + src/framework/CMakeLists.txt | 37 ++++ src/operators/CMakeLists.txt | 12 + src/tools/CMakeLists.txt | 2 + src/tools/input_gen/CMakeLists.txt | 26 +++ src/tools/registry/CMakeLists.txt | 35 +++ 22 files changed, 843 insertions(+) create mode 100644 CMakeLists.txt create mode 100644 cmake/FindNetCDF.cmake create mode 100644 cmake/FindPIO.cmake create mode 100644 cmake/FindPNETCDF.cmake create mode 100644 src/CMakeLists.txt create mode 100644 src/core_atmosphere/CMakeLists.txt create mode 100644 src/core_atmosphere/diagnostics/CMakeLists.txt create mode 100644 src/core_atmosphere/dynamics/CMakeLists.txt create mode 100644 src/core_atmosphere/physics/CMakeLists.txt create mode 100644 src/core_atmosphere/physics/physics_mmm/CMakeLists.txt create mode 100644 src/core_atmosphere/physics/physics_wrf/CMakeLists.txt create mode 100644 src/core_init_atmosphere/CMakeLists.txt create mode 100644 src/driver/CMakeLists.txt create mode 100644 src/external/CMakeLists.txt create mode 100644 src/external/SMIOL/CMakeLists.txt create mode 100644 src/external/esmf_time_f90/CMakeLists.txt create mode 100644 src/external/ezxml/CMakeLists.txt create mode 100644 src/framework/CMakeLists.txt create mode 100644 src/operators/CMakeLists.txt create mode 100644 src/tools/CMakeLists.txt create mode 100644 src/tools/input_gen/CMakeLists.txt create mode 100644 src/tools/registry/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000000..bb512f8e73 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,143 @@ +cmake_minimum_required(VERSION 3.13) +cmake_policy(SET CMP0076 NEW) +project(reg C Fortran) + + +# +# Define build options +# +set(MPAS_CORE "None" CACHE STRING "The MPAS core to build. Possible options: atmosphere init_atmosphere") +set(MPAS_COMPILER "None" CACHE STRING "The MPAS core to build. Possible options: gnu intel nvhpc") +set(MPAS_PRECISION "double" CACHE STRING "The default precision for real values. Possible options: single double") + +# +# Set core to build and associated preprocessing definitions +# +if(MPAS_CORE STREQUAL "atmosphere") + set(MPAS_EXE_NAME "atmosphere_model") + set(MPAS_CORE_DEF "CORE_ATMOSPHERE") +elseif(MPAS_CORE STREQUAL "init_atmosphere") + set(MPAS_EXE_NAME "init_atmosphere_model") + set(MPAS_CORE_DEF "CORE_INIT_ATMOSPHERE") +else() + message(FATAL_ERROR "Please define MPAS_CORE as one of: atmosphere init_atmosphere") +endif() + +add_executable(${MPAS_EXE_NAME}) +target_compile_definitions(${MPAS_EXE_NAME} PUBLIC ${MPAS_CORE_DEF}) + + +# +# Set compilation macros that are invariant +# +target_compile_definitions(${MPAS_EXE_NAME} PUBLIC _MPI) + + +# +# Set compiler and compiler options +# +if(MPAS_COMPILER STREQUAL gnu) + set(CMAKE_C_COMPILER mpicc) + set(CMAKE_Fortran_COMPILER mpif90) + set(CMAKE_Fortran_FLAGS "-ffree-line-length-none") + set(PROMOTION_FLAGS "-fdefault-real-8 -fdefault-double-8") + set(BYTESWAP_FLAGS "-fconvert=big-endian") +elseif(MPAS_COMPILER STREQUAL intel) + set(CMAKE_C_COMPILER mpicc) + set(CMAKE_Fortran_COMPILER mpif90) + set(PROMOTION_FLAGS "-real-size 64") + set(BYTESWAP_FLAGS "-convert big_endian") +elseif(MPAS_COMPILER STREQUAL nvhpc) + set(CMAKE_C_COMPILER mpicc) + set(CMAKE_Fortran_COMPILER mpifort) + set(PROMOTION_FLAGS "-r8") + set(BYTESWAP_FLAGS "-byteswapio") +else() + message(FATAL_ERROR "Please define MPAS_COMPILER as one of: gnu intel nvhpc") +endif() + +set_property(TARGET ${MPAS_EXE_NAME} PROPERTY Fortran_FORMAT FREE) +set_property(TARGET ${MPAS_EXE_NAME} PROPERTY Fortran_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/mod) + + +# +# Set precision for real values +# +if(MPAS_PRECISION STREQUAL "single") + target_compile_definitions(${MPAS_EXE_NAME} PUBLIC SINGLE_PRECISION) +else() + set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${PROMOTION_FLAGS}") +endif() + + +# +# Set flags to handle endianness of binary files +# +set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} ${BYTESWAP_FLAGS}") + + +# +# Locate external libraries: netCDF, parallel-netCDF, PIO +# +set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/" ${CMAKE_MODULE_PATH}) + + +find_package(NetCDF REQUIRED) +find_package(HDF5 REQUIRED) +find_package(PNETCDF REQUIRED) +find_package(PIO) + + +# +# If the PIO library was found, use PIO; otherwise use SMIOL +# +get_property(PIO_VERSION GLOBAL PROPERTY PIO_VERSION) +if(PIO_VERSION GREATER_EQUAL 1) + target_compile_definitions(${MPAS_EXE_NAME} PUBLIC MPAS_PIO_SUPPORT) + + # + # Set compilation macros to select appropriate PIO API + # + if(PIO_VERSION STREQUAL "2") + target_compile_definitions(${MPAS_EXE_NAME} PUBLIC USE_PIO2) + endif() + set(IO_LIBRARIES ${PIO_LIBRARIES}) + set(IO_INCLUDES_DIRS ${PIO_INCLUDE_DIRS}) +else() + target_compile_definitions(${MPAS_EXE_NAME} PUBLIC MPAS_SMIOL_SUPPORT) +endif() + + +# +# Process everything in the src/ subdirectory +# +add_subdirectory(src) + + +# +# Add include paths and libraries from packages that are internally built by MPAS +# +get_property(MPAS_INTERNAL_INCLUDE_DIRS GLOBAL PROPERTY MPAS_INTERNAL_INCLUDE_DIRS) +get_property(MPAS_INTERNAL_LIBRARIES GLOBAL PROPERTY MPAS_INTERNAL_LIBRARIES) +target_include_directories(${MPAS_EXE_NAME} PRIVATE ${MPAS_INTERNAL_INCLUDE_DIRS}) +target_link_libraries(${MPAS_EXE_NAME} PRIVATE ${MPAS_INTERNAL_LIBRARIES}) + +# +# Add external include paths and libraries +# +target_include_directories(${MPAS_EXE_NAME} + PUBLIC + ${IO_INCLUDE_DIRS} + ${PNETCDF_INCLUDE_DIRS} + ${HDF5_INCLUDE_DIRS} + ${NETCDF_INCLUDE_DIRS} + ) + +target_link_libraries(${MPAS_EXE_NAME} + PUBLIC + ${IO_LIBRARIES} + ${NetCDF_LIBRARIES} + ${HDF5_LIBRARIES} + ${PNETCDF_LIBRARIES} + ${CMAKE_DL_LIBS} + ) diff --git a/cmake/FindNetCDF.cmake b/cmake/FindNetCDF.cmake new file mode 100644 index 0000000000..f4a210900c --- /dev/null +++ b/cmake/FindNetCDF.cmake @@ -0,0 +1,205 @@ +# (C) Copyright 2011- ECMWF. +# +# This software is licensed under the terms of the Apache Licence Version 2.0 +# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +# In applying this licence, ECMWF does not waive the privileges and immunities +# granted to it by virtue of its status as an intergovernmental organisation nor +# does it submit to any jurisdiction. + +# Try to find NetCDF includes and library, only shared libraries are supported! +# +# This module defines +# +# - NetCDF_FOUND - System has NetCDF +# - NetCDF_INCLUDE_DIRS - the NetCDF include directories +# - NetCDF_LIBRARIES - the libraries needed to use NetCDF +# - NetCDF_VERSION - the version of NetCDF +# +# Following components are available: +# +# - C - C interface to NetCDF (netcdf) +# - CXX - CXX4 interface to NetCDF (netcdf_c++4) +# - Fortran - Fortran interface to NetCDF (netcdff) +# - CXX_LEGACY - Legacy C++ interface to NetCDF (netcdf_c++) +# +# For each component the following are defined: +# +# - NetCDF__FOUND - whether the component is found +# - NetCDF__LIBRARIES - the libraries for the component +# - NetCDF__INCLUDE_DIRS - the include directories for specfied component +# - NetCDF::NetCDF_ - target of component to be used with target_link_libraries() +# +# The following paths will be searched in order if set in CMake (first priority) or environment (second priority) +# +# - NETCDF_ROOT - root of NetCDF installation +# - NETCDF_DIR - root of NetCDF installation +# - NETCDF_PATH - root of NetCDF installation +# - NETCDF4_DIR - root of NetCDF installation +# - NetCDF_ROOT - root of NetCDF installation +# - NetCDF_DIR - root of NetCDF installation +# - NetCDF_PATH - root of NetCDF installation +# - NetCDF4_DIR - root of NetCDF installation +# +# Notes: +# +# - Each variable is also available in fully uppercased version +# - In each variable (not in targets), the "NetCDF" prefix may be interchanged with +# * NetCDF4 +# * NETCDF +# * NETCDF4 +# * The part "" in current filename Find.cmake +# - Capitalisation of COMPONENT arguments does not matter: The part of variables will be defined with +# * capitalisation as defined above +# * Uppercase capitalisation +# * capitalisation as used in find_package() arguments +# - If no components are defined, all components will be searched without guarantee that the required component is available. +# + +list( APPEND _possible_components C CXX Fortran CXX_LEGACY ) + +## Library names for each component +set( NetCDF_C_LIBRARY_NAME netcdf ) +set( NetCDF_CXX_LIBRARY_NAME netcdf_c++4 ) +set( NetCDF_CXX_LEGACY_LIBRARY_NAME netcdf_c++ ) +set( NetCDF_Fortran_LIBRARY_NAME netcdff ) + +foreach( _comp ${_possible_components} ) + string( TOUPPER "${_comp}" _COMP ) + set( _arg_${_COMP} ${_comp} ) + set( _name_${_COMP} ${_comp} ) +endforeach() + +unset( _search_components ) +foreach( _comp ${${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS} ) + string( TOUPPER "${_comp}" _COMP ) + set( _arg_${_COMP} ${_comp} ) + list( APPEND _search_components ${_name_${_COMP}} ) + if( NOT _name_${_COMP} ) + ecbuild_error( "Find${CMAKE_FIND_PACKAGE_NAME}: COMPONENT ${_comp} is not a valid component. Valid components: ${_possible_components}" ) + endif() +endforeach() +if( NOT _search_components ) + set( _search_components C ) +endif() + +## Search hints for finding include directories and libraries +set( _search_hints + ${NETCDF_ROOT} ${NETCDF_DIR} ${NETCDF_PATH} ${NETCDF4_DIR} + ${NetCDF_ROOT} ${NetCDF_DIR} ${NetCDF_PATH} ${NetCDF4_DIR} + ENV NETCDF_ROOT ENV NETCDF_DIR ENV NETCDF_PATH ENV NETCDF4_DIR + ENV NetCDF_ROOT ENV NetCDF_DIR ENV NetCDF_PATH ENV NetCDF4_DIR + ) + +## Find include directories +find_path(NetCDF_INCLUDE_DIRS + NAMES netcdf.h + DOC "netcdf include directories" + HINTS ${_search_hints} + PATH_SUFFIXES include ../../include +) +mark_as_advanced(NetCDF_INCLUDE_DIRS) + +## Find libraries for each component +foreach( _comp ${_search_components} ) + string( TOUPPER "${_comp}" _COMP ) + + find_library(NetCDF_${_comp}_LIBRARY + NAMES ${NetCDF_${_comp}_LIBRARY_NAME} + DOC "netcdf ${_comp} library" + HINTS ${_search_hints} + PATH_SUFFIXES lib ../../lib + ) + mark_as_advanced(NetCDF_${_comp}_LIBRARY) + if( NetCDF_${_comp}_LIBRARY AND NOT (NetCDF_${_comp}_LIBRARY MATCHES ".a$") ) + set( NetCDF_${_comp}_LIBRARY_SHARED TRUE ) + endif() + if( NetCDF_${_comp}_LIBRARY_SHARED AND NetCDF_INCLUDE_DIRS ) + set( ${CMAKE_FIND_PACKAGE_NAME}_${_arg_${_COMP}}_FOUND TRUE ) + list( APPEND NetCDF_LIBRARIES ${NetCDF_${_comp}_LIBRARY} ) + list( APPEND NetCDF_${_comp}_LIBRARIES ${NetCDF_${_comp}_LIBRARY} ) + + if (NOT TARGET NetCDF::NetCDF_${_comp}) + add_library(NetCDF::NetCDF_${_comp} UNKNOWN IMPORTED) + set_target_properties(NetCDF::NetCDF_${_comp} PROPERTIES + IMPORTED_LOCATION "${NetCDF_${_comp}_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${NetCDF_INCLUDE_DIRS}") + endif() + endif() +endforeach() + +## Find version +if (NetCDF_INCLUDE_DIRS) + find_program( NETCDF_CONFIG_EXECUTABLE + NAMES nc-config + HINTS ${_search_hints} + PATH_SUFFIXES bin Bin ../../bin + DOC "NetCDF nc-config helper" ) + mark_as_advanced( NETCDF_CONFIG_EXECUTABLE ) + + if( NETCDF_CONFIG_EXECUTABLE ) + execute_process( COMMAND ${NETCDF_CONFIG_EXECUTABLE} --version + RESULT_VARIABLE _netcdf_config_result + OUTPUT_VARIABLE _netcdf_config_version) + + if( _netcdf_config_result EQUAL 0 ) + string(REGEX REPLACE ".* ((([0-9]+)\\.)+([0-9]+)).*" "\\1" NetCDF_VERSION "${_netcdf_config_version}" ) + endif() + + elseif( EXISTS "${NetCDF_INCLUDE_DIRS}/netcdf_meta.h" ) + + file(STRINGS "${NetCDF_INCLUDE_DIRS}/netcdf_meta.h" _netcdf_version_lines + REGEX "#define[ \t]+NC_VERSION_(MAJOR|MINOR|PATCH|NOTE)") + string(REGEX REPLACE ".*NC_VERSION_MAJOR *\([0-9]*\).*" "\\1" _netcdf_version_major "${_netcdf_version_lines}") + string(REGEX REPLACE ".*NC_VERSION_MINOR *\([0-9]*\).*" "\\1" _netcdf_version_minor "${_netcdf_version_lines}") + string(REGEX REPLACE ".*NC_VERSION_PATCH *\([0-9]*\).*" "\\1" _netcdf_version_patch "${_netcdf_version_lines}") + string(REGEX REPLACE ".*NC_VERSION_NOTE *\"\([^\"]*\)\".*" "\\1" _netcdf_version_note "${_netcdf_version_lines}") + set(NetCDF_VERSION "${_netcdf_version_major}.${_netcdf_version_minor}.${_netcdf_version_patch}${_netcdf_version_note}") + unset(_netcdf_version_major) + unset(_netcdf_version_minor) + unset(_netcdf_version_patch) + unset(_netcdf_version_note) + unset(_netcdf_version_lines) + endif() +endif () + +## Finalize find_package +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args( ${CMAKE_FIND_PACKAGE_NAME} + REQUIRED_VARS NetCDF_INCLUDE_DIRS NetCDF_LIBRARIES + VERSION_VAR NetCDF_VERSION + HANDLE_COMPONENTS ) + +if( ${CMAKE_FIND_PACKAGE_NAME}_FOUND AND NOT ${CMAKE_FIND_PACKAGE_NAME}_FIND_QUIETLY ) + message( STATUS "Find${CMAKE_FIND_PACKAGE_NAME} defines targets:" ) + foreach( _comp ${_search_components} ) + string( TOUPPER "${_comp}" _COMP ) + + if( ${CMAKE_FIND_PACKAGE_NAME}_${_arg_${_COMP}}_FOUND ) + message( STATUS " - NetCDF::NetCDF_${_comp} [${NetCDF_${_comp}_LIBRARY}]") + endif() + endforeach() +endif() + +foreach( _prefix NetCDF NetCDF4 NETCDF NETCDF4 ${CMAKE_FIND_PACKAGE_NAME} ) + set( ${_prefix}_INCLUDE_DIRS ${NetCDF_INCLUDE_DIRS} ) + set( ${_prefix}_LIBRARIES ${NetCDF_LIBRARIES}) + set( ${_prefix}_VERSION ${NetCDF_VERSION} ) + set( ${_prefix}_FOUND ${${CMAKE_FIND_PACKAGE_NAME}_FOUND} ) + + foreach( _comp ${_search_components} ) + string( TOUPPER "${_comp}" _COMP ) + set( _arg_comp ${_arg_${_COMP}} ) + set( ${_prefix}_${_comp}_FOUND ${${CMAKE_FIND_PACKAGE_NAME}_${_arg_comp}_FOUND} ) + set( ${_prefix}_${_COMP}_FOUND ${${CMAKE_FIND_PACKAGE_NAME}_${_arg_comp}_FOUND} ) + set( ${_prefix}_${_arg_comp}_FOUND ${${CMAKE_FIND_PACKAGE_NAME}_${_arg_comp}_FOUND} ) + + set( ${_prefix}_${_comp}_LIBRARIES ${NetCDF_${_comp}_LIBRARIES} ) + set( ${_prefix}_${_COMP}_LIBRARIES ${NetCDF_${_comp}_LIBRARIES} ) + set( ${_prefix}_${_arg_comp}_LIBRARIES ${NetCDF_${_comp}_LIBRARIES} ) + + set( ${_prefix}_${_comp}_INCLUDE_DIRS ${NetCDF_INCLUDE_DIRS} ) + set( ${_prefix}_${_COMP}_INCLUDE_DIRS ${NetCDF_INCLUDE_DIRS} ) + set( ${_prefix}_${_arg_comp}_INCLUDE_DIRS ${NetCDF_INCLUDE_DIRS} ) + endforeach() +endforeach() diff --git a/cmake/FindPIO.cmake b/cmake/FindPIO.cmake new file mode 100644 index 0000000000..8ea1f22f86 --- /dev/null +++ b/cmake/FindPIO.cmake @@ -0,0 +1,43 @@ +# - Try to find PIO +# Once done this will define +# PIO_FOUND - System has PIO +# PIO_INCLUDE_DIRS - The PIO include directories +# PIO_LIBRARIES - The libraries needed to use PIO +# PIO_VERSION - A global property indicating the PIO API: either 1 or 2 if PIO was found, and 0 otherwise + +find_path(PIO_INCLUDE_DIR pio.mod PIO.mod HINTS ENV PIO ENV PIO_PATH PATH_SUFFIXES include) +find_library(PIO1_C_LIBRARY libpio.a HINTS ENV PIO ENV PIO_PATH PATH_SUFFIXES lib) +find_library(PIO2_C_LIBRARY libpioc.a libpioc.so HINTS ENV PIO ENV PIO_PATH PATH_SUFFIXES lib) +find_library(PIO_F_LIBRARY libpiof.a libpiof.so HINTS ENV PIO ENV PIO_PATH PATH_SUFFIXES lib) + +if(PIO1_C_LIBRARY) + set(PIO_C_LIBRARY ${PIO1_C_LIBRARY}) + set_property(GLOBAL PROPERTY PIO_VERSION 1) + + # + # PIO 1.x may not have a separate Fortran and C library, in which case, we can just + # use libpio.a as the only PIO library + # + if (${PIO_F_LIBRARY} STREQUAL "PIO_F_LIBRARY-NOTFOUND") + set(PIO_LIBRARIES ${PIO_C_LIBRARY}) + else() + set(PIO_LIBRARIES ${PIO_F_LIBRARY} ${PIO_C_LIBRARY}) + endif() + set(PIO_INCLUDE_DIRS ${PIO_INCLUDE_DIR}) +elseif(PIO2_C_LIBRARY) + set(PIO_C_LIBRARY ${PIO2_C_LIBRARY}) + set_property(GLOBAL PROPERTY PIO_VERSION 2) + set(PIO_LIBRARIES ${PIO_F_LIBRARY} ${PIO_C_LIBRARY}) + set(PIO_INCLUDE_DIRS ${PIO_INCLUDE_DIR}) +else() + message("No PIO library found...") + set_property(GLOBAL PROPERTY PIO_VERSION 0) + set(PIO_LIBRARIES "") + set(PIO_INCLUDE_DIRS "") +endif() + + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set PIO_FOUND to TRUE +# if all listed variables are TRUE +find_package_handle_standard_args(PIO DEFAULT_MSG PIO_LIBRARIES PIO_INCLUDE_DIRS) diff --git a/cmake/FindPNETCDF.cmake b/cmake/FindPNETCDF.cmake new file mode 100644 index 0000000000..08f0a1156a --- /dev/null +++ b/cmake/FindPNETCDF.cmake @@ -0,0 +1,16 @@ +# - Try to find PnetCDF +# Once done this will define +# PNETCDF_FOUND - System has PnetCDF +# PNETCDF_INCLUDE_DIRS - The PnetCDF include directories +# PNETCDF_LIBRARIES - The libraries needed to use PnetCDF + +find_path(PNETCDF_INCLUDE_DIR pnetcdf.mod PNETCDF.mod HINTS ENV PNETCDF ENV PNETCDF_PATH PATH_SUFFIXES include) +find_library(PNETCDF_LIBRARY libpnetcdf.a HINTS ENV PNETCDF ENV PNETCDF_PATH PATH_SUFFIXES lib) + +set(PNETCDF_INCLUDE_DIRS ${PNETCDF_INCLUDE_DIR}) +set(PNETCDF_LIBRARIES ${PNETCDF_LIBRARY}) + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set PNETCDF_FOUND to TRUE +# if all listed variables are TRUE +find_package_handle_standard_args(PNETCDF DEFAULT_MSG PNETCDF_LIBRARIES PNETCDF_INCLUDE_DIRS) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000000..4f2d5e9210 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,11 @@ +add_subdirectory(external) +add_subdirectory(tools) +add_subdirectory(framework) +add_subdirectory(operators) +if(MPAS_CORE STREQUAL "atmosphere") + add_subdirectory(core_atmosphere) +endif() +if(MPAS_CORE STREQUAL "init_atmosphere") + add_subdirectory(core_init_atmosphere) +endif() +add_subdirectory(driver) diff --git a/src/core_atmosphere/CMakeLists.txt b/src/core_atmosphere/CMakeLists.txt new file mode 100644 index 0000000000..e361160420 --- /dev/null +++ b/src/core_atmosphere/CMakeLists.txt @@ -0,0 +1,74 @@ +target_compile_definitions(${MPAS_EXE_NAME} PUBLIC DO_PHYSICS) +target_compile_definitions(${MPAS_EXE_NAME} PUBLIC mpas=MPAS) + +add_subdirectory(physics) +add_subdirectory(diagnostics) +add_subdirectory(dynamics) + +add_custom_command(OUTPUT + Registry_processed.xml + COMMAND + cpp -P -traditional ${CMAKE_SOURCE_DIR}/src/core_atmosphere/Registry.xml > Registry_processed.xml + DEPENDS + Registry.xml) + +add_custom_command(OUTPUT + block_dimension_routines.inc + core_variables.inc + define_packages.inc + domain_variables.inc + namelist_call.inc + namelist_defines.inc + setup_immutable_streams.inc + structs_and_variables.inc + COMMAND + ${CMAKE_BINARY_DIR}/src/tools/registry/parse Registry_processed.xml + DEPENDS + parse Registry_processed.xml) + +add_custom_target(atm_core + DEPENDS + block_dimension_routines.inc + core_variables.inc + define_packages.inc + domain_variables.inc + namelist_call.inc + namelist_defines.inc + setup_immutable_streams.inc + structs_and_variables.inc) + +add_custom_command(OUTPUT + namelist.atmosphere + COMMAND + ${CMAKE_BINARY_DIR}/src/tools/input_gen/namelist_gen Registry_processed.xml ${CMAKE_BINARY_DIR}/namelist.atmosphere in_defaults=true + DEPENDS + namelist_gen Registry_processed.xml) + +add_custom_target(atm_namelist + DEPENDS + namelist.atmosphere) + +add_custom_command(OUTPUT + streams.atmosphere + COMMAND + ${CMAKE_BINARY_DIR}/src/tools/input_gen/streams_gen Registry_processed.xml ${CMAKE_BINARY_DIR}/streams.atmosphere ${CMAKE_BINARY_DIR}/stream_list.atmosphere. listed + DEPENDS + streams_gen Registry_processed.xml) + +add_custom_target(atm_streams + DEPENDS + streams.atmosphere) + +add_dependencies(${MPAS_EXE_NAME} atm_core) +add_dependencies(${MPAS_EXE_NAME} atm_namelist) +add_dependencies(${MPAS_EXE_NAME} atm_streams) + +set_property(GLOBAL APPEND PROPERTY MPAS_INTERNAL_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}) + +target_sources(${MPAS_EXE_NAME} + PUBLIC + mpas_atm_core.F + mpas_atm_core_interface.F + mpas_atm_dimensions.F + mpas_atm_halos.F + mpas_atm_threading.F) diff --git a/src/core_atmosphere/diagnostics/CMakeLists.txt b/src/core_atmosphere/diagnostics/CMakeLists.txt new file mode 100644 index 0000000000..04de7093de --- /dev/null +++ b/src/core_atmosphere/diagnostics/CMakeLists.txt @@ -0,0 +1,10 @@ +target_sources(${MPAS_EXE_NAME} + PUBLIC + mpas_atm_diagnostics_manager.F + mpas_atm_diagnostics_utils.F + mpas_atm_diagnostic_template.F + mpas_cloud_diagnostics.F + mpas_convective_diagnostics.F + mpas_isobaric_diagnostics.F + mpas_pv_diagnostics.F + mpas_soundings.F) diff --git a/src/core_atmosphere/dynamics/CMakeLists.txt b/src/core_atmosphere/dynamics/CMakeLists.txt new file mode 100644 index 0000000000..ec0b64c00b --- /dev/null +++ b/src/core_atmosphere/dynamics/CMakeLists.txt @@ -0,0 +1,5 @@ +target_sources(${MPAS_EXE_NAME} + PUBLIC + mpas_atm_boundaries.F + mpas_atm_iau.F + mpas_atm_time_integration.F) diff --git a/src/core_atmosphere/physics/CMakeLists.txt b/src/core_atmosphere/physics/CMakeLists.txt new file mode 100644 index 0000000000..d42ea4386f --- /dev/null +++ b/src/core_atmosphere/physics/CMakeLists.txt @@ -0,0 +1,39 @@ +add_subdirectory(physics_wrf) +add_subdirectory(physics_mmm) + +target_sources(${MPAS_EXE_NAME} + PUBLIC + ccpp_kinds.F + mpas_atmphys_camrad_init.F + mpas_atmphys_constants.F + mpas_atmphys_control.F + mpas_atmphys_date_time.F + mpas_atmphys_driver_cloudiness.F + mpas_atmphys_driver_convection.F + mpas_atmphys_driver.F + mpas_atmphys_driver_gwdo.F + mpas_atmphys_driver_lsm.F + mpas_atmphys_driver_lsm_shared.F + mpas_atmphys_driver_microphysics.F + mpas_atmphys_driver_oml.F + mpas_atmphys_driver_pbl.F + mpas_atmphys_driver_radiation_lw.F + mpas_atmphys_driver_radiation_sw.F + mpas_atmphys_driver_sfclayer.F + mpas_atmphys_finalize.F + mpas_atmphys_functions.F + mpas_atmphys_init.F + mpas_atmphys_init_microphysics.F + mpas_atmphys_interface.F + mpas_atmphys_landuse.F + mpas_atmphys_lsm_noahinit.F + mpas_atmphys_manager.F + mpas_atmphys_o3climatology.F + mpas_atmphys_packages.F + mpas_atmphys_rrtmg_lwinit.F + mpas_atmphys_rrtmg_swinit.F + mpas_atmphys_todynamics.F + mpas_atmphys_update.F + mpas_atmphys_update_surface.F + mpas_atmphys_utilities.F + mpas_atmphys_vars.F) diff --git a/src/core_atmosphere/physics/physics_mmm/CMakeLists.txt b/src/core_atmosphere/physics/physics_mmm/CMakeLists.txt new file mode 100644 index 0000000000..1f06a3e740 --- /dev/null +++ b/src/core_atmosphere/physics/physics_mmm/CMakeLists.txt @@ -0,0 +1,10 @@ +target_sources(${MPAS_EXE_NAME} + PUBLIC + bl_gwdo.F + bl_ysu.F + cu_ntiedtke.F + module_libmassv.F + mp_radar.F + mp_wsm6_effectRad.F + mp_wsm6.F + sf_sfclayrev.F) diff --git a/src/core_atmosphere/physics/physics_wrf/CMakeLists.txt b/src/core_atmosphere/physics/physics_wrf/CMakeLists.txt new file mode 100644 index 0000000000..4ce54c4a38 --- /dev/null +++ b/src/core_atmosphere/physics/physics_wrf/CMakeLists.txt @@ -0,0 +1,38 @@ +target_sources(${MPAS_EXE_NAME} + PUBLIC + libmassv.F + module_bep_bem_helper.F + module_bl_gwdo.F + module_bl_mynn.F + module_bl_ysu.F + module_cam_error_function.F + module_cam_shr_kind_mod.F + module_cam_support.F + module_cu_gf.mpas.F + module_cu_kfeta.F + module_cu_ntiedtke.F + module_cu_tiedtke.F + module_mp_kessler.F + module_mp_radar.F + module_mp_thompson_cldfra3.F + module_mp_thompson.F + module_mp_wsm6.F + module_ra_cam.F + module_ra_cam_support.F + module_ra_rrtmg_lw.F + module_ra_rrtmg_sw.F + module_ra_rrtmg_vinterp.F + module_sf_bem.F + module_sf_bep_bem.F + module_sf_bep.F + module_sf_mynn.F + module_sf_noahdrv.F + module_sf_noahlsm.F + module_sf_noahlsm_glacial_only.F + module_sf_noah_seaice_drv.F + module_sf_noah_seaice.F + module_sf_oml.F + module_sf_sfcdiags.F + module_sf_sfclay.F + module_sf_sfclayrev.F + module_sf_urban.F) diff --git a/src/core_init_atmosphere/CMakeLists.txt b/src/core_init_atmosphere/CMakeLists.txt new file mode 100644 index 0000000000..cff0d1065e --- /dev/null +++ b/src/core_init_atmosphere/CMakeLists.txt @@ -0,0 +1,85 @@ +add_custom_command(OUTPUT + Registry_processed.xml + COMMAND + cpp -P -traditional ${CMAKE_SOURCE_DIR}/src/core_init_atmosphere/Registry.xml > Registry_processed.xml + DEPENDS + Registry.xml) + +add_custom_command(OUTPUT + block_dimension_routines.inc + core_variables.inc + define_packages.inc + domain_variables.inc + namelist_call.inc + namelist_defines.inc + setup_immutable_streams.inc + structs_and_variables.inc + COMMAND + ${CMAKE_BINARY_DIR}/src/tools/registry/parse Registry_processed.xml + DEPENDS + parse Registry_processed.xml) + +add_custom_target(init_atm_core + DEPENDS + block_dimension_routines.inc + core_variables.inc + define_packages.inc + domain_variables.inc + namelist_call.inc + namelist_defines.inc + setup_immutable_streams.inc + structs_and_variables.inc) + +add_custom_command(OUTPUT + namelist.init_atmosphere + COMMAND + ${CMAKE_BINARY_DIR}/src/tools/input_gen/namelist_gen Registry_processed.xml ${CMAKE_BINARY_DIR}/namelist.init_atmosphere in_defaults=true + DEPENDS + namelist_gen Registry_processed.xml) + +add_custom_target(init_atm_namelist + DEPENDS + namelist.init_atmosphere) + +add_custom_command(OUTPUT + streams.init_atmosphere + COMMAND + ${CMAKE_BINARY_DIR}/src/tools/input_gen/streams_gen Registry_processed.xml ${CMAKE_BINARY_DIR}/streams.init_atmosphere ${CMAKE_BINARY_DIR}/stream_list.init_atmosphere. listed + DEPENDS + streams_gen Registry_processed.xml) + +add_custom_target(init_atm_streams + DEPENDS + streams.init_atmosphere) + +add_dependencies(${MPAS_EXE_NAME} init_atm_core) +add_dependencies(${MPAS_EXE_NAME} init_atm_namelist) +add_dependencies(${MPAS_EXE_NAME} init_atm_streams) + +set_property(GLOBAL APPEND PROPERTY MPAS_INTERNAL_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}) + +target_sources(${MPAS_EXE_NAME} + PUBLIC + mpas_atm_advection.F + mpas_atmphys_constants.F + mpas_atmphys_date_time.F + mpas_atmphys_functions.F + mpas_atmphys_initialize_real.F + mpas_atmphys_utilities.F + mpas_geotile_manager.F + mpas_init_atm_bitarray.F + mpas_init_atm_cases.F + mpas_init_atm_core.F + mpas_init_atm_core_interface.F + mpas_init_atm_gwd.F + mpas_init_atm_hinterp.F + mpas_init_atm_llxy.F + mpas_init_atm_queue.F + mpas_init_atm_read_met.F + mpas_init_atm_static.F + mpas_init_atm_surface.F + mpas_init_atm_vinterp.F + mpas_kd_tree.F + mpas_parse_geoindex.F + mpas_stack.F + read_geogrid.c) diff --git a/src/driver/CMakeLists.txt b/src/driver/CMakeLists.txt new file mode 100644 index 0000000000..be4a74f85e --- /dev/null +++ b/src/driver/CMakeLists.txt @@ -0,0 +1,4 @@ +target_sources(${MPAS_EXE_NAME} + PUBLIC + mpas.F + mpas_subdriver.F) diff --git a/src/external/CMakeLists.txt b/src/external/CMakeLists.txt new file mode 100644 index 0000000000..17215336e9 --- /dev/null +++ b/src/external/CMakeLists.txt @@ -0,0 +1,3 @@ +add_subdirectory(ezxml) +add_subdirectory(esmf_time_f90) +add_subdirectory(SMIOL) diff --git a/src/external/SMIOL/CMakeLists.txt b/src/external/SMIOL/CMakeLists.txt new file mode 100644 index 0000000000..e9401c20b0 --- /dev/null +++ b/src/external/SMIOL/CMakeLists.txt @@ -0,0 +1,13 @@ +add_library(smiol) + +target_compile_definitions(smiol PUBLIC SMIOL_PNETCDF) + +target_sources(smiol + PRIVATE + smiolf.F90 + smiol.c + smiol_utils.c) + +set_property(GLOBAL APPEND PROPERTY MPAS_INTERNAL_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}) +set_property(GLOBAL APPEND PROPERTY MPAS_INTERNAL_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/src/external/SMIOL) +set_property(GLOBAL APPEND PROPERTY MPAS_INTERNAL_LIBRARIES smiol) diff --git a/src/external/esmf_time_f90/CMakeLists.txt b/src/external/esmf_time_f90/CMakeLists.txt new file mode 100644 index 0000000000..0c0b8eb754 --- /dev/null +++ b/src/external/esmf_time_f90/CMakeLists.txt @@ -0,0 +1,24 @@ +add_library(esmf_time) + +target_sources(esmf_time + PRIVATE + ESMF_AlarmClockMod.F90 + ESMF_AlarmMod.F90 + ESMF_BaseMod.F90 + ESMF_BaseTimeMod.F90 + ESMF_CalendarMod.F90 + ESMF_ClockMod.F90 + ESMF.F90 + ESMF_FractionMod.F90 + ESMF_Macros.inc + ESMF_ShrTimeMod.F90 + ESMF_Stubs.F90 + ESMF_TimeIntervalMod.F90 + ESMF_TimeMgr.inc + ESMF_TimeMod.F90 + MeatMod.F90 + wrf_error_fatal.F90 + wrf_message.F90) + +set_property(GLOBAL APPEND PROPERTY MPAS_INTERNAL_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/src/external/esmf_time_f90) +set_property(GLOBAL APPEND PROPERTY MPAS_INTERNAL_LIBRARIES esmf_time) diff --git a/src/external/ezxml/CMakeLists.txt b/src/external/ezxml/CMakeLists.txt new file mode 100644 index 0000000000..3ca1c88a3f --- /dev/null +++ b/src/external/ezxml/CMakeLists.txt @@ -0,0 +1,8 @@ +add_library(ezxml) + +target_sources(ezxml + PRIVATE + ezxml.c) + +set_property(GLOBAL APPEND PROPERTY MPAS_INTERNAL_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}) +set_property(GLOBAL APPEND PROPERTY MPAS_INTERNAL_LIBRARIES ezxml) diff --git a/src/framework/CMakeLists.txt b/src/framework/CMakeLists.txt new file mode 100644 index 0000000000..35ff77e175 --- /dev/null +++ b/src/framework/CMakeLists.txt @@ -0,0 +1,37 @@ +target_sources(${MPAS_EXE_NAME} + PUBLIC + mpas_abort.F + mpas_attlist.F + mpas_block_creator.F + mpas_block_decomp.F + mpas_bootstrapping.F + mpas_c_interfacing.F + mpas_constants.F + mpas_decomp.F + mpas_derived_types.F + mpas_dmpar.F + mpas_domain_routines.F + mpas_field_routines.F + mpas_forcing.F + mpas_framework.F + mpas_halo.F + mpas_hash.F + mpas_io.F + mpas_io_streams.F + mpas_io_units.F + mpas_kind_types.F + mpas_log.F + mpas_pool_routines.F + mpas_sort.F + mpas_stream_inquiry.F + mpas_stream_list.F + mpas_stream_manager.F + mpas_string_utils.F + mpas_threading.F + mpas_timekeeping.F + mpas_timer.F + pool_hash.c + random_id.c + regex_matching.c + stream_inquiry.c + xml_stream_parser.c) diff --git a/src/operators/CMakeLists.txt b/src/operators/CMakeLists.txt new file mode 100644 index 0000000000..354cf9c165 --- /dev/null +++ b/src/operators/CMakeLists.txt @@ -0,0 +1,12 @@ +target_sources(${MPAS_EXE_NAME} + PUBLIC + mpas_geometry_utils.F + mpas_matrix_operations.F + mpas_rbf_interpolation.F + mpas_spline_interpolation.F + mpas_tensor_operations.F + mpas_tracer_advection_helpers.F + mpas_tracer_advection_mono.F + mpas_tracer_advection_std.F + mpas_vector_operations.F + mpas_vector_reconstruction.F) diff --git a/src/tools/CMakeLists.txt b/src/tools/CMakeLists.txt new file mode 100644 index 0000000000..121e602868 --- /dev/null +++ b/src/tools/CMakeLists.txt @@ -0,0 +1,2 @@ +add_subdirectory(registry) +add_subdirectory(input_gen) diff --git a/src/tools/input_gen/CMakeLists.txt b/src/tools/input_gen/CMakeLists.txt new file mode 100644 index 0000000000..54af0c93b4 --- /dev/null +++ b/src/tools/input_gen/CMakeLists.txt @@ -0,0 +1,26 @@ +add_executable(namelist_gen) +add_executable(streams_gen) + +target_sources(namelist_gen + PUBLIC + namelist_gen.c + test_functions.c + ) + +target_sources(streams_gen + PUBLIC + streams_gen.c + test_functions.c + ) + + +# +# Add include paths and libraries from packages that are internally built by MPAS +# In particular, the ezxml library is needed by the namelist_gen and streams_gen tools +# +get_property(MPAS_INTERNAL_INCLUDE_DIRS GLOBAL PROPERTY MPAS_INTERNAL_INCLUDE_DIRS) +get_property(MPAS_INTERNAL_LIBRARIES GLOBAL PROPERTY MPAS_INTERNAL_LIBRARIES) +target_include_directories(namelist_gen PRIVATE ${MPAS_INTERNAL_INCLUDE_DIRS}) +target_include_directories(streams_gen PRIVATE ${MPAS_INTERNAL_INCLUDE_DIRS}) +target_link_libraries(namelist_gen PRIVATE ${MPAS_INTERNAL_LIBRARIES}) +target_link_libraries(streams_gen PRIVATE ${MPAS_INTERNAL_LIBRARIES}) diff --git a/src/tools/registry/CMakeLists.txt b/src/tools/registry/CMakeLists.txt new file mode 100644 index 0000000000..4df29ed2b5 --- /dev/null +++ b/src/tools/registry/CMakeLists.txt @@ -0,0 +1,35 @@ +find_package(Git) +if(GIT_FOUND) + execute_process(COMMAND ${GIT_EXECUTABLE} describe --dirty + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + OUTPUT_VARIABLE MPAS_GIT_VERSION + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + ) +else() + set(MPAS_GIT_VERSION "Unknown") +endif() + +add_executable(parse) + +target_compile_definitions(parse PUBLIC MPAS_NAMELIST_SUFFIX=${MPAS_CORE}) +target_compile_definitions(parse PUBLIC MPAS_GIT_VERSION=${MPAS_GIT_VERSION}) +target_compile_definitions(parse PUBLIC MPAS_EXE_NAME=${MPAS_EXE_NAME}) +target_compile_definitions(parse PUBLIC MPAS_BUILD_TARGET=${MPAS_COMPILER}) + +target_sources(parse + PUBLIC + dictionary.c + fortprintf.c + gen_inc.c + parse.c + utility.c) + +# +# Add include paths and libraries from packages that are internally built by MPAS +# In particular, the ezxml library is needed by the parse tool +# +get_property(MPAS_INTERNAL_INCLUDE_DIRS GLOBAL PROPERTY MPAS_INTERNAL_INCLUDE_DIRS) +get_property(MPAS_INTERNAL_LIBRARIES GLOBAL PROPERTY MPAS_INTERNAL_LIBRARIES) +target_include_directories(parse PRIVATE ${MPAS_INTERNAL_INCLUDE_DIRS}) +target_link_libraries(parse PRIVATE ${MPAS_INTERNAL_LIBRARIES})