From 382ff98e6c2ec294239ee9f8c7af03767a1b3715 Mon Sep 17 00:00:00 2001 From: Greg Sjaardema Date: Wed, 13 Jul 2016 09:30:54 -0400 Subject: [PATCH 1/6] Use an hdf5-api function that eliminates code The H5Aexists hdf5 function does the same function as the manually coded loop with much less code and fewer function calls. Also, the H5Aopen_idx and H5Aget_num_attrs functions are deprecated. --- libsrc4/nc4hdf.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/libsrc4/nc4hdf.c b/libsrc4/nc4hdf.c index 1fb08202e..2e951d75f 100644 --- a/libsrc4/nc4hdf.c +++ b/libsrc4/nc4hdf.c @@ -1954,24 +1954,14 @@ write_nc3_strict_att(hid_t hdf_grpid) int one = 1, num, a; char att_name[NC_MAX_NAME + 1]; int retval = NC_NOERR; + htri_t attr_exists; /* If the attribute already exists, call that a success and return * NC_NOERR. */ - if ((num = H5Aget_num_attrs(hdf_grpid)) < 0) + if ((attr_exists = H5Aexists(hdf_grpid, NC3_STRICT_ATT_NAME)) < 0) return NC_EHDFERR; - for (a = 0; a < num; a++) - { - if ((attid = H5Aopen_idx(hdf_grpid, (unsigned int)a)) < 0) - BAIL(NC_EHDFERR); - if (H5Aget_name(attid, NC_MAX_HDF5_NAME, att_name) < 0) - BAIL(NC_EHDFERR); - if (H5Aclose(attid) < 0) - return NC_EFILEMETA; - if (strcmp(att_name, NC3_STRICT_ATT_NAME)==0) - { - return NC_NOERR; - } - } + if (attr_exists) + return NC_NOERR; /* Create the attribute to mark this as a file that needs to obey * strict netcdf-3 rules. */ From a5b595e974c34d288ba8fb19b78078b13aec7a87 Mon Sep 17 00:00:00 2001 From: Ward Fisher Date: Tue, 1 Nov 2016 10:47:17 -0600 Subject: [PATCH 2/6] Removed stray info lines in nc-config templates. --- nc-config.cmake.in | 1 - nc-config.in | 1 - 2 files changed, 2 deletions(-) diff --git a/nc-config.cmake.in b/nc-config.cmake.in index a97e8403c..a6c248898 100755 --- a/nc-config.cmake.in +++ b/nc-config.cmake.in @@ -82,7 +82,6 @@ has_f03="no" nfconf=$(which nf-config 2>/dev/null) if [ -f "$nfconf" ]; then - echo "Using nf-config: $nfconf" has_fortran="yes" fc=`nf-config --fc` fflags=`nf-config --fflags` diff --git a/nc-config.in b/nc-config.in index e6f01534a..1c7198d69 100755 --- a/nc-config.in +++ b/nc-config.in @@ -29,7 +29,6 @@ has_f03="no" nfconf=$(which nf-config 2>/dev/null) if [ -f "$nfconf" ]; then - echo "Using nf-config: $nfconf" has_fortran="yes" fc=`nf-config --fc` fflags=`nf-config --fflags` From 12d9891305a76947c5794e57f75c558a8b083f49 Mon Sep 17 00:00:00 2001 From: Ward Fisher Date: Thu, 10 Nov 2016 23:22:02 +0000 Subject: [PATCH 3/6] Moved stanza for NC_EXTRA_DEPS before checking for other libraries. --- CMakeLists.txt | 87 ++++++++++++++++++++++---------------------------- 1 file changed, 39 insertions(+), 48 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d6d0d2c56..d025d0967 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -393,6 +393,33 @@ IF(NOT MSVC) ENDIF(BUILD_FORTRAN) ENDIF() + +### +# Allow the user to specify libraries +# to link against, similar to automakes 'LIBS' variable. +### +SET(NC_EXTRA_DEPS "" CACHE STRING "Additional libraries to link against.") +IF(NC_EXTRA_DEPS) + STRING(REPLACE " " ";" DEPS_LIST ${NC_EXTRA_DEPS}) + FOREACH(_DEP ${DEPS_LIST}) + STRING(REGEX REPLACE "^-l" "" _LIB ${_DEP}) + FIND_LIBRARY("${_LIB}_DEP" NAMES "${_LIB}" "lib${_LIB}") + MESSAGE(${${_LIB}_DEP}) + IF(NOT "${_LIB}_DEP") + MESSAGE(FATAL_ERROR "Error finding ${_LIB}.") + ELSE() + MESSAGE(STATUS "Found ${_LIB}: ${${_LIB}_DEP}") + ENDIF() + SET(EXTRA_DEPS ${EXTRA_DEPS} "${${_LIB}_DEP}") + ENDFOREACH() + MESSAGE("Extra deps: ${EXTRA_DEPS}") + LIST(REMOVE_DUPLICATES EXTRA_DEPS) + SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${EXTRA_DEPS}) +ENDIF() +### +# End user-specified dependent libraries. +### + # Option to use HDF4 OPTION(ENABLE_HDF4 "Build netCDF-4 with HDF5 read capability(HDF4, HDF5 and Zlib required)." OFF) IF(ENABLE_HDF4) @@ -639,6 +666,18 @@ IF(USE_HDF5 OR ENABLE_NETCDF_4) ENDIF() SET(HDF5_C_LIBRARY hdf5) ENDIF(NOT MSVC) + SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} sz) + #Check to see if H5Z_SZIP exists in HDF5_Libraries. If so, we must use szip. + CHECK_LIBRARY_EXISTS(${HDF5_C_LIBRARY} H5Pset_szip "" USE_SZIP) + IF(USE_SZIP) + FIND_LIBRARY(SZIP NAMES szip sz) + IF(SZIP) + SET(SZIP_LIBRARY ${SZIP}) + SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${SZIP}) + ELSE() + MESSAGE(FATAL_ERROR "HDF5 Requires SZIP, but cannot find libszip or libsz.") + ENDIF() + ENDIF() CHECK_LIBRARY_EXISTS(${HDF5_C_LIBRARY} H5free_memory "" HDF5_HAS_H5FREE) CHECK_LIBRARY_EXISTS(${HDF5_C_LIBRARY} H5Pset_libver_bounds "" HDF5_HAS_LIBVER_BOUNDS) @@ -649,15 +688,6 @@ IF(USE_HDF5 OR ENABLE_NETCDF_4) SET(HDF5_CC h5cc) ENDIF() - # execute_process(COMMAND sh -c "${HDF5_CC} -showconfig | grep -i 'HDF5 version' | cut -d: -f2 | tr -d ' '" - # OUTPUT_VARIABLE HDF5_VERSION - # ERROR_QUIET) - - # It cannot be assumed that libhdf5.settings exists. If it doesn't, - # the call to h5cc will have failed. At this point we will have to - # trust the user that they have configured their system properly. - - # Starting with hdf5 1.8.11, dynamic loading is an option. # In case hdf5 has a dependency on libdl, the user must specify # -DENABLE_DYNAMIC_LOADING=ON when configuring netcdf. @@ -675,19 +705,6 @@ IF(USE_HDF5 OR ENABLE_NETCDF_4) INCLUDE_DIRECTORIES(${LIBDL_INCLUDE_DIR}) ENDIF() - #Check to see if H5Z_SZIP exists in HDF5_Libraries. If so, we must use szip. - CHECK_LIBRARY_EXISTS(hdf5 H5Z_SZIP "" USE_SZIP) - IF(USE_SZIP) - FIND_LIBRARY(SZIP NAMES szip sz) - IF(SZIP) - SET(SZIP_LIBRARY ${SZIP}) - ELSE() - MESSAGE(FATAL_ERROR "HDF5 Requires SZIP, but cannot find libszip or libsz.") - ENDIF() - #FIND_PACKAGE(SZIP NO_MODULE REQUIRED) - #INCLUDE_DIRECTORIES(${SZIP_INCLUDE_DIR}) - ENDIF() - SET(H5_USE_16_API 1) OPTION(NC_ENABLE_HDF_16_API "Enable HDF5 1.6.x Compatibility(Required)" ON) IF(NOT NC_ENABLE_HDF_16_API) @@ -863,32 +880,6 @@ IF(ENABLE_TESTS) MARK_AS_ADVANCED(ENABLE_FAILING_TESTS) ENDIF() -### -# Allow the user to specify libraries -# to link against, similar to automakes 'LIBS' variable. -### -SET(NC_EXTRA_DEPS "" CACHE STRING "Additional libraries to link against.") -IF(NC_EXTRA_DEPS) - STRING(REPLACE " " ";" DEPS_LIST ${NC_EXTRA_DEPS}) - FOREACH(_DEP ${DEPS_LIST}) - STRING(REGEX REPLACE "^-l" "" _LIB ${_DEP}) - FIND_LIBRARY("${_LIB}_DEP" NAMES "${_LIB}" "lib${_LIB}") - MESSAGE(${${_LIB}_DEP}) - IF(NOT "${_LIB}_DEP") - MESSAGE(FATAL_ERROR "Error finding ${_LIB}.") - ELSE() - MESSAGE(STATUS "Found ${_LIB}: ${${_LIB}_DEP}") - ENDIF() - SET(EXTRA_DEPS ${EXTRA_DEPS} "${${_LIB}_DEP}") - ENDFOREACH() - MESSAGE("Extra deps: ${EXTRA_DEPS}") - LIST(REMOVE_DUPLICATES EXTRA_DEPS) -ENDIF() -### -# End user-specified dependent libraries. -### - - ### # Option to enable extreme numbers during testing. ### From 7d1289fb64768658cbd3077e7a11254707bc3bf9 Mon Sep 17 00:00:00 2001 From: Ward Fisher Date: Thu, 10 Nov 2016 23:30:01 +0000 Subject: [PATCH 4/6] Started replacing hack using TLL_LIBS with CMAKE_REQUIRED_LIBRARIES --- liblib/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/liblib/CMakeLists.txt b/liblib/CMakeLists.txt index 7fb509643..bbfc475b0 100644 --- a/liblib/CMakeLists.txt +++ b/liblib/CMakeLists.txt @@ -80,8 +80,8 @@ IF(TLL_LIBS) LIST(REMOVE_DUPLICATES TLL_LIBS) ENDIF() -TARGET_LINK_LIBRARIES(netcdf ${TLL_LIBS}) - +#TARGET_LINK_LIBRARIES(netcdf ${TLL_LIBS}) +SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${TLL_LIBS}) IF(MSVC) SET_TARGET_PROPERTIES(netcdf PROPERTIES LINK_FLAGS_DEBUG " /NODEFAULTLIB:MSVCRT" From 0927fed94397fd160ddc2fce43861c5539062d96 Mon Sep 17 00:00:00 2001 From: Ward Fisher Date: Fri, 11 Nov 2016 00:39:19 +0000 Subject: [PATCH 5/6] Modified previous change. --- liblib/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/liblib/CMakeLists.txt b/liblib/CMakeLists.txt index bbfc475b0..f1d7597d2 100644 --- a/liblib/CMakeLists.txt +++ b/liblib/CMakeLists.txt @@ -80,7 +80,7 @@ IF(TLL_LIBS) LIST(REMOVE_DUPLICATES TLL_LIBS) ENDIF() -#TARGET_LINK_LIBRARIES(netcdf ${TLL_LIBS}) +TARGET_LINK_LIBRARIES(netcdf ${TLL_LIBS}) SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${TLL_LIBS}) IF(MSVC) SET_TARGET_PROPERTIES(netcdf PROPERTIES From f4a5d389927302e871436dd3a1b5c7934c261bff Mon Sep 17 00:00:00 2001 From: Ward Fisher Date: Thu, 10 Nov 2016 18:06:29 -0700 Subject: [PATCH 6/6] Corrected issue for systems that don't have libsz installed. --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d025d0967..f626a3b77 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -666,9 +666,9 @@ IF(USE_HDF5 OR ENABLE_NETCDF_4) ENDIF() SET(HDF5_C_LIBRARY hdf5) ENDIF(NOT MSVC) - SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} sz) + #Check to see if H5Z_SZIP exists in HDF5_Libraries. If so, we must use szip. - CHECK_LIBRARY_EXISTS(${HDF5_C_LIBRARY} H5Pset_szip "" USE_SZIP) + CHECK_LIBRARY_EXISTS(${HDF5_C_LIBRARY} H5P_SZIP "" USE_SZIP) IF(USE_SZIP) FIND_LIBRARY(SZIP NAMES szip sz) IF(SZIP)