diff --git a/CMakeLists.txt b/CMakeLists.txt index 4bac1aad3..e4354272a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -488,12 +488,16 @@ endif() # Turn off enable_netcdf4 because it will be used # as a shorthand for ENABLE_HDF5|ENABLE_HDF4|ENABLE_NCZARR set(NETCDF_ENABLE_NETCDF4 OFF CACHE BOOL "" FORCE) - option(NETCDF_ENABLE_DAP "Enable DAP2 and DAP4 Client." ON) option(NETCDF_ENABLE_NCZARR "Enable NCZarr Client." ON) option(NETCDF_ENABLE_PNETCDF "Build with parallel I/O for CDF-1, 2, and 5 files using PnetCDF." OFF) set(NETCDF_ENABLE_CDF5 AUTO CACHE STRING "AUTO") option(NETCDF_ENABLE_CDF5 "Enable CDF5 support" ON) +option(NETCDF_ENABLE_HDF4 "Enable HDF4 Read Support" OFF) +option(NETCDF_ENABLE_HDF4_FILE_TESTS "Enable HDF4 File Tests" ${NETCDF_ENABLE_HDF4}) +if(NETCDF_ENABLE_HDF4) + set(USE_HDF4 ON) +endif() # Netcdf-4 support (i.e. libsrc4) is required by more than just HDF5 (e.g. NCZarr) # So depending on what above formats are enabled, enable netcdf-4 @@ -1427,7 +1431,6 @@ endif(USE_HDF5) if(USE_HDF4) add_subdirectory(libhdf4) - add_subdirectory(hdf4_test) endif(USE_HDF4) if(NETCDF_ENABLE_DAP2) @@ -1466,6 +1469,8 @@ if(NETCDF_ENABLE_NCZARR) DESTINATION ${netCDF_BINARY_DIR}/nczarr_test/) endif() +# Tests and files which depend on libnetcdf must be included +# *after* this line. add_subdirectory(liblib) if(NETCDF_ENABLE_PLUGINS) @@ -1486,6 +1491,9 @@ if(NETCDF_ENABLE_TESTS) add_subdirectory(nctest) endif() add_subdirectory(nc_test) + if(USE_HDF4) + add_subdirectory(hdf4_test) + endif() if(USE_HDF5) include_directories(h5_test) add_subdirectory(nc_test4) @@ -1664,6 +1672,7 @@ is_enabled(BUILD_SHARED_LIBS enable_shared) is_enabled(NETCDF_ENABLE_V2_API HAS_NC2) is_enabled(NETCDF_ENABLE_NETCDF4 HAS_NC4) is_enabled(NETCDF_ENABLE_HDF4 HAS_HDF4) +is_enabled(USE_HDF4 HAS_HDF4) is_enabled(USE_HDF5 HAS_HDF5) is_enabled(OFF HAS_BENCHMARKS) is_enabled(STATUS_PNETCDF HAS_PNETCDF) diff --git a/cmake/dependencies.cmake b/cmake/dependencies.cmake index db8b903d5..89d155528 100644 --- a/cmake/dependencies.cmake +++ b/cmake/dependencies.cmake @@ -14,8 +14,8 @@ find_package(MakeDist) ################################ # HDF4 ################################ -if(NETCDF_ENABLE_HDF4) - set(USE_HDF4 ON ) +if(USE_HDF4) + set(NETCDF_USE_HDF4 ON ) # Check for include files, libraries. find_path(MFHDF_H_INCLUDE_DIR mfhdf.h) @@ -65,11 +65,17 @@ if(NETCDF_ENABLE_HDF4) if(NOT JPEG_LIB) message(FATAL_ERROR "HDF4 Support enabled but cannot find libjpeg") endif() - set(HDF4_LIBRARIES ${JPEG_LIB} ${HDF4_LIBRARIES} ) + set(HDF4_LIBRARIES ${JPEG_LIB} ${HDF4_LIBRARIES} CACHE STRING "") message(STATUS "Found JPEG libraries: ${JPEG_LIB}") + target_link_libraries(netcdf + PRIVATE + ${HDF4_LIBRARIES} + ) + # Option to enable HDF4 file tests. - option(NETCDF_ENABLE_HDF4_FILE_TESTS "Run HDF4 file tests. This fetches sample HDF4 files from the Unidata resources site to test with (requires curl)." ON) + #option(NETCDF_ENABLE_HDF4_FILE_TESTS "Run HDF4 file tests. This fetches sample HDF4 files from the Unidata resources site to test with (requires curl)." ON) + if(NETCDF_ENABLE_HDF4_FILE_TESTS) find_program(PROG_CURL NAMES curl) if(PROG_CURL) @@ -77,10 +83,11 @@ if(NETCDF_ENABLE_HDF4) else() message(STATUS "Unable to locate 'curl'. Disabling hdf4 file tests.") set(USE_HDF4_FILE_TESTS OFF ) + set(NETCDF_ENABLE_HDF4_FILE_TESTS OFF) endif() set(USE_HDF4_FILE_TESTS ${USE_HDF4_FILE_TESTS} ) endif() -endif() +endif(USE_HDF4) ################################ # HDF5 diff --git a/cmake/netcdf_functions_macros.cmake b/cmake/netcdf_functions_macros.cmake index 064947bbb..5b7820791 100644 --- a/cmake/netcdf_functions_macros.cmake +++ b/cmake/netcdf_functions_macros.cmake @@ -148,6 +148,7 @@ macro(build_bin_test F) add_executable(${F} "${CMAKE_CURRENT_BINARY_DIR}/${F}.c" ${ARGN}) endif() target_link_libraries(${F} netcdf ${ALL_TLL_LIBS}) + if(MSVC) set_target_properties(${F} PROPERTIES @@ -176,6 +177,8 @@ endmacro() # Binary tests which are used by a script looking for a specific name. macro(build_bin_test_no_prefix F) build_bin_test(${F}) + + if(WIN32) #SET_PROPERTY(TEST ${F} PROPERTY FOLDER "tests/") set_target_properties(${F} PROPERTIES diff --git a/hdf4_test/CMakeLists.txt b/hdf4_test/CMakeLists.txt index d935d9d6f..24afa184f 100644 --- a/hdf4_test/CMakeLists.txt +++ b/hdf4_test/CMakeLists.txt @@ -6,18 +6,20 @@ # See netcdf-c/COPYRIGHT file for more info. # Copy some test files from current source dir to out-of-tree build dir. -FILE(GLOB COPY_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.sh ${CMAKE_CURRENT_SOURCE_DIR}/*.hdf4) -FILE(COPY ${COPY_FILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) -IF(WIN32) - FILE(COPY ${COPY_FILES} DESTINATION ${RUNTIME_OUTPUT_DIRECTORY}/) -ENDIF() +file(GLOB COPY_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.sh ${CMAKE_CURRENT_SOURCE_DIR}/*.hdf4) +file(COPY ${COPY_FILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) +if(WIN32) + file(COPY ${COPY_FILES} DESTINATION ${RUNTIME_OUTPUT_DIRECTORY}/) +endif() -IF(USE_HDF4_FILE_TESTS AND NOT WIN32) +if(USE_HDF4_FILE_TESTS AND NOT WIN32) build_bin_test_no_prefix(tst_interops2) + target_link_libraries(tst_interops2 netcdf ${ALL_TLL_LIBS}) build_bin_test_no_prefix(tst_interops3) add_bin_test(hdf4_test tst_chunk_hdf4) add_bin_test(hdf4_test tst_h4_lendian) add_bin_test(hdf4_test tst_hdf4_extra) add_sh_test(hdf4_test run_get_hdf4_files) add_sh_test(hdf4_test run_formatx_hdf4) -ENDIF() +endif() + diff --git a/libhdf4/CMakeLists.txt b/libhdf4/CMakeLists.txt index cbb350771..4d8878ca6 100644 --- a/libhdf4/CMakeLists.txt +++ b/libhdf4/CMakeLists.txt @@ -22,5 +22,7 @@ if (NETCDF_ENABLE_DLL) target_compile_definitions(netcdfhdf4 PRIVATE DLL_NETCDF DLL_EXPORT) endif() +target_link_libraries(netcdfhdf4 PUBLIC ${HDF4_LIBRARIES}) + # Remember to package this file for CMake builds. ADD_EXTRA_DIST(${libhdf4_SOURCES} CMakeLists.txt) diff --git a/ncgen/generr.c b/ncgen/generr.c index 2235bfec5..ae37d5e2f 100644 --- a/ncgen/generr.c +++ b/ncgen/generr.c @@ -82,8 +82,10 @@ void markcdf4(const char* msg) { enhanced_flag = 1; - if(markcdf4_msg == NULL) + + if(markcdf4_msg == NULL) { markcdf4_msg = (char*)msg; + } } char*