-
Notifications
You must be signed in to change notification settings - Fork 0
/
FindnetCDF.cmake
120 lines (101 loc) · 4.29 KB
/
FindnetCDF.cmake
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Adapted from
# https://gitlab.kitware.com/vtk/vtk/-/blob/master/CMake/FindnetCDF.cmake
#[==[
Provides the following variables:
* `netCDF_FOUND`: Whether netCDF was found or not.
* `netCDF_INCLUDE_DIRS`: Include directories necessary to use netCDF.
* `netCDF_LIBRARIES`: Libraries necessary to use netCDF.
* `netCDF_VERSION`: The version of netCDF found.
* `netCDF::netcdf`: A target to use with `target_link_libraries`.
* `netCDF_HAS_PARALLEL`: Whether or not netCDF was found with parallel IO support.
#]==]
list(APPEND CMAKE_MESSAGE_CONTEXT FindnetCDF)
function(FindnetCDF_get_is_parallel_aware include_dir)
file(STRINGS "${include_dir}/netcdf_meta.h" _netcdf_lines
REGEX "#define[ \t]+NC_HAS_PARALLEL[ \t]")
# (netcdf_meta.h exists since version 4.3.3-rc2)
string(REGEX REPLACE ".*NC_HAS_PARALLEL[ \t]*([0-1]+).*" "\\1"
_netcdf_has_parallel "${_netcdf_lines}")
if (_netcdf_has_parallel)
set(netCDF_HAS_PARALLEL TRUE PARENT_SCOPE)
else()
set(netCDF_HAS_PARALLEL FALSE PARENT_SCOPE)
endif()
endfunction()
find_package(PkgConfig QUIET)
if (PkgConfig_FOUND)
pkg_check_modules(_netCDF QUIET netcdf IMPORTED_TARGET)
if (_netCDF_FOUND)
unset(netCDF_DIR CACHE)
pkg_get_variable(netcdf_pcfiledir netcdf pcfiledir)
message(DEBUG "Location of .pc file: ${netcdf_pcfiledir}")
message(VERBOSE "netCDF include directories: ${_netCDF_INCLUDE_DIRS}")
message(VERBOSE "netCDF libraries: ${_netCDF_LINK_LIBRARIES}")
# Forward the variables in a consistent way.
set(netCDF_FOUND "${_netCDF_FOUND}")
set(netCDF_INCLUDE_DIRS "${_netCDF_INCLUDE_DIRS}")
set(netCDF_LIBRARIES "${_netCDF_LIBRARIES}")
set(netCDF_VERSION "${_netCDF_VERSION}")
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(netCDF
REQUIRED_VARS netCDF_LIBRARIES
# netCDF_INCLUDE_DIRS is not required because system-default
# include paths are not reported by `FindPkgConfig`, so this
# might be empty. Assume that if we have a library, the include
# directories are fine (if any) since PkgConfig reported that
# the package was found.
VERSION_VAR netCDF_VERSION)
if (NOT TARGET netCDF::netcdf)
add_library(netCDF::netcdf INTERFACE IMPORTED)
set_target_properties(netCDF::netcdf PROPERTIES
INTERFACE_LINK_LIBRARIES "PkgConfig::_netCDF")
endif ()
FindnetCDF_get_is_parallel_aware("${_netCDF_INCLUDEDIR}")
endif ()
endif ()
if (NOT PkgConfig_FOUND OR NOT _netCDF_FOUND)
find_path(netCDF_INCLUDE_DIR
NAMES netcdf.h
DOC "netcdf include directories")
##mark_as_advanced(netCDF_INCLUDE_DIR)
find_library(netCDF_LIBRARY
NAMES netcdf
DOC "netcdf library")
##mark_as_advanced(netCDF_LIBRARY)
if (netCDF_INCLUDE_DIR)
unset(netCDF_DIR CACHE)
file(STRINGS "${netCDF_INCLUDE_DIR}/netcdf_meta.h" _netcdf_version_lines
REGEX "#define[ \t]+NC_VERSION_(MAJOR|MINOR|PATCH|NOTE)")
string(REGEX REPLACE ".*NC_VERSION_MAJOR *\([0-9]*\).*" "\\1"
_netcdf_version_major "${_netcdf_version_lines}")
string(REGEX REPLACE ".*NC_VERSION_MINOR *\([0-9]*\).*" "\\1"
_netcdf_version_minor "${_netcdf_version_lines}")
string(REGEX REPLACE ".*NC_VERSION_PATCH *\([0-9]*\).*" "\\1"
_netcdf_version_patch "${_netcdf_version_lines}")
string(REGEX REPLACE ".*NC_VERSION_NOTE *\"\([^\"]*\)\".*" "\\1"
_netcdf_version_note "${_netcdf_version_lines}")
set(netCDF_VERSION
"${_netcdf_version_major}.${_netcdf_version_minor}.${_netcdf_version_patch}${_netcdf_version_note}")
unset(_netcdf_version_major)
unset(_netcdf_version_minor)
unset(_netcdf_version_patch)
unset(_netcdf_version_note)
unset(_netcdf_version_lines)
FindnetCDF_get_is_parallel_aware("${netCDF_INCLUDE_DIR}")
endif ()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(netCDF
REQUIRED_VARS netCDF_LIBRARY netCDF_INCLUDE_DIR
VERSION_VAR netCDF_VERSION)
if (netCDF_FOUND)
set(netCDF_INCLUDE_DIRS "${netCDF_INCLUDE_DIR}")
set(netCDF_LIBRARIES "${netCDF_LIBRARY}")
if (NOT TARGET netCDF::netcdf)
add_library(netCDF::netcdf UNKNOWN IMPORTED)
set_target_properties(netCDF::netcdf PROPERTIES
IMPORTED_LOCATION "${netCDF_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${netCDF_INCLUDE_DIR}")
endif ()
endif ()
endif()
list(POP_BACK CMAKE_MESSAGE_CONTEXT)