File: check_hdf5.cmake

package info (click to toggle)
netcdf-parallel 1%3A4.9.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 116,192 kB
  • sloc: ansic: 279,265; sh: 14,143; cpp: 5,971; yacc: 2,612; makefile: 2,075; lex: 1,218; javascript: 280; xml: 173; awk: 2
file content (55 lines) | stat: -rw-r--r-- 1,712 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# Work out which HDF5 config header we can safely include
#
# We'd like to just use H5public.h, but if HDF5 was built against MPI, this
# might require us to have found MPI already. The next best file is H5pubconf.h,
# which actually has all the feature macros we want to check, but some
# distributions rename this for multiarch, so we've got to check some different
# names.
#
# HDF5_INCLUDE_DIR should already be set before calling this
function(check_hdf5_feature_header)
  if (_H5_FEATURE_HEADER)
    return()
  endif()

  include(CheckIncludeFile)

  set(CMAKE_REQUIRED_INCLUDES ${HDF5_INCLUDE_DIR})

  message(STATUS "Checking for HDF5 config header")
  foreach(_h5_header "H5public.h" "H5pubconf.h" "H5pubconf-64.h" "H5pubconf-32.h")
    check_include_file(${_h5_header} _can_include_h5_header${_h5_header})

    if (_can_include_h5_header${_h5_header})
      message(STATUS "Using ${_h5_header} to check for feature macros")
      set(_H5_FEATURE_HEADER ${_h5_header} CACHE INTERNAL "")
      return()
    endif()
  endforeach()

  message(FATAL_ERROR "Could not include any HDF5 config headers")
endfunction()


# Check for an HDF5 feature macro named FEATURE and store the result in VAR
#
# This just wraps `check_c_source_compiles` but ensures we use the correct header
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()