Skip to content

Commit

Permalink
Export and install CMake targets and config for ACCESS-OM3 libraries.
Browse files Browse the repository at this point in the history
This required to properly declare headers/module files that are only needed for building.
  • Loading branch information
micaeljtoliveira committed Nov 29, 2023
1 parent 0911d8b commit 5ee073b
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 4 deletions.
11 changes: 10 additions & 1 deletion CDEPS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,27 +102,36 @@ if(OM3_LIB_INSTALL)
# cdeps_common
set_target_properties(OM3_cdeps_common PROPERTIES
OUTPUT_NAME access-cdeps-common
EXPORT_NAME cdeps-common
)
install(TARGETS OM3_cdeps_common
EXPORT AccessOM3cdeps_Targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT AccessOM3_RunTime NAMELINK_COMPONENT AccessOM3_Development
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT AccessOM3_Development
)
# components
foreach(LIB atm ocn ice wav rof)
set_target_properties(OM3_cdeps_d${LIB} PROPERTIES
OUTPUT_NAME access-cdeps-d${LIB}
EXPORT_NAME cdeps-d${LIB}
)
install(TARGETS OM3_cdeps_d${LIB}
EXPORT AccessOM3cdeps_Targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT AccessOM3_RunTime NAMELINK_COMPONENT AccessOM3_Development
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT AccessOM3_Development
)
# Fortran module files are a special case, as currently there is no standard
# way of handling them in CMake
target_include_directories(OM3_cdeps_d${LIB} PUBLIC "$<INSTALL_INTERFACE:${CMAKE_INSTALL_MODULEDIR}/access-d${LIB}>")
target_include_directories(OM3_cdeps_d${LIB} PUBLIC "$<INSTALL_INTERFACE:${CMAKE_INSTALL_MODULEDIR}/access-cdeps-d${LIB}>")
get_target_property(d${LIB}_moddir OM3_cdeps_d${LIB} Fortran_MODULE_DIRECTORY)
install(FILES ${d${LIB}_moddir}/${LIB}_comp_nuopc.mod
DESTINATION ${CMAKE_INSTALL_MODULEDIR}/access-cdeps-d${LIB}
COMPONENT AccessOM3_Development
)
endforeach()
install(EXPORT AccessOM3cdeps_Targets
FILE AccessOM3cdepsTargets.cmake
NAMESPACE AccessOM3::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/AccessOM3
)
endif()
8 changes: 8 additions & 0 deletions CICE/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,10 @@ endif()
if(OM3_LIB_INSTALL)
set_target_properties(OM3_cice PROPERTIES
OUTPUT_NAME access-cice
EXPORT_NAME cice
)
install(TARGETS OM3_cice
EXPORT AccessOM3cice_Targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT AccessOM3_RunTime NAMELINK_COMPONENT AccessOM3_Development
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT AccessOM3_Development
)
Expand All @@ -172,4 +174,10 @@ if(OM3_LIB_INSTALL)
DESTINATION ${CMAKE_INSTALL_MODULEDIR}/access-cice
COMPONENT AccessOM3_Development
)
install(EXPORT AccessOM3cice_Targets
FILE AccessOM3ciceTargets.cmake
NAMESPACE AccessOM3::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/AccessOM3
)

endif()
14 changes: 14 additions & 0 deletions CMEPS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ if(OM3_LIB_INSTALL)
## CMEPS library
set_target_properties(OM3_cmeps PROPERTIES
OUTPUT_NAME access-cmeps
EXPORT_NAME cmeps
)
install(TARGETS OM3_cmeps
EXPORT AccessOM3cmeps_Targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT AccessOM3_RunTime NAMELINK_COMPONENT AccessOM3_Development
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT AccessOM3_Development
)
Expand All @@ -82,12 +84,19 @@ if(OM3_LIB_INSTALL)
DESTINATION ${CMAKE_INSTALL_MODULEDIR}/access-cmeps
COMPONENT AccessOM3_Development
)
install(EXPORT AccessOM3cmeps_Targets
FILE AccessOM3cmepsTargets.cmake
NAMESPACE AccessOM3::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/AccessOM3
)

## NUOPC cap share
set_target_properties(OM3_nuopc_cap_share PROPERTIES
OUTPUT_NAME access-nuopc_cap_share
EXPORT_NAME nuopc_cap_share
)
install(TARGETS OM3_nuopc_cap_share
EXPORT AccessOM3nuopc_cap_share_Targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT AccessOM3_RunTime NAMELINK_COMPONENT AccessOM3_Development
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT AccessOM3_Development
)
Expand All @@ -99,4 +108,9 @@ if(OM3_LIB_INSTALL)
DESTINATION ${CMAKE_INSTALL_MODULEDIR}/access-nuopc_cap_share
COMPONENT AccessOM3_Development
)
install(EXPORT AccessOM3nuopc_cap_share_Targets
FILE AccessOM3nuopc_cap_shareTargets.cmake
NAMESPACE AccessOM3::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/AccessOM3
)
endif()
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ message(STATUS " - OM3_CICE_IO ${OM3_CICE_IO}")

list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
include(GNUInstallDirs)
if(OM3_LIB_INSTALL)
include(CMakePackageConfigHelpers)
endif()

# Include some custom cmake modules
include(FortranLib)
Expand Down Expand Up @@ -238,3 +241,16 @@ if(OM3_BIN_INSTALL)
)
endforeach()
endif()

# Libraries
if(OM3_LIB_INSTALL)
configure_package_config_file(
cmake/AccessOM3Config.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/AccessOM3Config.cmake
INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/AccessOM3
)
install(FILES ${CMAKE_SOURCE_DIR}/cmake/FindFoX.cmake ${CMAKE_CURRENT_BINARY_DIR}/AccessOM3Config.cmake
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/AccessOM3
COMPONENT AccessOM3_Development
)
endif()
7 changes: 7 additions & 0 deletions MOM6/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,10 @@ add_patched_source(OM3_mom6 MOM6/config_src/drivers/nuopc_cap/mom_cap.F90)
if(OM3_LIB_INSTALL)
set_target_properties(OM3_mom6 PROPERTIES
OUTPUT_NAME access-mom6
EXPORT_NAME mom6
)
install(TARGETS OM3_mom6
EXPORT AccessOM3mom6_Targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT AccessOM3_RunTime NAMELINK_COMPONENT AccessOM3_Development
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT AccessOM3_Development
)
Expand All @@ -344,4 +346,9 @@ if(OM3_LIB_INSTALL)
DESTINATION ${CMAKE_INSTALL_MODULEDIR}/access-mom6
COMPONENT AccessOM3_Development
)
install(EXPORT AccessOM3mom6_Targets
FILE AccessOM3mom6Targets.cmake
NAMESPACE AccessOM3::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/AccessOM3
)
endif()
7 changes: 7 additions & 0 deletions WW3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ target_link_libraries(OM3_ww3_ounp PRIVATE AccessOM3::ww3)
if(OM3_LIB_INSTALL)
set_target_properties(OM3_ww3 PROPERTIES
OUTPUT_NAME access-ww3
EXPORT_NAME ww3
)
install(TARGETS OM3_ww3
EXPORT AccessOM3ww3_Targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT AccessOM3_RunTime NAMELINK_COMPONENT AccessOM3_Development
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT AccessOM3_Development
)
Expand All @@ -158,6 +160,11 @@ if(OM3_LIB_INSTALL)
DESTINATION ${CMAKE_INSTALL_MODULEDIR}/access-ww3
COMPONENT AccessOM3_Development
)
install(EXPORT AccessOM3ww3_Targets
FILE AccessOM3ww3Targets.cmake
NAMESPACE AccessOM3::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/AccessOM3
)
endif()

## Utilities
Expand Down
82 changes: 82 additions & 0 deletions cmake/AccessOM3Config.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
@PACKAGE_INIT@

if(NOT AccessOM3_FIND_QUIETLY)
message(STATUS "Found AccessOM3: ${PACKAGE_PREFIX_DIR}")
endif()

# Available components

# The following components are always available (order is important!)
set(_supported_components timing share nuopc_cap_share cmeps cdeps mom6 cice ww3)

# Check validity of requested components
foreach(_comp ${AccessOM3_FIND_COMPONENTS})
if (NOT _comp IN_LIST _supported_components)
set(AccessOM3_FOUND False)
set(AccessOM3_NOT_FOUND_MESSAGE "Unsupported component: ${_comp}")
endif()
endforeach()

# Some components are only available if they were built
if ((mom6 IN_LIST ${AccessOM3_FIND_COMPONENTS}) AND (NOT @OM3_BUILD_MOM6@))
set(AccessOM3_FOUND False)
set(AccessOM3_NOT_FOUND_MESSAGE "The following component is not available: mom6")
endif()
if ((cice IN_LIST ${AccessOM3_FIND_COMPONENTS}) AND (NOT @OM3_BUILD_CICE6@))
set(AccessOM3_FOUND False)
set(AccessOM3_NOT_FOUND_MESSAGE "The following component is not available: cice")
endif()
if ((ww3 IN_LIST ${AccessOM3_FIND_COMPONENTS}) AND (NOT @OM3_BUILD_WW3@))
set(AccessOM3_FOUND False)
set(AccessOM3_NOT_FOUND_MESSAGE "The following component is not available: ww3")
endif()

# Build a list of all the required components, taking into account their dependencies
set(_required_components ${AccessOM3_FIND_COMPONENTS})
if(cice IN_LIST _required_components)
list(APPEND _required_components cdeps nuopc_cap_share share timing)
endif()
if(mom6 IN_LIST _required_components)
list(APPEND _required_components nuopc_cap_share share)
endif()
if(cdeps IN_LIST _required_components)
list(APPEND _required_components cmeps share nuopc_cap_share)
endif()
if(cmeps IN_LIST _required_components)
list(APPEND _required_components nuopc_cap_share share timing)
endif()
if(nuopc_cap_share IN_LIST _required_components)
list(APPEND _required_components share timing)
endif()
if(share IN_LIST _required_components)
list(APPEND _required_components timing)
endif()
list(REMOVE_DUPLICATES _required_components)

if(NOT AccessOM3_FIND_QUIETLY)
message(STATUS " - AccessOM3 Components: ${_required_components}")
endif()

# Include required targets. We do this by looping over the _supported_components
# list because the order in which targets are loaded matters.
foreach(_comp ${_supported_components})
if (_comp IN_LIST _required_components)
include("${CMAKE_CURRENT_LIST_DIR}/AccessOM3${_comp}Targets.cmake")
endif()
endforeach()

# Find dependencies of required components
include(CMakeFindDependencyMacro)

list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})

if (cdeps IN_LIST _required_components)
find_dependency(FoX)
endif()
if (mom6 IN_LIST _required_components)
find_dependency(fms COMPONENTS R8 REQUIRED)
endif()

list(REMOVE_ITEM CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR})

check_required_components(_supported_components)
4 changes: 2 additions & 2 deletions cmake/FortranLib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ function(add_fortran_library LIB MOD_DIR)
get_target_property(LIB_DIR ${LIB} BINARY_DIR)
set_target_properties(${LIB} PROPERTIES Fortran_MODULE_DIRECTORY ${LIB_DIR}/${MOD_DIR})

target_include_directories(${LIB} INTERFACE ${LIB_DIR}/${MOD_DIR})
endfunction(add_fortran_library)
target_include_directories(${LIB} INTERFACE "$<BUILD_INTERFACE:${LIB_DIR}/${MOD_DIR}>")
endfunction(add_fortran_library)
16 changes: 15 additions & 1 deletion share/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## share library
add_fortran_library(OM3_share mod/share STATIC)
add_library(AccessOM3::share ALIAS OM3_share)
target_include_directories(OM3_share PUBLIC CESM_share/include)
target_include_directories(OM3_share PUBLIC "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/CESM_share/include>")
if(CMAKE_Fortran_COMPILER_ID MATCHES "GNU")
target_compile_definitions(OM3_share PRIVATE CPRGNU NAMING=_ADD_UNDERSCORE FORTRANUNDERSCORE)
elseif(CMAKE_Fortran_COMPILER_ID MATCHES "Intel")
Expand Down Expand Up @@ -81,8 +81,10 @@ if(OM3_LIB_INSTALL)
## share library
set_target_properties(OM3_share PROPERTIES
OUTPUT_NAME access-share
EXPORT_NAME share
)
install(TARGETS OM3_share
EXPORT AccessOM3share_Targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT AccessOM3_RunTime NAMELINK_COMPONENT AccessOM3_Development
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT AccessOM3_Development
)
Expand All @@ -94,12 +96,19 @@ if(OM3_LIB_INSTALL)
DESTINATION ${CMAKE_INSTALL_MODULEDIR}/access-share
COMPONENT AccessOM3_Development
)
install(EXPORT AccessOM3share_Targets
FILE AccessOM3shareTargets.cmake
NAMESPACE AccessOM3::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/AccessOM3
)

## timing library
set_target_properties(OM3_timing PROPERTIES
OUTPUT_NAME access-timing
EXPORT_NAME timing
)
install(TARGETS OM3_timing
EXPORT AccessOM3timing_Targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT AccessOM3_RunTime NAMELINK_COMPONENT AccessOM3_Development
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT AccessOM3_Development
)
Expand All @@ -111,4 +120,9 @@ if(OM3_LIB_INSTALL)
DESTINATION ${CMAKE_INSTALL_MODULEDIR}/access-timing
COMPONENT AccessOM3_Development
)
install(EXPORT AccessOM3timing_Targets
FILE AccessOM3timingTargets.cmake
NAMESPACE AccessOM3::
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/AccessOM3
)
endif()

0 comments on commit 5ee073b

Please sign in to comment.