Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

FindNETCDF.cmake 4.4 KB

You have to be logged in to leave a comment. Sign In
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
  1. #
  2. # $Id$
  3. #
  4. # Locate netcdf
  5. #
  6. # This module accepts the following environment variables:
  7. #
  8. # NETCDF_DIR or NETCDF_ROOT - Specify the location of NetCDF
  9. #
  10. # This module defines the following CMake variables:
  11. #
  12. # NETCDF_FOUND - True if libnetcdf is found
  13. # NETCDF_LIBRARY - A variable pointing to the NetCDF library
  14. # NETCDF_INCLUDE_DIR - Where to find the headers
  15. # NETCDF_INCLUDE_DIRS - Where to find the headers
  16. # NETCDF_DEFINITIONS - Extra compiler flags
  17. #=============================================================================
  18. # Inspired by FindGDAL
  19. #
  20. # Distributed under the OSI-approved bsd license (the "License")
  21. #
  22. # This software is distributed WITHOUT ANY WARRANTY; without even the
  23. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  24. # See COPYING-CMAKE-SCRIPTS for more information.
  25. #=============================================================================
  26. # This makes the presumption that you are include netcdf.h like
  27. #
  28. #include "netcdf.h"
  29. if (UNIX AND NOT NETCDF_FOUND)
  30. # Use nc-config to obtain the libraries
  31. find_program (NETCDF_CONFIG nc-config
  32. HINTS
  33. ${NETCDF_DIR}
  34. ${NETCDF_ROOT}
  35. $ENV{NETCDF_DIR}
  36. $ENV{NETCDF_ROOT}
  37. PATH_SUFFIXES bin
  38. PATHS
  39. /sw # Fink
  40. /opt/local # DarwinPorts
  41. /opt/csw # Blastwave
  42. /opt
  43. /usr/local
  44. )
  45. if (NETCDF_CONFIG)
  46. execute_process (COMMAND ${NETCDF_CONFIG} --cflags
  47. ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
  48. OUTPUT_VARIABLE NETCDF_CONFIG_CFLAGS)
  49. if (NETCDF_CONFIG_CFLAGS)
  50. string (REGEX MATCHALL "(^| )-I[^ ]+" _netcdf_dashI ${NETCDF_CONFIG_CFLAGS})
  51. string (REGEX REPLACE "(^| )-I" "" _netcdf_includepath "${_netcdf_dashI}")
  52. string (REGEX REPLACE "(^| )-I[^ ]+" "" _netcdf_cflags_other ${NETCDF_CONFIG_CFLAGS})
  53. endif (NETCDF_CONFIG_CFLAGS)
  54. execute_process (COMMAND ${NETCDF_CONFIG} --libs
  55. ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
  56. OUTPUT_VARIABLE NETCDF_CONFIG_LIBS)
  57. if (NETCDF_CONFIG_LIBS)
  58. # Ensure -l is precedeced by whitespace to not match
  59. # '-l' in '-L/usr/lib/x86_64-linux-gnu/hdf5/serial'
  60. string (REGEX MATCHALL "(^| )-l[^ ]+" _netcdf_dashl ${NETCDF_CONFIG_LIBS})
  61. string (REGEX REPLACE "(^| )-l" "" _netcdf_lib "${_netcdf_dashl}")
  62. string (REGEX MATCHALL "(^| )-L[^ ]+" _netcdf_dashL ${NETCDF_CONFIG_LIBS})
  63. string (REGEX REPLACE "(^| )-L" "" _netcdf_libpath "${_netcdf_dashL}")
  64. endif (NETCDF_CONFIG_LIBS)
  65. endif (NETCDF_CONFIG)
  66. if (_netcdf_lib)
  67. list (REMOVE_DUPLICATES _netcdf_lib)
  68. list (REMOVE_ITEM _netcdf_lib netcdf)
  69. endif (_netcdf_lib)
  70. endif (UNIX AND NOT NETCDF_FOUND)
  71. find_path (NETCDF_INCLUDE_DIR netcdf.h
  72. HINTS
  73. ${_netcdf_includepath}
  74. ${NETCDF_DIR}
  75. ${NETCDF_ROOT}
  76. $ENV{NETCDF_DIR}
  77. $ENV{NETCDF_ROOT}
  78. PATH_SUFFIXES
  79. include/netcdf
  80. include/netcdf-4
  81. include/netcdf-3
  82. include
  83. PATHS
  84. /sw # Fink
  85. /opt/local # DarwinPorts
  86. /opt/csw # Blastwave
  87. /opt
  88. /usr/local
  89. )
  90. find_library (NETCDF_LIBRARY
  91. NAMES netcdf
  92. HINTS
  93. ${_netcdf_libpath}
  94. ${NETCDF_DIR}
  95. ${NETCDF_ROOT}
  96. $ENV{NETCDF_DIR}
  97. $ENV{NETCDF_ROOT}
  98. PATH_SUFFIXES lib
  99. PATHS
  100. /sw
  101. /opt/local
  102. /opt/csw
  103. /opt
  104. /usr/local
  105. )
  106. # find all libs that nc-config reports
  107. foreach (_extralib ${_netcdf_lib})
  108. find_library (_found_lib_${_extralib}
  109. NAMES ${_extralib}
  110. PATHS ${_netcdf_libpath})
  111. list (APPEND NETCDF_LIBRARY ${_found_lib_${_extralib}})
  112. endforeach (_extralib)
  113. if (NETCDF_LIBRARY AND NETCDF_INCLUDE_DIR AND NOT HAVE_NETCDF4)
  114. # Ensure that NetCDF with version 4 extensions is installed
  115. include (CMakePushCheckState)
  116. include (CheckSymbolExists)
  117. cmake_push_check_state() # save state of CMAKE_REQUIRED_*
  118. set (CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${NETCDF_INCLUDE_DIR})
  119. set (CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${NETCDF_LIBRARY})
  120. set (HAVE_NETCDF4 HAVE_NETCDF4) # to force check_symbol_exists again
  121. check_symbol_exists (nc_def_var_deflate netcdf.h HAVE_NETCDF4)
  122. cmake_pop_check_state() # restore state of CMAKE_REQUIRED_*
  123. if (NOT HAVE_NETCDF4)
  124. message (SEND_ERROR "Library found but netCDF-4/HDF5 format unsupported. Do not configure netCDF-4 with --disable-netcdf-4.")
  125. endif (NOT HAVE_NETCDF4)
  126. endif (NETCDF_LIBRARY AND NETCDF_INCLUDE_DIR AND NOT HAVE_NETCDF4)
  127. include (FindPackageHandleStandardArgs)
  128. find_package_handle_standard_args (NETCDF
  129. DEFAULT_MSG NETCDF_LIBRARY NETCDF_INCLUDE_DIR HAVE_NETCDF4)
  130. set (NETCDF_LIBRARIES ${NETCDF_LIBRARY})
  131. set (NETCDF_INCLUDE_DIRS ${NETCDF_INCLUDE_DIR})
  132. string (REPLACE "-DNDEBUG" "" NETCDF_DEFINITIONS "${_netcdf_cflags_other}")
  133. # vim: textwidth=78 noexpandtab tabstop=2 softtabstop=2 shiftwidth=2
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...