From 79c7d21e961ad5c536a23d8e86fbb16192e12d0d Mon Sep 17 00:00:00 2001 From: Dom Heinzeller Date: Thu, 27 Feb 2020 10:11:22 -0700 Subject: [PATCH 1/2] Modules/FindNetCDF.cmake: figure out NetCDF dependencies for static libraries --- Modules/FindNetCDF.cmake | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/Modules/FindNetCDF.cmake b/Modules/FindNetCDF.cmake index 8b474fa..87fc7d6 100644 --- a/Modules/FindNetCDF.cmake +++ b/Modules/FindNetCDF.cmake @@ -79,20 +79,43 @@ if (NETCDF_META) endif() endif (NETCDF_META) +set(NETCDF_IS_STATIC FALSE) find_library (NETCDF_flib - names libnetcdff.a netcdff.a libnetcdff.so netcdff.so libnetcdff.dylib netcdff.dylib + names libnetcdff.so netcdff.so libnetcdff.dylib netcdff.dylib HINTS ${NETCDF_DIR}/lib ${NETCDF_FORTRAN_DIR}/lib ${NETCDF_FORTRAN}/lib ${NETCDF_FORTRAN_ROOT}/lib + ${NETCDF_DIR}/lib64 + ${NETCDF_FORTRAN_DIR}/lib64 + ${NETCDF_FORTRAN}/lib64 + ${NETCDF_FORTRAN_ROOT}/lib64 ) +if(NETCDF_flib MATCHES "NETCDF_flib-NOTFOUND") + # Dynamic library not found, look for static library instead + find_library (NETCDF_flib + names libnetcdff.a netcdff.a + HINTS + ${NETCDF_DIR}/lib + ${NETCDF_FORTRAN_DIR}/lib + ${NETCDF_FORTRAN}/lib + ${NETCDF_FORTRAN_ROOT}/lib + ${NETCDF_DIR}/lib64 + ${NETCDF_FORTRAN_DIR}/lib64 + ${NETCDF_FORTRAN}/lib64 + ${NETCDF_FORTRAN_ROOT}/lib64 + ) + if(NOT NETCDF_flib MATCHES "NETCDF_flib-NOTFOUND") + set(NETCDF_IS_STATIC TRUE) + endif() +endif() + if (NETCDF_flib) set(NETCDF_F90 "YES") - endif() -find_library (NETCDF_LIBRARIES_C +find_library (NETCDF_LIBRARIES_C NAMES netcdf HINTS ${NETCDF_DIR}/lib ) mark_as_advanced(NETCDF_LIBRARIES_C) @@ -174,6 +197,13 @@ if( NETCDF_LIBRARIES_F90 ) endif() set (NETCDF_LIBRARIES "${NetCDF_libs}" CACHE STRING "All NetCDF libraries required for interface level") + +if(NETCDF_IS_STATIC) + find_package(HDF5 MODULE COMPONENTS C HL REQUIRED) + find_package(ZLIB MODULE REQUIRED) + set(NETCDF_LIBRARIES "${NETCDF_LIBRARIES};${HDF5_HL_LIBRARIES};${HDF5_LIBRARIES};${ZLIB_LIBRARIES}") +endif() + # handle the QUIETLY and REQUIRED arguments and set NETCDF_FOUND to TRUE if # all listed variables are TRUE include (FindPackageHandleStandardArgs) From a49558c3e30c6130ed4821c9af474857a8be9d3d Mon Sep 17 00:00:00 2001 From: Dom Heinzeller Date: Thu, 27 Feb 2020 14:31:31 -0700 Subject: [PATCH 2/2] Bugfix to work if called multiple times --- Modules/FindNetCDF.cmake | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/Modules/FindNetCDF.cmake b/Modules/FindNetCDF.cmake index 87fc7d6..4a13a87 100644 --- a/Modules/FindNetCDF.cmake +++ b/Modules/FindNetCDF.cmake @@ -79,9 +79,8 @@ if (NETCDF_META) endif() endif (NETCDF_META) -set(NETCDF_IS_STATIC FALSE) find_library (NETCDF_flib - names libnetcdff.so netcdff.so libnetcdff.dylib netcdff.dylib + names libnetcdff.so netcdff.so libnetcdff.dylib netcdff.dylib libnetcdff.a netcdff.a HINTS ${NETCDF_DIR}/lib ${NETCDF_FORTRAN_DIR}/lib @@ -93,26 +92,13 @@ find_library (NETCDF_flib ${NETCDF_FORTRAN_ROOT}/lib64 ) -if(NETCDF_flib MATCHES "NETCDF_flib-NOTFOUND") - # Dynamic library not found, look for static library instead - find_library (NETCDF_flib - names libnetcdff.a netcdff.a - HINTS - ${NETCDF_DIR}/lib - ${NETCDF_FORTRAN_DIR}/lib - ${NETCDF_FORTRAN}/lib - ${NETCDF_FORTRAN_ROOT}/lib - ${NETCDF_DIR}/lib64 - ${NETCDF_FORTRAN_DIR}/lib64 - ${NETCDF_FORTRAN}/lib64 - ${NETCDF_FORTRAN_ROOT}/lib64 - ) - if(NOT NETCDF_flib MATCHES "NETCDF_flib-NOTFOUND") - set(NETCDF_IS_STATIC TRUE) - endif() -endif() - if (NETCDF_flib) + get_filename_component(NETCDF_flib_ext ${NETCDF_flib} EXT) + if(NETCDF_flib_ext STREQUAL ".a") + set(NETCDF_IS_STATIC TRUE) + else() + set(NETCDF_IS_STATIC FALSE) + endif() set(NETCDF_F90 "YES") endif() find_library (NETCDF_LIBRARIES_C