-
Notifications
You must be signed in to change notification settings - Fork 291
Open
Description
I had a hard time trying to run CMake with NetCDF with a dependent HDF5.
It kept claiming that my HDF5 was not compiled with ZLIB support - which is wrong
I tracked down the problem up to the check trying to detect H5_HAVE_ZLIB_H
My HDF5 does have #define H5_HAVE_ZLIB_H 1
but the CMake of NetCDF was not detecting it at configure stage.
I finally found the problem in the test of check_hdf5.cmake
function(check_hdf5_feature VAR FEATURE)
if (NOT _H5_FEATURE_HEADER)
check_hdf5_feature_header()
endif()
include(CheckCSourceCompiles)
set(CMAKE_REQUIRED_INCLUDES ${HDF5_INCLUDE_DIR})
message(STATUS "Checking for ${FEATURE}")
check_c_source_compiles("
#include <${_H5_FEATURE_HEADER}>
#if !${FEATURE}
#error
#endif
int main() {}"
_has_${FEATURE})
set(${VAR} ${_has_${FEATURE}} PARENT_SCOPE)
endfunction()
The problem are the lines
#if !${FEATURE}
#error
#endif
I think they are interpreted as a comment of CMake, not as C code !
It must be escaped properly.
The best fix I think is using the [=[...]=] syntax
function(check_hdf5_feature VAR FEATURE)
if (NOT _H5_FEATURE_HEADER)
check_hdf5_feature_header()
endif()
include(CheckCSourceCompiles)
set(CMAKE_REQUIRED_INCLUDES ${HDF5_INCLUDE_DIR})
message(STATUS "Checking for ${FEATURE}")
check_c_source_compiles([=[
#include <${_H5_FEATURE_HEADER}>
#if !${FEATURE}
#error
#endif
int main() {}]=]
_has_${FEATURE})
set(${VAR} ${_has_${FEATURE}} PARENT_SCOPE)
endfunction()
Also, I had to add
unset(_has_${FEATURE} CACHE)
because of cache poisoning during my tests
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels