FindGDAL.cmake
Go to the documentation of this file.
1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
3 
4 #[=======================================================================[.rst:
5 FindGDAL
6 --------
7 
8 Find GDAL.
9 
10 IMPORTED Targets
11 ^^^^^^^^^^^^^^^^
12 
13 This module defines :prop_tgt:`IMPORTED` target ``GDAL::GDAL``
14 if GDAL has been found.
15 
16 Result Variables
17 ^^^^^^^^^^^^^^^^
18 
19 This module will set the following variables in your project:
20 
21 ``GDAL_FOUND``
22  True if GDAL is found.
23 ``GDAL_INCLUDE_DIRS``
24  Include directories for GDAL headers.
25 ``GDAL_LIBRARIES``
26  Libraries to link to GDAL.
27 ``GDAL_VERSION``
28  The version of GDAL found.
29 
30 Cache variables
31 ^^^^^^^^^^^^^^^
32 
33 The following cache variables may also be set:
34 
35 ``GDAL_LIBRARY``
36  The libgdal library file.
37 ``GDAL_INCLUDE_DIR``
38  The directory containing ``gdal.h``.
39 
40 Hints
41 ^^^^^
42 
43 Set ``GDAL_DIR`` or ``GDAL_ROOT`` in the environment to specify the
44 GDAL installation prefix.
45 #]=======================================================================]
46 
47 # $GDALDIR is an environment variable that would
48 # correspond to the ./configure --prefix=$GDAL_DIR
49 # used in building gdal.
50 #
51 # Created by Eric Wing. I'm not a gdal user, but OpenSceneGraph uses it
52 # for osgTerrain so I whipped this module together for completeness.
53 # I actually don't know the conventions or where files are typically
54 # placed in distros.
55 # Any real gdal users are encouraged to correct this (but please don't
56 # break the OS X framework stuff when doing so which is what usually seems
57 # to happen).
58 
59 # This makes the presumption that you are include gdal.h like
60 #
61 #include "gdal.h"
62 
63 find_path(GDAL_INCLUDE_DIR gdal.h
64  HINTS
65  ${GDAL_ROOT}
66  ENV GDAL_DIR
67  ENV GDAL_ROOT
68  PATH_SUFFIXES
69  include/gdal
70  include/GDAL
71  include
72  DOC "Path to the GDAL include directory"
73 )
74 mark_as_advanced(GDAL_INCLUDE_DIR)
75 
76 # GDAL name its library when built with CMake as `gdal${major}${minor}`.
77 set(_gdal_versions
78  3.0 2.4 2.3 2.2 2.1 2.0 1.11 1.10 1.9 1.8 1.7 1.6 1.5 1.4 1.3 1.2)
79 
80 set(_gdal_libnames)
81 foreach (_gdal_version IN LISTS _gdal_versions)
82  string(REPLACE "." "" _gdal_version "${_gdal_version}")
83  list(APPEND _gdal_libnames "gdal${_gdal_version}" "GDAL${_gdal_version}")
84 endforeach ()
85 
86 find_library(GDAL_LIBRARY
87  NAMES ${_gdal_libnames} gdal gdal_i gdal1.5.0 gdal1.4.0 gdal1.3.2 GDAL
88  HINTS
89  ${GDAL_ROOT}
90  ENV GDAL_DIR
91  ENV GDAL_ROOT
92  DOC "Path to the GDAL library"
93 )
94 mark_as_advanced(GDAL_LIBRARY)
95 
96 if (EXISTS "${GDAL_INCLUDE_DIR}/gdal_version.h")
97  file(STRINGS "${GDAL_INCLUDE_DIR}/gdal_version.h" _gdal_version
98  REGEX "GDAL_RELEASE_NAME")
99  string(REGEX REPLACE ".*\"\(.*\)\"" "\\1" GDAL_VERSION "${_gdal_version}")
100  unset(_gdal_version)
101 else ()
102  set(GDAL_VERSION GDAL_VERSION-NOTFOUND)
103 endif ()
104 
105 include(FindPackageHandleStandardArgs)
106 find_package_handle_standard_args(GDAL
107  VERSION_VAR GDAL_VERSION
108  REQUIRED_VARS GDAL_LIBRARY GDAL_INCLUDE_DIR)
109 
110 if (GDAL_FOUND)
111  set(GDAL_LIBRARIES ${GDAL_LIBRARY})
112  set(GDAL_INCLUDE_DIRS ${GDAL_INCLUDE_DIR})
113 
114  if (NOT TARGET GDAL::GDAL)
115  add_library(GDAL::GDAL UNKNOWN IMPORTED)
116  set_target_properties(GDAL::GDAL PROPERTIES
117  IMPORTED_LOCATION "${GDAL_LIBRARY}"
118  INTERFACE_INCLUDE_DIRECTORIES "${GDAL_INCLUDE_DIR}")
119  endif ()
120 endif ()
boost::graph_traits< vtkGraph *>::vertex_descriptor target(boost::graph_traits< vtkGraph *>::edge_descriptor e, vtkGraph *)
version
string