@@ -13,6 +13,9 @@ cmake_minimum_required(VERSION 3.6.1)
1313project (netCDF LANGUAGES C CXX )
1414set (PACKAGE "netCDF" CACHE STRING "" )
1515
16+ # Use libraries specified in CMAKE_REQUIRED_LIBRARIES for check include macros
17+ cmake_policy (SET CMP0075 NEW )
18+
1619#####
1720# Version Info:
1821#
@@ -791,6 +794,7 @@ IF(USE_HDF5)
791794 IF (NOT HDF5_C_LIBRARY)
792795 SET (HDF5_C_LIBRARY hdf5)
793796 ENDIF ()
797+
794798 ENDIF (HDF5_C_LIBRARY AND HDF5_HL_LIBRARY AND HDF5_INCLUDE_DIR )
795799
796800 FIND_PACKAGE (Threads )
@@ -800,8 +804,42 @@ IF(USE_HDF5)
800804 SET (HDF5_C_LIBRARY_hdf5 "${HDF5_C_LIBRARY} " )
801805 ENDIF ()
802806
803- #Check to see if H5Z_SZIP exists in HDF5_Libraries. If so, we must use szip library.
807+ FIND_PATH (HAVE_HDF5_H hdf5.h PATHS ${HDF5_INCLUDE_DIR} NO_DEFAULT_PATH )
808+ IF (NOT HAVE_HDF5_H)
809+ MESSAGE (FATAL_ERROR "Compiling a test with hdf5 failed. Either hdf5.h cannot be found, or the log messages should be checked for another reason." )
810+ ELSE (NOT HAVE_HDF5_H )
811+ INCLUDE_DIRECTORIES (${HAVE_HDF5_H} )
812+ ENDIF (NOT HAVE_HDF5_H )
813+
804814 set (CMAKE_REQUIRED_INCLUDES ${HDF5_INCLUDE_DIR} )
815+
816+ # Check to ensure that HDF5 was built with zlib.
817+ # This needs to be near the beginning since we
818+ # need to know whether to add "-lz" to the symbol
819+ # tests below.
820+ CHECK_C_SOURCE_COMPILES ("#include <H5public.h>
821+ #if !H5_HAVE_ZLIB_H
822+ #error
823+ #endif
824+ int main() {
825+ int x = 1;}" HAVE_HDF5_ZLIB )
826+ IF (NOT HAVE_HDF5_ZLIB)
827+ MESSAGE (FATAL_ERROR "HDF5 was built without zlib. Rebuild HDF5 with zlib." )
828+ ELSE ()
829+ # If user has specified the `ZLIB_LIBRARY`, use it; otherwise try to find...
830+ IF (NOT ZLIB_LIBRARY)
831+ find_package (ZLIB )
832+ IF (ZLIB_FOUND)
833+ SET (ZLIB_LIBRARY ${ZLIB_LIBRARIES} )
834+ ELSE ()
835+ MESSAGE (FATAL_ERROR "HDF5 Requires ZLIB, but cannot find libz." )
836+ ENDIF ()
837+ ENDIF ()
838+ SET (CMAKE_REQUIRED_LIBRARIES ${ZLIB_LIBRARY} ${CMAKE_REQUIRED_LIBRARIES} )
839+ MESSAGE (STATUS "HDF5 has zlib." )
840+ ENDIF ()
841+
842+ #Check to see if H5Z_SZIP exists in HDF5_Libraries. If so, we must use szip library.
805843 CHECK_C_SOURCE_COMPILES ("#include <H5public.h>
806844 #if !H5_HAVE_FILTER_SZIP
807845 #error
@@ -887,31 +925,15 @@ IF(USE_HDF5)
887925 ENDIF ()
888926
889927 FIND_PATH (HAVE_HDF5_H hdf5.h PATHS ${HDF5_INCLUDE_DIR} NO_DEFAULT_PATH )
890- FIND_PATH (HAVE_HDF5_H hdf5.h )
891928 IF (NOT HAVE_HDF5_H)
892929 MESSAGE (FATAL_ERROR "Compiling a test with hdf5 failed. Either hdf5.h cannot be found, or the log messages should be checked for another reason." )
893930 ELSE (NOT HAVE_HDF5_H )
894931 INCLUDE_DIRECTORIES (${HAVE_HDF5_H} )
895932 ENDIF (NOT HAVE_HDF5_H )
896933
897- # Check to ensure that HDF5 was built with zlib.
898- set (CMAKE_REQUIRED_INCLUDES ${HDF5_INCLUDE_DIR} )
899-
900-
901- CHECK_C_SOURCE_COMPILES ("#include <H5public.h>
902- #if !H5_HAVE_ZLIB_H
903- #error
904- #endif
905- int main() {
906- int x = 1;}" HAVE_HDF5_ZLIB )
907- IF (NOT HAVE_HDF5_ZLIB)
908- MESSAGE (FATAL_ERROR "HDF5 was built without zlib. Rebuild HDF5 with zlib." )
909- ENDIF ()
910-
911934 #option to include HDF5 High Level header file (hdf5_hl.h) in case we are not doing a make install
912935 INCLUDE_DIRECTORIES (${HDF5_HL_INCLUDE_DIR} )
913936
914-
915937ENDIF (USE_HDF5 )
916938
917939# See if we have libcurl
0 commit comments