Skip to content

Commit 07bb2d2

Browse files
authored
Add cmake/FindGDAL.cmake (copied from mapserver) (#276)
1 parent 483aaf8 commit 07bb2d2

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

cmake/FindGDAL.cmake

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# Locate gdal
2+
#
3+
# This module accepts the following environment variables:
4+
#
5+
# GDAL_DIR or GDAL_ROOT - Specify the location of GDAL
6+
#
7+
# This module defines the following CMake variables:
8+
#
9+
# GDAL_FOUND - True if libgdal is found
10+
# GDAL_LIBRARY - A variable pointing to the GDAL library
11+
# GDAL_INCLUDE_DIR - Where to find the headers
12+
13+
#=============================================================================
14+
# Copyright 2007-2009 Kitware, Inc.
15+
#
16+
# Distributed under the OSI-approved BSD License (the "License");
17+
# see accompanying file Copyright.txt for details.
18+
#
19+
# This software is distributed WITHOUT ANY WARRANTY; without even the
20+
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21+
# See the License for more information.
22+
#=============================================================================
23+
# (To distribute this file outside of CMake, substitute the full
24+
# License text for the above reference.)
25+
26+
#
27+
# $GDALDIR is an environment variable that would
28+
# correspond to the ./configure --prefix=$GDAL_DIR
29+
# used in building gdal.
30+
#
31+
# Created by Eric Wing. I'm not a gdal user, but OpenSceneGraph uses it
32+
# for osgTerrain so I whipped this module together for completeness.
33+
# I actually don't know the conventions or where files are typically
34+
# placed in distros.
35+
# Any real gdal users are encouraged to correct this (but please don't
36+
# break the OS X framework stuff when doing so which is what usually seems
37+
# to happen).
38+
39+
# This makes the presumption that you are include gdal.h like
40+
#
41+
#include "gdal.h"
42+
43+
find_path(GDAL_INCLUDE_DIR gdal.h
44+
HINTS
45+
ENV GDAL_DIR
46+
ENV GDAL_ROOT
47+
PATH_SUFFIXES
48+
gdal
49+
GDAL
50+
gdal1
51+
PATHS
52+
/sw # Fink
53+
/opt/local # DarwinPorts
54+
/opt/csw # Blastwave
55+
/opt
56+
)
57+
58+
if(UNIX)
59+
# Use gdal-config to obtain the library version (this should hopefully
60+
# allow us to -lgdal1.x.y where x.y are correct version)
61+
# For some reason, libgdal development packages do not contain
62+
# libgdal.so...
63+
find_program(GDAL_CONFIG gdal-config
64+
HINTS
65+
ENV GDAL_DIR
66+
ENV GDAL_ROOT
67+
PATH_SUFFIXES bin
68+
PATHS
69+
/sw # Fink
70+
/opt/local # DarwinPorts
71+
/opt/csw # Blastwave
72+
/opt
73+
)
74+
75+
if(GDAL_CONFIG)
76+
exec_program(${GDAL_CONFIG} ARGS --libs OUTPUT_VARIABLE GDAL_CONFIG_LIBS)
77+
if(GDAL_CONFIG_LIBS)
78+
string(REGEX MATCHALL "-l[^ ]+" _gdal_dashl ${GDAL_CONFIG_LIBS})
79+
string(REGEX REPLACE "-l" "" _gdal_lib "${_gdal_dashl}")
80+
string(REGEX MATCHALL "-L[^ ]+" _gdal_dashL ${GDAL_CONFIG_LIBS})
81+
string(REGEX REPLACE "-L" "" _gdal_libpath "${_gdal_dashL}")
82+
endif()
83+
endif()
84+
endif()
85+
86+
find_library(GDAL_LIBRARY
87+
NAMES ${_gdal_lib} gdal gdal_i gdal1.5.0 gdal1.4.0 gdal1.3.2 GDAL
88+
HINTS
89+
ENV GDAL_DIR
90+
ENV GDAL_ROOT
91+
${_gdal_libpath}
92+
PATH_SUFFIXES lib
93+
PATHS
94+
/sw
95+
/opt/local
96+
/opt/csw
97+
/opt
98+
/usr/freeware
99+
)
100+
101+
set(GDAL_LIBRARIES ${GDAL_LIBRARY})
102+
set(GDAL_INCLUDE_DIRS ${GDAL_INCLUDE_DIR})
103+
include(FindPackageHandleStandardArgs)
104+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(GDAL DEFAULT_MSG GDAL_LIBRARY GDAL_INCLUDE_DIR)
105+
MARK_AS_ADVANCED(GDAL_LIBRARY GDAL_INCLUDE_DIR GDAL_CONFIG)
106+

0 commit comments

Comments
 (0)