summaryrefslogtreecommitdiffstats
path: root/Modules/FindGDAL.cmake
diff options
context:
space:
mode:
authorPhilip Lowman <philip@yhbt.com>2009-01-31 06:50:40 (GMT)
committerPhilip Lowman <philip@yhbt.com>2009-01-31 06:50:40 (GMT)
commit1897b563d9b2568c9459e631047ed9c6c708e4b6 (patch)
tree84a3ea147d4976c5de229e4acc92be2ffcad848d /Modules/FindGDAL.cmake
parentaa45ec10bc8ed2c3f056c5eb3f23de392d055cff (diff)
downloadCMake-1897b563d9b2568c9459e631047ed9c6c708e4b6.zip
CMake-1897b563d9b2568c9459e631047ed9c6c708e4b6.tar.gz
CMake-1897b563d9b2568c9459e631047ed9c6c708e4b6.tar.bz2
BUG: Fix library detection for GDAL on most Linux distributions (Issue #7445)
Diffstat (limited to 'Modules/FindGDAL.cmake')
-rw-r--r--Modules/FindGDAL.cmake100
1 files changed, 60 insertions, 40 deletions
diff --git a/Modules/FindGDAL.cmake b/Modules/FindGDAL.cmake
index e21fe83..e69ee3f 100644
--- a/Modules/FindGDAL.cmake
+++ b/Modules/FindGDAL.cmake
@@ -1,8 +1,14 @@
# Locate gdal
-# This module defines
-# GDAL_LIBRARY
-# GDAL_FOUND, if false, do not try to link to gdal
-# GDAL_INCLUDE_DIR, where to find the headers
+#
+# This module accepts the following environment variables:
+#
+# GDAL_DIR or GDAL_ROOT - Specify the location of GDAL
+#
+# This module defines the following CMake variables:
+#
+# GDAL_FOUND - True if libgdal is found
+# GDAL_LIBRARY - A variable pointing to the GDAL library
+# GDAL_INCLUDE_DIR - Where to find the headers
#
# $GDALDIR is an environment variable that would
# correspond to the ./configure --prefix=$GDAL_DIR
@@ -17,57 +23,71 @@
# to happen).
# This makes the presumption that you are include gdal.h like
-# #include "gdal.h"
+#
+#include "gdal.h"
FIND_PATH(GDAL_INCLUDE_DIR gdal.h
HINTS
- $ENV{GDAL_DIR}
- PATH_SUFFIXES include
+ $ENV{GDAL_DIR}
+ $ENV{GDAL_ROOT}
+ PATH_SUFFIXES
+ include/gdal
+ include/GDAL
+ include
PATHS
- ~/Library/Frameworks/gdal.framework/Headers
- /Library/Frameworks/gdal.framework/Headers
- /usr/local/include/gdal
- /usr/local/include/GDAL
- /usr/local/include
- /usr/include/gdal
- /usr/include/GDAL
- /usr/include
- /sw/include/gdal
- /sw/include/GDAL
- /sw/include # Fink
- /opt/local/include/gdal
- /opt/local/include/GDAL
- /opt/local/include # DarwinPorts
- /opt/csw/include/gdal
- /opt/csw/include/GDAL
- /opt/csw/include # Blastwave
- /opt/include/gdal
- /opt/include/GDAL
- /opt/include
+ ~/Library/Frameworks/gdal.framework/Headers
+ /Library/Frameworks/gdal.framework/Headers
+ /sw # Fink
+ /opt/local # DarwinPorts
+ /opt/csw # Blastwave
+ /opt
)
+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...
+ FIND_PROGRAM(GDAL_CONFIG gdal-config
+ HINTS
+ $ENV{GDAL_DIR}
+ $ENV{GDAL_ROOT}
+ 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})
+ string(REGEX REPLACE "-l" "" _gdal_lib "${_gdal_dashl}")
+ string(REGEX MATCHALL "-L[^ ]+" _gdal_dashL ${GDAL_CONFIG_LIBS})
+ string(REGEX REPLACE "-L" "" _gdal_libpath "${_gdal_dashL}")
+ endif()
+ endif()
+endif()
+
FIND_LIBRARY(GDAL_LIBRARY
- NAMES gdal GDAL
+ NAMES ${_gdal_lib} gdal gdal_i gdal1.5.0 gdal1.4.0 gdal1.3.2 GDAL
HINTS
- $ENV{GDAL_DIR}
+ $ENV{GDAL_DIR}
+ $ENV{GDAL_ROOT}
+ ${_gdal_libpath}
PATH_SUFFIXES lib64 lib
PATHS
- ~/Library/Frameworks
- /Library/Frameworks
- /usr/local
- /usr
/sw
/opt/local
/opt/csw
/opt
/usr/freeware
- [HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session\ Manager\\Environment;GDAL_ROOT]/lib
)
-SET(GDAL_FOUND "NO")
-IF(GDAL_LIBRARY AND GDAL_INCLUDE_DIR)
- SET(GDAL_FOUND "YES")
-ENDIF(GDAL_LIBRARY AND GDAL_INCLUDE_DIR)
-
-
+include(FindPackageHandleStandardArgs)
+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})