Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CMake circular dependencies for external use #273

Merged
merged 9 commits into from
Aug 12, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
63 changes: 42 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions ESMF/Shared/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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@ )
Expand Down
Loading