From 759973a75f99ed1d3e1c5d0bdae32d2f528ef233 Mon Sep 17 00:00:00 2001 From: Harshula Jayasuriya Date: Thu, 1 Aug 2024 15:29:50 +1000 Subject: [PATCH] Copy upstream CMakeLists.txt, FMS.pc.in and FMSConfig.cmake.in --- CMakeLists.txt | 547 +++++++++++++++++++++++++++++++++++++++------ FMS.pc.in | 41 ++++ FMSConfig.cmake.in | 75 +++++++ 3 files changed, 595 insertions(+), 68 deletions(-) create mode 100644 FMS.pc.in create mode 100644 FMSConfig.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index ab0bf5ae08..9e4aebb4ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,81 +1,492 @@ -cmake_minimum_required(VERSION 3.6) -project(FMS C Fortran) - -# make sure that the default is a RELWITHDEBINFO -if (NOT CMAKE_BUILD_TYPE) - set (CMAKE_BUILD_TYPE RELWITHDEBINFO CACHE STRING - "Choose the type of build, options are: Debug Release Relwithdebinfo." - FORCE) -endif() -message("Build type: " ${CMAKE_BUILD_TYPE}) - -find_package(MPI) -if(NOT MPI_FOUND) - # On NCI systems the MPI compiler is a wrapper script that adds compiler specific - # paths based on the loaded modules. Set MPIFORT_EXE and MPICC_EXE to the paths - # to these scripts and all should be well - if (DEFINED ENV{MPIFORT_EXE}) - message("mpifort executable found: " $ENV{MPIFORT_EXE}) - message("Will assume system MPI implementation is sound. Remove MPIFORT_EXE from environment to automatically configure MPI") - set(MPI_FORTRAN_COMPILER $ENV{MPIFORT_EXE}) - set(CMAKE_Fortran_COMPILER $ENV{MPIFORT_EXE}) - else () - message("Could not find Fortran MPI. Will continue and hope for the best") - endif() - if (DEFINED ENV{MPICC_EXE}) - message("mpicc executable found: " $ENV{MPICC_EXE}) - message("Will assume system MPI implementation is sound. Remove MPICC_EXE from environment to automatically configure MPI") - set(MPI_C_COMPILER $ENV{MPICC_EXE}) - set(CMAKE_C_COMPILER $ENV{MPICC_EXE}) - else () - message("Could not find C MPI. Will continue and hope for the best") - endif() +#*********************************************************************** +#* GNU Lesser General Public License +#* +#* This file is part of the GFDL Flexible Modeling System (FMS). +#* +#* FMS is free software: you can redistribute it and/or modify it under +#* the terms of the GNU Lesser General Public License as published by +#* the Free Software Foundation, either version 3 of the License, or (at +#* your option) any later version. +#* +#* FMS is distributed in the hope that it will be useful, but WITHOUT +#* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +#* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +#* for more details. +#* +#* You should have received a copy of the GNU Lesser General Public +#* License along with FMS. If not, see . +#*********************************************************************** + +# Copyright (c) GFDL, @underwoo + +cmake_minimum_required(VERSION 3.12 FATAL_ERROR) + +# Define the CMake project +project(FMS + VERSION 2025.01.0 + DESCRIPTION "GFDL FMS Library" + HOMEPAGE_URL "https://www.gfdl.noaa.gov/fms" + LANGUAGES C Fortran) + +include(GNUInstallDirs) + +if(NOT CMAKE_BUILD_TYPE MATCHES "^(Debug|Release|RelWithDebInfo|MinSizeRel)$") + message(STATUS "Setting build type to 'Release' as none was specified.") + set(CMAKE_BUILD_TYPE + "Release" + CACHE STRING "Choose the type of build." FORCE) + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") +endif() + +if(NOT CMAKE_C_COMPILER_ID MATCHES "^(Intel|GNU|Clang|IntelLLVM)$") + message( + WARNING "Compiler not officially supported: ${CMAKE_C_COMPILER_ID}") +endif() + +if(NOT CMAKE_Fortran_COMPILER_ID MATCHES "^(Intel|GNU|IntelLLVM)$") + message( + WARNING "Compiler not officially supported: ${CMAKE_Fortran_COMPILER_ID}") +endif() + +# Append directory that contains CMake Modules for building FMS +list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) + +# Build options +option(OPENMP "Build FMS with OpenMP support" OFF) +option(32BIT "Build 32-bit (r4) FMS library" ON) +option(64BIT "Build 64-bit (r8) FMS library" OFF) +option(FPIC "Build with position independent code" OFF) +option(SHARED_LIBS "Build shared/dynamic libraries" OFF) + +# Options for compiler definitions +option(INTERNAL_FILE_NML "Enable compiler definition -DINTERNAL_FILE_NML" ON) +option(ENABLE_QUAD_PRECISION "Enable compiler definition -DENABLE_QUAD_PRECISION" ON) +option(PORTABLE_KINDS "Enable compiler definition -DPORTABLE_KINDS" OFF) +option(GFS_PHYS "Enable compiler definition -DGFS_PHYS" OFF) +option(LARGEFILE "Enable compiler definition -Duse_LARGEFILE" OFF) +option(WITH_YAML "Enable compiler definition -Duse_yaml" OFF) +option(USE_DEPRECATED_IO "Enable compiler definition -Duse_deprecated_io (compile with fms_io/mpp_io)" OFF) + +if(32BIT) + list(APPEND kinds "r4") +endif() +if(64BIT) + list(APPEND kinds "r8") +endif() +if(NOT kinds) + message(STATUS "Single Precision 32BIT: ${32BIT}") + message(STATUS "Double Precision 64BIT: ${64BIT}") + message(FATAL_ERROR "Either 32BIT or 64BIT should be ON") +endif() + +# Find dependencies +find_package(MPI REQUIRED COMPONENTS C Fortran) +find_package(NetCDF REQUIRED COMPONENTS C Fortran) + +# Check for the OpenMP library and set the required compile flags +if (OPENMP) + find_package(OpenMP REQUIRED COMPONENTS C Fortran) endif() -include_directories(${MPI_Fortran_INCLUDE_PATH}) -add_compile_options(${MPI_Fortran_COMPILE_FLAGS}) +if (WITH_YAML) + find_package(libyaml REQUIRED) + include_directories(${LIBYAML_INCLUDE_DIR}) +endif () + +# Enables position independent code (i.e., -fPIC) +if (FPIC) + set(CMAKE_POSITION_INDEPENDENT_CODE ON) +endif () + +# Collect FMS Fortran source files +list(APPEND fms_fortran_src_files + affinity/fms_affinity.F90 + amip_interp/amip_interp.F90 + astronomy/astronomy.F90 + axis_utils/axis_utils.F90 + axis_utils/axis_utils2.F90 + block_control/block_control.F90 + column_diagnostics/column_diagnostics.F90 + constants/constants.F90 + constants/fmsconstants.F90 + constants4/constantsr4.F90 + constants4/fmsconstantsr4.F90 + coupler/atmos_ocean_fluxes.F90 + coupler/coupler_types.F90 + coupler/ensemble_manager.F90 + data_override/get_grid_version.F90 + data_override/data_override.F90 + diag_integral/diag_integral.F90 + diag_manager/diag_axis.F90 + diag_manager/diag_data.F90 + diag_manager/diag_grid.F90 + diag_manager/diag_manager.F90 + diag_manager/diag_output.F90 + diag_manager/diag_table.F90 + diag_manager/diag_util.F90 + diag_manager/fms_diag_time_utils.F90 + diag_manager/fms_diag_object.F90 + diag_manager/fms_diag_yaml.F90 + diag_manager/fms_diag_file_object.F90 + diag_manager/fms_diag_field_object.F90 + diag_manager/fms_diag_axis_object.F90 + diag_manager/fms_diag_output_buffer.F90 + diag_manager/fms_diag_input_buffer.F90 + diag_manager/fms_diag_time_reduction.F90 + diag_manager/fms_diag_outfield.F90 + diag_manager/fms_diag_elem_weight_procs.F90 + diag_manager/fms_diag_fieldbuff_update.F90 + diag_manager/fms_diag_bbox.F90 + diag_manager/fms_diag_reduction_methods.F90 + drifters/cloud_interpolator.F90 + drifters/drifters.F90 + drifters/drifters_comm.F90 + drifters/drifters_core.F90 + drifters/drifters_input.F90 + drifters/drifters_io.F90 + drifters/quicksort.F90 + exchange/stock_constants.F90 + exchange/xgrid.F90 + field_manager/field_manager.F90 + field_manager/fm_util.F90 + field_manager/fm_yaml.F90 + fms/fms_io.F90 + fms/fms.F90 + fms2_io/blackboxio.F90 + fms2_io/fms_io_utils.F90 + fms2_io/fms_netcdf_domain_io.F90 + fms2_io/fms_netcdf_unstructured_domain_io.F90 + fms2_io/fms2_io.F90 + fms2_io/netcdf_io.F90 + horiz_interp/horiz_interp_bicubic.F90 + horiz_interp/horiz_interp_bilinear.F90 + horiz_interp/horiz_interp_conserve.F90 + horiz_interp/horiz_interp_spherical.F90 + horiz_interp/horiz_interp_type.F90 + horiz_interp/horiz_interp.F90 + interpolator/interpolator.F90 + memutils/memutils.F90 + monin_obukhov/monin_obukhov_inter.F90 + monin_obukhov/monin_obukhov.F90 + grid_utils/gradient.F90 + mosaic2/grid2.F90 + mosaic2/mosaic2.F90 + mpp/mpp.F90 + mpp/mpp_data.F90 + mpp/mpp_domains.F90 + mpp/mpp_efp.F90 + mpp/mpp_io.F90 + mpp/mpp_memutils.F90 + mpp/mpp_parameter.F90 + mpp/mpp_utilities.F90 + parser/yaml_parser.F90 + parser/fms_yaml_output.F90 + platform/platform.F90 + random_numbers/mersennetwister.F90 + random_numbers/random_numbers.F90 + sat_vapor_pres/sat_vapor_pres_k.F90 + sat_vapor_pres/sat_vapor_pres.F90 + string_utils/fms_string_utils.F90 + time_interp/time_interp_external.F90 + time_interp/time_interp_external2.F90 + time_interp/time_interp.F90 + time_manager/get_cal_time.F90 + time_manager/time_manager.F90 + topography/gaussian_topog.F90 + topography/topography.F90 + tracer_manager/tracer_manager.F90 + tridiagonal/tridiagonal.F90 + libFMS.F90 +) + +# Collect FMS C source files +list(APPEND fms_c_src_files + affinity/affinity.c + fms/fms_stacksize.c + grid_utils/gradient_c2l.c + grid_utils/grid_utils.c + grid_utils/tree_utils.c + horiz_interp/include/horiz_interp_conserve_xgrid.c + mpp/mpp_memuse.c + parser/yaml_parser_binding.c + parser/yaml_output_functions.c + string_utils/fms_string_utils_binding.c +) + +# Collect FMS header files +list(APPEND fms_header_files + include/file_version.h + include/fms_platform.h +) -message("Using Fortran: ${CMAKE_Fortran_COMPILER_ID} ${CMAKE_Fortran_COMPILER} and C: ${CMAKE_C_COMPILER_ID} ${CMAKE_C_COMPILER}") +# Standard FMS compiler definitions +list(APPEND fms_defs + use_libMPI + use_netCDF) -if(CMAKE_Fortran_COMPILER_ID STREQUAL "Intel") - set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -fno-alias -stack-temps -safe-cray-ptr -ftz -assume byterecl -i4 -r8 -nowarn -sox -traceback") - set(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} -O2 -fp-model source") - set(CMAKE_Fortran_FLAGS_RELWITHDEBINFO "${CMAKE_Fortran_FLAGS_RELWITHDEBINFO} -g") - set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} -g -O0 -check -check noarg_temp_created -check nopointer -warn -warn noerrors -fpe0 -ftrapuv") -elseif(CMAKE_Fortran_COMPILER_ID STREQUAL "GNU") - set(CMAKE_Fortran_FLAGS "${CMAKE_Fortran_FLAGS} -no-pie -fcray-pointer -fdefault-real-8 -ffree-line-length-none -fno-range-check") - set(CMAKE_Fortran_FLAGS_RELEASE "${CMAKE_Fortran_FLAGS_RELEASE} -O2") - set(CMAKE_Fortran_FLAGS_RELWITHDEBINFO "${CMAKE_Fortran_FLAGS_RELWITHDEBINFO} -g") - set(CMAKE_Fortran_FLAGS_DEBUG "${CMAKE_Fortran_FLAGS_DEBUG} -O0 -g -Wuninitialized -fcheck=bounds -Werror -ffpe-trap=invalid,zero,overflow") -else () - message ("Unknown FORTRAN compiler default flags only...") +# check gettid +include(CheckFunctionExists) +check_function_exists(gettid HAVE_GETTID) +if(HAVE_GETTID) + list(APPEND fms_defs HAVE_GETTID) endif() -if(CMAKE_C_COMPILER_ID STREQUAL "Intel") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -sox -traceback") - set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -debug") - set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2 -debug minimal") -elseif(CMAKE_C_COMPILER_ID STREQUAL "GNU") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -frecord-gcc-switches") - set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0 -Werror -Wuninitialized -Wno-stringop-overflow") - set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -O2") -else () - message ("Unknown C compiler default flags only...") +# Additional (optional) compiler definitions +if(NOT CONSTANTS) + set(CONSTANTS GFDL) +endif() +if(CONSTANTS STREQUAL "GFS") + list(APPEND fms_defs GFS_CONSTANTS) +elseif(CONSTANTS STREQUAL "GEOS") + list(APPEND fms_defs GEOS_CONSTANTS) +elseif(CONSTANTS STREQUAL "GFDL") + list(APPEND fms_defs GFDL_CONSTANTS) +else() + message(FATAL_ERROR "CONSTANTS=${CONSTANTS} option not supported") endif() -string(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE) -message("Using Fortran flags: ${CMAKE_Fortran_FLAGS} ${CMAKE_Fortran_FLAGS_${BUILD_TYPE}}") -message("Using C flags: ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${BUILD_TYPE}}") +if(GFS_PHYS) + list(APPEND fms_defs GFS_PHYS) +endif() -add_definitions(-Duse_libMPI -Duse_netCDF -Duse_LARGEFILE -DSPMD -D__IFC) +if(WITH_YAML) + list(APPEND fms_defs use_yaml) +endif() -set(FMS_DIR "${CMAKE_CURRENT_SOURCE_DIR}") +if(USE_DEPRECATED_IO) + message( WARNING "fms_io WILL BE DEPRECATED IN A FUTURE RELEASE. PLEASE UPDATE TO USE FMS2_IO AND REMOVE " + "-DUSE_DEPRECATED_IO=on FROM YOUR OPTIONS") + list(APPEND fms_defs use_deprecated_io) +endif() -# FMS static library -file(GLOB_RECURSE FMS_SOURCE LIST_DIRECTORIES false - ${FMS_DIR}/*.[fF]90 ${FMS_DIR}/*.c) +if(INTERNAL_FILE_NML) + list(APPEND fms_defs INTERNAL_FILE_NML) +endif() + +if(ENABLE_QUAD_PRECISION) + list(APPEND fms_defs ENABLE_QUAD_PRECISION) +endif() + +if(PORTABLE_KINDS) + list(APPEND fms_defs PORTABLE_KINDS) +endif() + +if(LARGEFILE) + list(APPEND fms_defs use_LARGEFILE) +endif() + +# Precision-based compiler definitions +if(32BIT) + list(APPEND r4_defs OVERLOAD_R4 OVERLOAD_R8) +endif() + +# Add platform specific compiler definitions +if(APPLE) + list(APPEND fms_defs __APPLE__) +endif() + +# Obtain compiler-specific flags +include(fms_compiler_flags) + +foreach(kind ${kinds}) + + set(libTgt fms_${kind}) + set(includeDir "include_${kind}") + set(moduleDir "${CMAKE_CURRENT_BINARY_DIR}/${includeDir}") + + # C + add_library(${libTgt}_c OBJECT ${fms_c_src_files}) + + target_include_directories(${libTgt}_c PRIVATE include + grid_utils) + target_compile_definitions(${libTgt}_c PRIVATE "${fms_defs}") + + target_link_libraries(${libTgt}_c PRIVATE NetCDF::NetCDF_C + MPI::MPI_C) + + if(OpenMP_C_FOUND) + target_link_libraries(${libTgt}_c PRIVATE OpenMP::OpenMP_C) + endif() + + # Fortran + add_library(${libTgt}_f OBJECT ${fms_fortran_src_files}) + + target_include_directories(${libTgt}_f PRIVATE include + fms + fms/include + fms2_io/include + string_utils/include + mpp/include + column_diagnostics/include + monin_obukhov/include + sat_vapor_pres/include + horiz_interp/include + diag_integral/include + random_numbers/include + diag_manager/include + constants4 + topography/include + axis_utils/include + mosaic2/include + constants + astronomy/include + field_manager/include + time_interp/include + tracer_manager/include + tridiagonal/include + interpolator/include + coupler/include + data_override/include + amip_interp/include) + + target_compile_definitions(${libTgt}_f PRIVATE "${fms_defs}") + target_compile_definitions(${libTgt}_f PRIVATE "${${kind}_defs}") + + set_target_properties(${libTgt}_f PROPERTIES COMPILE_FLAGS "${${kind}_flags}") + + set_target_properties(${libTgt}_f PROPERTIES Fortran_MODULE_DIRECTORY + ${moduleDir}) + + target_link_libraries(${libTgt}_f PRIVATE NetCDF::NetCDF_Fortran + MPI::MPI_Fortran) + + if(OpenMP_Fortran_FOUND) + target_link_libraries(${libTgt}_f PRIVATE OpenMP::OpenMP_Fortran) + endif() + + # Check if gnu 10 or higher + # this should only be needed with mpich, but wasn't able to find a good way to find the MPI flavor consistently + if ( CMAKE_Fortran_COMPILER_VERSION MATCHES "1[0-9]\.[0-9]*\.[0-9]*" AND CMAKE_Fortran_COMPILER_ID MATCHES "GNU") + include(CheckFortranCompilerFlag) + check_fortran_compiler_flag("-fallow-argument-mismatch" _arg_mismatch_flag) + if(_arg_mismatch_flag) + message(STATUS "Adding -fallow-argument-mismatch flag to compile with GCC >=10 and MPICH") + target_compile_options(${libTgt}_f PRIVATE "-fallow-argument-mismatch;-w") + endif() + endif() + + # FMS (C + Fortran) + if (SHARED_LIBS) + message(STATUS "Shared library target: ${libTgt}") + add_library(${libTgt} SHARED $ + $) + else () + message(STATUS "Static library target: ${libTgt}") + add_library(${libTgt} STATIC $ + $) + endif () + + target_include_directories(${libTgt} PUBLIC + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $ + $) + + target_include_directories(${libTgt} INTERFACE + $ + $) + + target_compile_definitions(${libTgt} PRIVATE "${fms_defs}") + target_compile_definitions(${libTgt} PRIVATE "${${kind}_defs}") + + target_link_libraries(${libTgt} PUBLIC NetCDF::NetCDF_C + NetCDF::NetCDF_Fortran + MPI::MPI_Fortran) + + if(OpenMP_Fortran_FOUND) + target_link_libraries(${libTgt} PRIVATE OpenMP::OpenMP_C OpenMP::OpenMP_Fortran) + endif() + + add_library(FMS::${libTgt} ALIAS ${libTgt}) + + list(APPEND LIB_TARGETS ${libTgt}) + install(DIRECTORY ${moduleDir} DESTINATION ${CMAKE_INSTALL_PREFIX}) + install(FILES ${fms_header_files} DESTINATION ${CMAKE_INSTALL_PREFIX}/${includeDir}) + +endforeach() + +install( + TARGETS ${LIB_TARGETS} + EXPORT FMSExports + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}) + +### Package config +include(CMakePackageConfigHelpers) +set(CONFIG_INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/fms) + +export(EXPORT FMSExports + NAMESPACE FMS:: + FILE fms-targets.cmake) + +configure_package_config_file( + ${CMAKE_CURRENT_SOURCE_DIR}/FMSConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/fms-config.cmake + INSTALL_DESTINATION ${CONFIG_INSTALL_DESTINATION}) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/fms-config.cmake + DESTINATION ${CONFIG_INSTALL_DESTINATION}) + +write_basic_package_version_file( + ${CMAKE_CURRENT_BINARY_DIR}/fms-config-version.cmake + VERSION ${PROJECT_VERSION} + COMPATIBILITY AnyNewerVersion) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/fms-config-version.cmake + DESTINATION ${CONFIG_INSTALL_DESTINATION}) + +install(EXPORT FMSExports + NAMESPACE FMS:: + FILE fms-targets.cmake + DESTINATION ${CONFIG_INSTALL_DESTINATION}) + +# pkgconf +set(prefix ${CMAKE_INSTALL_PREFIX}) +set(exec_prefix ${CMAKE_INSTALL_PREFIX}) +set(libdir ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) +set(includedir ${CMAKE_INSTALL_PREFIX}/${includeDir}) + +set(CC ${CMAKE_C_COMPILER}) +set(FC ${CMAKE_Fortran_COMPILER}) +set(CFLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE}}") +set(CPPFLAGS "${CMAKE_CPP_FLAGS} ${CMAKE_CPP_FLAGS_${CMAKE_BUILD_TYPE}}") +set(FCFLAGS "${CMAKE_Fortran_FLAGS} ${CMAKE_Fortran_FLAGS_${CMAKE_BUILD_TYPE}}") +set(LDFLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS_${CMAKE_BUILD_TYPE}}") + +set(VERSION ${PROJECT_VERSION}) + +# TODO: If FMS depends on a library that is built as a static library, it +# should be listed here as an ldflag. +set(LIBS "") + +if(NOT ${NetCDF_Fortran_LIBRARY_SHARED}) + # autotools: Libs.private: -lnetcdff -lnetcdf + string(APPEND LIBS ${NetCDF_Fortran_LIBRARIES}) +endif() -add_library(FMS ${FMS_SOURCE}) +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/FMS.pc.in + ${CMAKE_CURRENT_BINARY_DIR}/FMS.pc @ONLY) -target_include_directories(FMS PRIVATE - /usr/include ${FMS_DIR}/include ${FMS_DIR}/mosaic ${FMS_DIR}/drifters ${FMS_DIR}/fms ${FMS_DIR}/mpp/include) +install(FILES ${CMAKE_CURRENT_BINARY_DIR}/FMS.pc + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig + COMPONENT utilities) diff --git a/FMS.pc.in b/FMS.pc.in new file mode 100644 index 0000000000..c9f2a96e5c --- /dev/null +++ b/FMS.pc.in @@ -0,0 +1,41 @@ +#*********************************************************************** +#* GNU Lesser General Public License +#* +#* This file is part of the GFDL Flexible Modeling System (FMS). +#* +#* FMS is free software: you can redistribute it and/or modify it under +#* the terms of the GNU Lesser General Public License as published by +#* the Free Software Foundation, either version 3 of the License, or (at +#* your option) any later version. +#* +#* FMS is distributed in the hope that it will be useful, but WITHOUT +#* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +#* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +#* for more details. +#* +#* You should have received a copy of the GNU Lesser General Public +#* License along with FMS. If not, see . +#*********************************************************************** + +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +# Including the following, as they may be useful when building other components +# and as a way to better record how the library was built. +ccompiler=@CC@ +fccompiler=@FC@ +cppflagss.compiled=@CPPFLAGS@ +cflags.compiled=@CFLAGS@ +fcflags.compiled=@FCFLAGS@ +ldflags.compiled=@LDFLAGS@ + +Name: FMS +Description: The Flexible Modeling System Infrastructure Library +URL: https://www.gfdl.noaa.gov/fms +Version: @VERSION@ +Libs: -L${libdir} -lFMS +Libs.private: @LIBS@ +Cflags: -I${includedir} +Fflags: -I${includedir} diff --git a/FMSConfig.cmake.in b/FMSConfig.cmake.in new file mode 100644 index 0000000000..27e059cfbf --- /dev/null +++ b/FMSConfig.cmake.in @@ -0,0 +1,75 @@ +@PACKAGE_INIT@ + +#fms-config.cmake +# +# Valid Find COMPONENTS: +# * R4 - 32-bit library +# * R8 - 64-bit library +# +# Imported interface targets provided: +# * FMS::fms_r4 - real32 library target +# * FMS::fms_r8 - real64 library target + +# Include targets file. This will create IMPORTED target fms +include("${CMAKE_CURRENT_LIST_DIR}/fms-targets.cmake") +include("${CMAKE_CURRENT_LIST_DIR}/fms-config-version.cmake") +include(CMakeFindDependencyMacro) + +find_dependency(MPI COMPONENTS Fortran) + +# ON/OFF implies FMS was compiled with/without OpenMP +if(@OPENMP@) + find_dependency(OpenMP COMPONENTS Fortran) +endif() + +find_dependency(NetCDF COMPONENTS C Fortran) + +set(FMSVersion "${PACKAGE_VERSION}") +set_and_check(FMS_INSTALL_PREFIX "${PACKAGE_PREFIX_DIR}") + +list(APPEND _possible_fms_components "R4" "R8") +foreach(_comp ${_possible_fms_components}) + set(_name_${_comp} ${_comp}) +endforeach() + +#R4 is the default component +if(NOT FMS_FIND_COMPONENTS) + list(APPEND _search_fms_components "R4") +endif() +foreach(_comp ${FMS_FIND_COMPONENTS}) + list(APPEND _search_fms_components ${_comp}) + if(NOT _name_${_comp}) + message(SEND_ERROR "FMS: COMPONENT ${_comp} is not a valid component. Valid components: ${_possible_fms_components}") + endif() +endforeach() +list(REMOVE_DUPLICATES _search_fms_components) + +# ON/OFF implies FMS was compiled with/without 32BIT option +set(FMS_R4_FOUND 0) +if(@32BIT@) + set(FMS_R4_FOUND 1) + get_property(FMS_R4_LIBRARIES TARGET FMS::fms_r4 PROPERTY LOCATION) + get_target_property(FMS_BUILD_TYPES FMS::fms_r4 IMPORTED_CONFIGURATIONS) + list(APPEND FMS_POSSIBLE_COMPONENTS R4) +endif() + +# ON/OFF implies FMS was compiled with/without 64BIT option +set(FMS_R8_FOUND 0) +if(@64BIT@) + set(FMS_R8_FOUND 1) + get_property(FMS_R8_LIBRARIES TARGET FMS::fms_r8 PROPERTY LOCATION) + get_target_property(FMS_BUILD_TYPES FMS::fms_r8 IMPORTED_CONFIGURATIONS) +endif() + +check_required_components("FMS") + +message(STATUS "Found FMS: \"${FMS_INSTALL_PREFIX}\" (Version: \"${FMSVersion}\")") +message( STATUS "FMS targets:" ) +foreach(component ${_search_fms_components}) + string( TOLOWER "${component}" _component ) + if(FMS_${component}_FOUND) + message(STATUS " - FMS::fms_${_component} [Lib: ${FMS_${component}_LIBRARIES}]") + else() + message(STATUS " - FMS::fms_${_component} [COMPONENT ${component} NOT FOUND]") + endif() +endforeach()