cmake/Modules/FindGDAL.cmake

92 lines
2.5 KiB
CMake
Raw Normal View History

2016-10-30 18:24:19 +01:00
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
2014-08-03 19:52:23 +02:00
#.rst:
# FindGDAL
# --------
#
#
#
# Locate gdal
#
# This module accepts the following environment variables:
#
2014-08-03 19:52:23 +02:00
# ::
#
# GDAL_DIR or GDAL_ROOT - Specify the location of GDAL
#
#
#
# This module defines the following CMake variables:
#
2014-08-03 19:52:23 +02:00
# ::
#
# GDAL_FOUND - True if libgdal is found
# GDAL_LIBRARY - A variable pointing to the GDAL library
# GDAL_INCLUDE_DIR - Where to find the headers
2009-10-04 10:30:41 +03:00
#
# $GDALDIR is an environment variable that would
# correspond to the ./configure --prefix=$GDAL_DIR
# used in building gdal.
#
2013-03-16 19:13:01 +02:00
# Created by Eric Wing. I'm not a gdal user, but OpenSceneGraph uses it
# 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
2013-03-16 19:13:01 +02:00
# break the OS X framework stuff when doing so which is what usually seems
# to happen).
# This makes the presumption that you are include gdal.h like
#
#include "gdal.h"
2013-03-16 19:13:01 +02:00
find_path(GDAL_INCLUDE_DIR gdal.h
HINTS
2013-03-16 19:13:01 +02:00
ENV GDAL_DIR
ENV GDAL_ROOT
PATH_SUFFIXES
include/gdal
include/GDAL
include
)
2013-03-16 19:13:01 +02:00
if(UNIX)
# 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...
2013-03-16 19:13:01 +02:00
find_program(GDAL_CONFIG gdal-config
HINTS
2013-03-16 19:13:01 +02:00
ENV GDAL_DIR
ENV GDAL_ROOT
PATH_SUFFIXES bin
)
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})
2015-04-27 22:25:09 +02:00
string(REPLACE "-l" "" _gdal_lib "${_gdal_dashl}")
string(REGEX MATCHALL "-L[^ ]+" _gdal_dashL ${GDAL_CONFIG_LIBS})
2015-04-27 22:25:09 +02:00
string(REPLACE "-L" "" _gdal_libpath "${_gdal_dashL}")
endif()
endif()
endif()
2013-03-16 19:13:01 +02:00
find_library(GDAL_LIBRARY
NAMES ${_gdal_lib} gdal gdal_i gdal1.5.0 gdal1.4.0 gdal1.3.2 GDAL
HINTS
2013-03-16 19:13:01 +02:00
ENV GDAL_DIR
ENV GDAL_ROOT
${_gdal_libpath}
2013-03-16 19:13:01 +02:00
PATH_SUFFIXES lib
)
2011-02-07 16:37:25 +01:00
include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(GDAL DEFAULT_MSG GDAL_LIBRARY GDAL_INCLUDE_DIR)
set(GDAL_LIBRARIES ${GDAL_LIBRARY})
set(GDAL_INCLUDE_DIRS ${GDAL_INCLUDE_DIR})