|
| 1 | +#*********************************************************************** |
| 2 | +#* Apache License 2.0 |
| 3 | +#* |
| 4 | +#* This file is part of the GFDL Flexible Modeling System (FMS). |
| 5 | +#* |
| 6 | +#* Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +#* you may not use this file except in compliance with the License. |
| 8 | +#* You may obtain a copy of the License at |
| 9 | +#* |
| 10 | +#* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +#* |
| 12 | +#* FMS is distributed in the hope that it will be useful, but WITHOUT |
| 13 | +#* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied; |
| 14 | +#* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A |
| 15 | +#* PARTICULAR PURPOSE. See the License for the specific language |
| 16 | +#* governing permissions and limitations under the License. |
| 17 | +#*********************************************************************** |
| 18 | + |
| 19 | +cmake_minimum_required(VERSION 3.12 FATAL_ERROR) |
| 20 | + |
| 21 | +# Build options |
| 22 | +option(PORTABLE_KINDS "Enable compiler defition -DPORTABLE_KINDS" ON) |
| 23 | +option(WITH_YAML "Enable compiler definition -Duse_yaml" ON) |
| 24 | +option(CFMS_TESTS "Enable compiling of test scripts" OFF) |
| 25 | +set(CMAKE_POSITION_INDEPENDENT_CODE ON) |
| 26 | + |
| 27 | +include(FetchContent) |
| 28 | + |
| 29 | +#Define the cmake project |
| 30 | +project(cFMS |
| 31 | + VERSION 2026.01.0 |
| 32 | + DESCRIPTION "C Access to GFDL FMS Library" |
| 33 | + HOMEPAGE_URL "https://github.com/NOAA-GFDL/cFMS" |
| 34 | + LANGUAGES C Fortran) |
| 35 | + |
| 36 | +if(NOT CMAKE_C_COMPILER_ID MATCHES "^(Intel|GNU|Clang|IntelLLVM)$") |
| 37 | + message( |
| 38 | + WARNING "Compiler not officially supported: ${CMAKE_C_COMPILER_ID)}" |
| 39 | + ) |
| 40 | +endif() |
| 41 | + |
| 42 | +if(NOT CMAKE_Fortran_COMPILER_ID MATCHES "^(Intel|GNU|IntelLLVM)$") |
| 43 | + message( |
| 44 | + WARNING "Compiler not officially supported: ${CMAKE_Fortran_COMPILER_ID}" |
| 45 | + ) |
| 46 | +endif() |
| 47 | + |
| 48 | +# Find dependencies |
| 49 | + |
| 50 | +FetchContent_Declare( |
| 51 | + FMS |
| 52 | + GIT_REPOSITORY https://github.com/NOAA-GFDL/FMS.git |
| 53 | + GIT_TAG 043ab2f6037af92997aa72a467430e95c03652ae |
| 54 | +) |
| 55 | +FetchContent_MakeAvailable(FMS) |
| 56 | + |
| 57 | +list(APPEND cfms_src_files |
| 58 | + c_constants/c_constants.F90 |
| 59 | + c_data_override/c_data_override.F90 |
| 60 | + c_diag_manager/c_diag_manager.F90 |
| 61 | + c_fms/c_fms.F90 |
| 62 | + c_fms_utils/c_fms_utils.F90 |
| 63 | + c_grid_utils/c_grid_utils.F90 |
| 64 | + c_horiz_interp/c_horiz_interp.F90 |
| 65 | +) |
| 66 | + |
| 67 | +list(APPEND cfms_header_files |
| 68 | + c_constants/c_constants.h |
| 69 | + c_data_override/c_data_override.h |
| 70 | + c_diag_manager/c_diag_manager.h |
| 71 | + c_fms/c_fms.h |
| 72 | + c_grid_utils/c_grid_utils.h |
| 73 | + c_horiz_interp/c_horiz_interp.h |
| 74 | +) |
| 75 | + |
| 76 | +add_library(cFMS SHARED |
| 77 | + ${cfms_src_files} |
| 78 | +) |
| 79 | + |
| 80 | +target_link_libraries(cFMS PUBLIC |
| 81 | + FMS::fms |
| 82 | + ${LIBYAML_LIBRARIES} |
| 83 | +) |
| 84 | + |
| 85 | +target_include_directories(cFMS PRIVATE |
| 86 | + c_data_override/include |
| 87 | + c_diag_manager/include |
| 88 | + c_fms/include |
| 89 | + c_fms_utils/include |
| 90 | + c_horiz_interp/include |
| 91 | + ${CMAKE_CURRENT_SOURCE_DIR}/FMS/include |
| 92 | +) |
| 93 | + |
| 94 | +install(TARGETS cFMS |
| 95 | + LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX} |
| 96 | +) |
| 97 | +install(FILES ${cfms_header_files} |
| 98 | + DESTINATION ${CMAKE_INSTALL_PREFIX}/include) |
| 99 | + |
| 100 | +# Tests |
| 101 | +if(CFMS_TESTS) |
| 102 | + enable_testing() |
| 103 | + add_subdirectory(test_cfms) |
| 104 | +endif() |
| 105 | + |
| 106 | + |
| 107 | + |
0 commit comments