From 3fcd94e916680c9c6a04d82956bf2cea0189dad8 Mon Sep 17 00:00:00 2001 From: James Foucar Date: Thu, 28 Sep 2023 16:06:58 -0600 Subject: [PATCH] Guard all Find modules from repetition so users don't have to Fix mpas netcdf dep, should be public --- components/cmake/common_setup.cmake | 6 ++---- components/cmake/modules/FindCsmShare.cmake | 11 +++++++---- components/cmake/modules/FindMCT.cmake | 4 ++++ components/cmake/modules/FindNETCDF.cmake | 4 ++++ components/cmake/modules/FindPIO.cmake | 4 ++++ components/mpas-framework/src/CMakeLists.txt | 3 ++- 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/components/cmake/common_setup.cmake b/components/cmake/common_setup.cmake index d9f47932e7da..adc809293693 100644 --- a/components/cmake/common_setup.cmake +++ b/components/cmake/common_setup.cmake @@ -110,10 +110,8 @@ endif() # Have to do this here for now because the macros must be loaded in order for # the netcdf cmake variables to be set. Once scorpio has a good package-config, # this won't be necessary -if (NOT TARGET netcdf) - find_package(NETCDF REQUIRED) - target_link_libraries(spio INTERFACE netcdf) -endif() +find_package(NETCDF REQUIRED) +target_link_libraries(spio INTERFACE netcdf) # Set HAVE_SLASHPROC on LINUX systems which are not bluegene or Darwin (OSx) string(FIND "${CPPDEFS}" "-DLINUX" HAS_DLINUX) diff --git a/components/cmake/modules/FindCsmShare.cmake b/components/cmake/modules/FindCsmShare.cmake index fef2f95a0285..fa6dd0a8036c 100644 --- a/components/cmake/modules/FindCsmShare.cmake +++ b/components/cmake/modules/FindCsmShare.cmake @@ -11,6 +11,10 @@ # The "csm_share" target # +if (TARGET csm_share) + return() +endif() + # Build the name of the path where libcsm_share should be located if (USE_ESMF_LIB) set(ESMFDIR "esmf") @@ -22,10 +26,9 @@ set(CSM_SHARE "${INSTALL_SHAREDPATH}/${COMP_INTERFACE}/${ESMFDIR}/${NINST_VALUE} # Look for libcsm_share in the complex path we built above find_library(CSM_SHARE_LIB csm_share REQUIRED PATHS ${CSM_SHARE}) -# Grab mct if we don't already have it -if (NOT TARGET mct) - find_package(MCT REQUIRED) -endif() +# Grab mct and spio if we don't already have it +find_package(MCT REQUIRED) +find_package(PIO REQUIRED) # Create the interface library, and set target properties add_library (csm_share INTERFACE) diff --git a/components/cmake/modules/FindMCT.cmake b/components/cmake/modules/FindMCT.cmake index 303c47c43b0e..068aead89f7f 100644 --- a/components/cmake/modules/FindMCT.cmake +++ b/components/cmake/modules/FindMCT.cmake @@ -11,6 +11,10 @@ # The "mct" target # +if (TARGET mct) + return() +endif() + # Look for libmct in INSTALL_SHAREDPATH/lib find_library(MCT_LIB mct REQUIRED PATHS ${INSTALL_SHAREDPATH}/lib) find_library(MPEU_LIB mpeu REQUIRED PATHS ${INSTALL_SHAREDPATH}/lib $ENV{mct_ROOT}) diff --git a/components/cmake/modules/FindNETCDF.cmake b/components/cmake/modules/FindNETCDF.cmake index 6491fead5128..df7458f7f923 100644 --- a/components/cmake/modules/FindNETCDF.cmake +++ b/components/cmake/modules/FindNETCDF.cmake @@ -7,6 +7,10 @@ # The "netcdf" target # +if (TARGET netcdf) + return() +endif() + # Pnetcdf is optional, and only if not running serial if (NOT MPILIB STREQUAL mpi-serial) if (PNETCDF_PATH) diff --git a/components/cmake/modules/FindPIO.cmake b/components/cmake/modules/FindPIO.cmake index d3d6f8116274..e339576cb7fb 100644 --- a/components/cmake/modules/FindPIO.cmake +++ b/components/cmake/modules/FindPIO.cmake @@ -7,6 +7,10 @@ # The "spio" target # +if (TARGET spio) + return() +endif() + if (NOT PIO_LIBDIR) set(PIO_LIBDIR "${INSTALL_SHAREDPATH}/lib") endif() diff --git a/components/mpas-framework/src/CMakeLists.txt b/components/mpas-framework/src/CMakeLists.txt index ccd3c06a92c7..49ece73d90d5 100644 --- a/components/mpas-framework/src/CMakeLists.txt +++ b/components/mpas-framework/src/CMakeLists.txt @@ -77,7 +77,8 @@ include(${CMAKE_CURRENT_SOURCE_DIR}/operators/operators.cmake) add_library(common) target_compile_definitions(common PRIVATE ${CPPDEFS}) target_include_directories(common PRIVATE ${INCLUDES}) -target_link_libraries(common PRIVATE netcdf) +find_package(NETCDF REQUIRED) +target_link_libraries(common PUBLIC netcdf) genf90_targets("${COMMON_RAW_SOURCES}" "${INCLUDES}" "${CPPDEFS}" "" "") target_sources(common PRIVATE ${SOURCES})