Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Modules / FindGDAL.cmake
blobe69ee3f7aac058c1433bd839d247c9e74b6dc756
1 # Locate gdal
3 # This module accepts the following environment variables:
5 #    GDAL_DIR or GDAL_ROOT - Specify the location of GDAL
7 # This module defines the following CMake variables:
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
13 # $GDALDIR is an environment variable that would
14 # correspond to the ./configure --prefix=$GDAL_DIR
15 # used in building gdal.
17 # Created by Eric Wing. I'm not a gdal user, but OpenSceneGraph uses it 
18 # for osgTerrain so I whipped this module together for completeness.
19 # I actually don't know the conventions or where files are typically
20 # placed in distros.
21 # Any real gdal users are encouraged to correct this (but please don't
22 # break the OS X framework stuff when doing so which is what usually seems 
23 # to happen).
25 # This makes the presumption that you are include gdal.h like
27 #include "gdal.h"
29 FIND_PATH(GDAL_INCLUDE_DIR gdal.h
30   HINTS
31     $ENV{GDAL_DIR}
32     $ENV{GDAL_ROOT}
33   PATH_SUFFIXES
34      include/gdal
35      include/GDAL
36      include
37   PATHS
38       ~/Library/Frameworks/gdal.framework/Headers
39       /Library/Frameworks/gdal.framework/Headers
40       /sw # Fink
41       /opt/local # DarwinPorts
42       /opt/csw # Blastwave
43       /opt
46 IF(UNIX)
47     # Use gdal-config to obtain the library version (this should hopefully
48     # allow us to -lgdal1.x.y where x.y are correct version)
49     # For some reason, libgdal development packages do not contain
50     # libgdal.so...
51     FIND_PROGRAM(GDAL_CONFIG gdal-config
52         HINTS
53           $ENV{GDAL_DIR}
54           $ENV{GDAL_ROOT}
55         PATH_SUFFIXES bin
56         PATHS
57             /sw # Fink
58             /opt/local # DarwinPorts
59             /opt/csw # Blastwave
60             /opt
61     )
63     if(GDAL_CONFIG)
64         exec_program(${GDAL_CONFIG} ARGS --libs OUTPUT_VARIABLE GDAL_CONFIG_LIBS)
65         if(GDAL_CONFIG_LIBS)
66             string(REGEX MATCHALL "-l[^ ]+" _gdal_dashl ${GDAL_CONFIG_LIBS})
67             string(REGEX REPLACE "-l" "" _gdal_lib "${_gdal_dashl}")
68             string(REGEX MATCHALL "-L[^ ]+" _gdal_dashL ${GDAL_CONFIG_LIBS})
69             string(REGEX REPLACE "-L" "" _gdal_libpath "${_gdal_dashL}")
70         endif()
71     endif()
72 endif()
74 FIND_LIBRARY(GDAL_LIBRARY 
75   NAMES ${_gdal_lib} gdal gdal_i gdal1.5.0 gdal1.4.0 gdal1.3.2 GDAL
76   HINTS
77      $ENV{GDAL_DIR}
78      $ENV{GDAL_ROOT}
79      ${_gdal_libpath}
80   PATH_SUFFIXES lib64 lib
81   PATHS
82     /sw
83     /opt/local
84     /opt/csw
85     /opt
86     /usr/freeware
89 include(FindPackageHandleStandardArgs)
90 FIND_PACKAGE_HANDLE_STANDARD_ARGS(GDAL DEFAULT_MSG GDAL_LIBRARY GDAL_INCLUDE_DIR)
92 set(GDAL_LIBRARIES ${GDAL_LIBRARY})
93 set(GDAL_INCLUDE_DIRS ${GDAL_INCLUDE_DIR})