diff --git a/CHANGELOG.md b/CHANGELOG.md index 4cf611f2..3f337e17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add explicit `find_package()` calls for missing dependencies for MAPL for builds with spack-stack. Will eventually be fixed in MAPL in later versions - Corrected the units of the gravimetric soil moisture to percent instead of fractional in the FENGSHA dust scheme. +- Fix issue of GOCART/GEOSgcm circular CMake dependencies when used as external project ### Added diff --git a/CMakeLists.txt b/CMakeLists.txt index d59c2b4c..b3cb6d8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,24 +2,42 @@ cmake_minimum_required (VERSION 3.17) cmake_policy (SET CMP0053 NEW) cmake_policy (SET CMP0054 NEW) -project ( - GOCART - VERSION 2.2.1 - LANGUAGES Fortran CXX C) # Note - CXX is required for ESMF - -if ("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}") - message(SEND_ERROR "In-source builds are disabled. Please - issue cmake command in separate build directory.") -endif ("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}") - -# Set the default build type to release -if (NOT CMAKE_BUILD_TYPE) - 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 the possible values of build type for cmake-gui - set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS - "Debug" "Release" "MinSizeRel" "RelWithDebInfo") -endif () +# Let's look for the ESMA cmake directory in a few places +# to see if we are building standalone +set (ESMA_CMAKE_DIRS + cmake + @cmake + cmake@ + ) + +foreach (dir IN LISTS ESMA_CMAKE_DIRS) + if (EXISTS ${CMAKE_CURRENT_LIST_DIR}/${dir}) + list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/${dir}") + set (ESMA_CMAKE_PATH "${CMAKE_CURRENT_LIST_DIR}/${dir}" CACHE PATH "Path to ESMA_cmake code") + set(GOCART_STANDALONE TRUE) + endif () +endforeach () + +if (GOCART_STANDALONE) + project ( + GOCART + VERSION 2.2.1 + LANGUAGES Fortran CXX C) # Note - CXX is required for ESMF + + if ("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}") + message(SEND_ERROR "In-source builds are disabled. Please + issue cmake command in separate build directory.") + endif ("${PROJECT_SOURCE_DIR}" STREQUAL "${PROJECT_BINARY_DIR}") + + # Set the default build type to release + if (NOT CMAKE_BUILD_TYPE) + 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 the possible values of build type for cmake-gui + set_property (CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS + "Debug" "Release" "MinSizeRel" "RelWithDebInfo") + endif () +endif() # Set build options option (UFS_GOCART "Build GOCART component for UFS" OFF) @@ -41,11 +59,12 @@ if (UFS_GOCART) endif() if (NOT COMMAND esma) - list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake@") include (esma) endif() -ecbuild_declare_project() +if(GOCART_STANDALONE) + ecbuild_declare_project() +endif() if (NOT Baselibs_FOUND) # Find dependencies @@ -87,7 +106,9 @@ include_directories(${MPI_Fortran_INCLUDE_PATH}) add_subdirectory (ESMF) add_subdirectory (Process_Library) -ecbuild_install_project (NAME GOCART) +if(GOCART_STANDALONE) + ecbuild_install_project (NAME GOCART) +endif() # https://www.scivision.dev/cmake-auto-gitignore-build-dir/ # --- auto-ignore build directory diff --git a/ESMF/Shared/CMakeLists.txt b/ESMF/Shared/CMakeLists.txt index e9a3f721..4763e354 100644 --- a/ESMF/Shared/CMakeLists.txt +++ b/ESMF/Shared/CMakeLists.txt @@ -12,10 +12,12 @@ if( EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/@GSW ) set (gsw_ECBUILD_SYSTEM_INCLUDED TRUE) endif() -if ( IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/MAPL@ ) - esma_add_subdirectories ( - MAPL - ) +if (NOT TARGET MAPL) + if ( IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/MAPL@ ) + esma_add_subdirectories ( + MAPL + ) + endif () endif () if ( IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/GMAO_Shared@ )