FindGDAL.cmake 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #.rst:
  4. # FindGDAL
  5. # --------
  6. #
  7. #
  8. #
  9. # Locate gdal
  10. #
  11. # This module accepts the following environment variables:
  12. #
  13. # ::
  14. #
  15. # GDAL_DIR or GDAL_ROOT - Specify the location of GDAL
  16. #
  17. #
  18. #
  19. # This module defines the following CMake variables:
  20. #
  21. # ::
  22. #
  23. # GDAL_FOUND - True if libgdal is found
  24. # GDAL_LIBRARY - A variable pointing to the GDAL library
  25. # GDAL_INCLUDE_DIR - Where to find the headers
  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. # This makes the presumption that you are include gdal.h like
  39. #
  40. #include "gdal.h"
  41. find_path(GDAL_INCLUDE_DIR gdal.h
  42. HINTS
  43. ENV GDAL_DIR
  44. ENV GDAL_ROOT
  45. PATH_SUFFIXES
  46. include/gdal
  47. include/GDAL
  48. include
  49. )
  50. if(UNIX)
  51. # Use gdal-config to obtain the library version (this should hopefully
  52. # allow us to -lgdal1.x.y where x.y are correct version)
  53. # For some reason, libgdal development packages do not contain
  54. # libgdal.so...
  55. find_program(GDAL_CONFIG gdal-config
  56. HINTS
  57. ENV GDAL_DIR
  58. ENV GDAL_ROOT
  59. PATH_SUFFIXES bin
  60. )
  61. if(GDAL_CONFIG)
  62. exec_program(${GDAL_CONFIG} ARGS --libs OUTPUT_VARIABLE GDAL_CONFIG_LIBS)
  63. if(GDAL_CONFIG_LIBS)
  64. string(REGEX MATCHALL "-l[^ ]+" _gdal_dashl ${GDAL_CONFIG_LIBS})
  65. string(REPLACE "-l" "" _gdal_lib "${_gdal_dashl}")
  66. string(REGEX MATCHALL "-L[^ ]+" _gdal_dashL ${GDAL_CONFIG_LIBS})
  67. string(REPLACE "-L" "" _gdal_libpath "${_gdal_dashL}")
  68. endif()
  69. endif()
  70. endif()
  71. find_library(GDAL_LIBRARY
  72. NAMES ${_gdal_lib} gdal gdal_i gdal1.5.0 gdal1.4.0 gdal1.3.2 GDAL
  73. HINTS
  74. ENV GDAL_DIR
  75. ENV GDAL_ROOT
  76. ${_gdal_libpath}
  77. PATH_SUFFIXES lib
  78. )
  79. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  80. FIND_PACKAGE_HANDLE_STANDARD_ARGS(GDAL DEFAULT_MSG GDAL_LIBRARY GDAL_INCLUDE_DIR)
  81. set(GDAL_LIBRARIES ${GDAL_LIBRARY})
  82. set(GDAL_INCLUDE_DIRS ${GDAL_INCLUDE_DIR})