FindNetCDF.cmake
Go to the documentation of this file.
1 #[==[
2 Provides the following variables:
3 
4  * `NetCDF_FOUND`: Whether NetCDF was found or not.
5  * `NetCDF_INCLUDE_DIRS`: Include directories necessary to use NetCDF.
6  * `NetCDF_LIBRARIES`: Libraries necessary to use NetCDF.
7  * `NetCDF_VERSION`: The version of NetCDF found.
8  * `NetCDF::NetCDF`: A target to use with `target_link_libraries`.
9  * `NetCDF_HAS_PARALLEL`: Whether or not NetCDF was found with parallel IO support.
10 #]==]
11 
12 function(FindNetCDF_get_is_parallel_aware include_dir)
13  file(STRINGS "${include_dir}/netcdf_meta.h" _netcdf_lines
14  REGEX "#define[ \t]+NC_HAS_PARALLEL[ \t]")
15  string(REGEX REPLACE ".*NC_HAS_PARALLEL[ \t]*([0-1]+).*" "\\1" _netcdf_has_parallel "${_netcdf_lines}")
16  if (_netcdf_has_parallel)
17  set(NetCDF_HAS_PARALLEL TRUE PARENT_SCOPE)
18  else()
19  set(NetCDF_HAS_PARALLEL FALSE PARENT_SCOPE)
20  endif()
21 endfunction()
22 
23 # Try to find a CMake-built NetCDF.
24 find_package(netCDF CONFIG QUIET)
25 if (netCDF_FOUND)
26  # Forward the variables in a consistent way.
27  set(NetCDF_FOUND "${netCDF_FOUND}")
28  set(NetCDF_INCLUDE_DIRS "${netCDF_INCLUDE_DIR}")
29  set(NetCDF_LIBRARIES "${netCDF_LIBRARIES}")
30  set(NetCDF_VERSION "${NetCDFVersion}")
31 
32  include(FindPackageHandleStandardArgs)
33  find_package_handle_standard_args(NetCDF
34  REQUIRED_VARS NetCDF_INCLUDE_DIRS NetCDF_LIBRARIES
35  VERSION_VAR NetCDF_VERSION)
36 
37  if (NOT TARGET NetCDF::NetCDF)
38  add_library(NetCDF::NetCDF INTERFACE IMPORTED)
39  if (TARGET "netCDF::netcdf")
40  # 4.7.3
41  set_target_properties(NetCDF::NetCDF PROPERTIES
42  INTERFACE_LINK_LIBRARIES "netCDF::netcdf")
43  elseif (TARGET "netcdf")
44  set_target_properties(NetCDF::NetCDF PROPERTIES
45  INTERFACE_LINK_LIBRARIES "netcdf")
46  else ()
47  set_target_properties(NetCDF::NetCDF PROPERTIES
48  INTERFACE_LINK_LIBRARIES "${netCDF_LIBRARIES}")
49  endif ()
50  endif ()
51 
52  FindNetCDF_get_is_parallel_aware("${NetCDF_INCLUDE_DIRS}")
53  # Skip the rest of the logic in this file.
54  return ()
55 endif ()
56 
57 find_package(PkgConfig QUIET)
58 if (PkgConfig_FOUND)
59  pkg_check_modules(_NetCDF QUIET netcdf IMPORTED_TARGET)
60  if (_NetCDF_FOUND)
61  # Forward the variables in a consistent way.
62  set(NetCDF_FOUND "${_NetCDF_FOUND}")
63  set(NetCDF_INCLUDE_DIRS "${_NetCDF_INCLUDE_DIRS}")
64  set(NetCDF_LIBRARIES "${_NetCDF_LIBRARIES}")
65  set(NetCDF_VERSION "${_NetCDF_VERSION}")
66 
67  include(FindPackageHandleStandardArgs)
68  find_package_handle_standard_args(NetCDF
69  REQUIRED_VARS NetCDF_LIBRARIES
70  # This is not required because system-default include paths are not
71  # reported by `FindPkgConfig`, so this might be empty. Assume that if we
72  # have a library, the include directories are fine (if any) since
73  # PkgConfig reported that the package was found.
74  # NetCDF_INCLUDE_DIRS
75  VERSION_VAR NetCDF_VERSION)
76 
77  if (NOT TARGET NetCDF::NetCDF)
78  add_library(NetCDF::NetCDF INTERFACE IMPORTED)
79  set_target_properties(NetCDF::NetCDF PROPERTIES
80  INTERFACE_LINK_LIBRARIES "PkgConfig::_NetCDF")
81  endif ()
82 
83  FindNetCDF_get_is_parallel_aware("${_NetCDF_INCLUDEDIR}")
84  # Skip the rest of the logic in this file.
85  return ()
86  endif ()
87 endif ()
88 
89 find_path(NetCDF_INCLUDE_DIR
90  NAMES netcdf.h
91  DOC "netcdf include directories")
92 mark_as_advanced(NetCDF_INCLUDE_DIR)
93 
94 find_library(NetCDF_LIBRARY
95  NAMES netcdf
96  DOC "netcdf library")
97 mark_as_advanced(NetCDF_LIBRARY)
98 
99 if (NetCDF_INCLUDE_DIR)
100  file(STRINGS "${NetCDF_INCLUDE_DIR}/netcdf_meta.h" _netcdf_version_lines
101  REGEX "#define[ \t]+NC_VERSION_(MAJOR|MINOR|PATCH|NOTE)")
102  string(REGEX REPLACE ".*NC_VERSION_MAJOR *\([0-9]*\).*" "\\1" _netcdf_version_major "${_netcdf_version_lines}")
103  string(REGEX REPLACE ".*NC_VERSION_MINOR *\([0-9]*\).*" "\\1" _netcdf_version_minor "${_netcdf_version_lines}")
104  string(REGEX REPLACE ".*NC_VERSION_PATCH *\([0-9]*\).*" "\\1" _netcdf_version_patch "${_netcdf_version_lines}")
105  string(REGEX REPLACE ".*NC_VERSION_NOTE *\"\([^\"]*\)\".*" "\\1" _netcdf_version_note "${_netcdf_version_lines}")
106  set(NetCDF_VERSION "${_netcdf_version_major}.${_netcdf_version_minor}.${_netcdf_version_patch}${_netcdf_version_note}")
107  unset(_netcdf_version_major)
108  unset(_netcdf_version_minor)
109  unset(_netcdf_version_patch)
110  unset(_netcdf_version_note)
111  unset(_netcdf_version_lines)
112 
113  FindNetCDF_get_is_parallel_aware("${NetCDF_INCLUDE_DIR}")
114 endif ()
115 
116 include(FindPackageHandleStandardArgs)
117 find_package_handle_standard_args(NetCDF
118  REQUIRED_VARS NetCDF_LIBRARY NetCDF_INCLUDE_DIR
119  VERSION_VAR NetCDF_VERSION)
120 
121 if (NetCDF_FOUND)
122  set(NetCDF_INCLUDE_DIRS "${NetCDF_INCLUDE_DIR}")
123  set(NetCDF_LIBRARIES "${NetCDF_LIBRARY}")
124 
125  if (NOT TARGET NetCDF::NetCDF)
126  add_library(NetCDF::NetCDF UNKNOWN IMPORTED)
127  set_target_properties(NetCDF::NetCDF PROPERTIES
128  IMPORTED_LOCATION "${NetCDF_LIBRARY}"
129  INTERFACE_INCLUDE_DIRECTORIES "${NetCDF_INCLUDE_DIR}")
130  endif ()
131 endif ()
boost::graph_traits< vtkGraph *>::vertex_descriptor target(boost::graph_traits< vtkGraph *>::edge_descriptor e, vtkGraph *)
version
string
function FindNetCDF_get_is_parallel_aware(include_dir)
Provides the following variables: