FindGDAL.cmake 3.3 KB
Newer Older
1
2
3
4
5
6
#.rst:
# FindGDAL
# --------
#
#
#
7
# Locate gdal
8
9
10
#
# This module accepts the following environment variables:
#
11
12
13
14
15
# ::
#
#     GDAL_DIR or GDAL_ROOT - Specify the location of GDAL
#
#
16
17
18
#
# This module defines the following CMake variables:
#
19
20
21
22
23
# ::
#
#     GDAL_FOUND - True if libgdal is found
#     GDAL_LIBRARY - A variable pointing to the GDAL library
#     GDAL_INCLUDE_DIR - Where to find the headers
24
25
26
27
28
29
30
31
32
33
34

#=============================================================================
# Copyright 2007-2009 Kitware, Inc.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
35
# (To distribute this file outside of CMake, substitute the full
36
37
#  License text for the above reference.)

38
39
40
41
42
#
# $GDALDIR is an environment variable that would
# correspond to the ./configure --prefix=$GDAL_DIR
# used in building gdal.
#
43
# Created by Eric Wing. I'm not a gdal user, but OpenSceneGraph uses it
44
45
46
47
# for osgTerrain so I whipped this module together for completeness.
# I actually don't know the conventions or where files are typically
# placed in distros.
# Any real gdal users are encouraged to correct this (but please don't
48
# break the OS X framework stuff when doing so which is what usually seems
49
50
51
# to happen).

# This makes the presumption that you are include gdal.h like
52
53
#
#include "gdal.h"
54

55
find_path(GDAL_INCLUDE_DIR gdal.h
56
  HINTS
57
58
    ENV GDAL_DIR
    ENV GDAL_ROOT
59
60
61
62
  PATH_SUFFIXES
     include/gdal
     include/GDAL
     include
63
  PATHS
64
65
66
67
68
69
      ~/Library/Frameworks/gdal.framework/Headers
      /Library/Frameworks/gdal.framework/Headers
      /sw # Fink
      /opt/local # DarwinPorts
      /opt/csw # Blastwave
      /opt
70
71
)

72
if(UNIX)
73
74
75
76
    # Use gdal-config to obtain the library version (this should hopefully
    # allow us to -lgdal1.x.y where x.y are correct version)
    # For some reason, libgdal development packages do not contain
    # libgdal.so...
77
    find_program(GDAL_CONFIG gdal-config
78
        HINTS
79
80
          ENV GDAL_DIR
          ENV GDAL_ROOT
81
82
83
84
85
86
87
88
89
90
91
92
        PATH_SUFFIXES bin
        PATHS
            /sw # Fink
            /opt/local # DarwinPorts
            /opt/csw # Blastwave
            /opt
    )

    if(GDAL_CONFIG)
        exec_program(${GDAL_CONFIG} ARGS --libs OUTPUT_VARIABLE GDAL_CONFIG_LIBS)
        if(GDAL_CONFIG_LIBS)
            string(REGEX MATCHALL "-l[^ ]+" _gdal_dashl ${GDAL_CONFIG_LIBS})
93
            string(REPLACE "-l" "" _gdal_lib "${_gdal_dashl}")
94
            string(REGEX MATCHALL "-L[^ ]+" _gdal_dashL ${GDAL_CONFIG_LIBS})
95
            string(REPLACE "-L" "" _gdal_libpath "${_gdal_dashL}")
96
97
98
99
        endif()
    endif()
endif()

100
find_library(GDAL_LIBRARY
101
  NAMES ${_gdal_lib} gdal gdal_i gdal1.5.0 gdal1.4.0 gdal1.3.2 GDAL
102
  HINTS
103
104
     ENV GDAL_DIR
     ENV GDAL_ROOT
105
     ${_gdal_libpath}
106
  PATH_SUFFIXES lib
107
108
109
110
111
112
113
114
  PATHS
    /sw
    /opt/local
    /opt/csw
    /opt
    /usr/freeware
)

115
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
116
FIND_PACKAGE_HANDLE_STANDARD_ARGS(GDAL DEFAULT_MSG GDAL_LIBRARY GDAL_INCLUDE_DIR)
117

118
119
set(GDAL_LIBRARIES ${GDAL_LIBRARY})
set(GDAL_INCLUDE_DIRS ${GDAL_INCLUDE_DIR})