FindGDAL.cmake 3.3 KB

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