FindPostgreSQL.cmake 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. # - Find the PostgreSQL installation.
  2. # Usage:
  3. # In your CMakeLists.txt file do something like this:
  4. # ...
  5. # # PostgreSQL
  6. # FIND_PACKAGE(PostgreSQL)
  7. # ...
  8. # if( PostgreSQL_FOUND )
  9. # include_directories(${PostgreSQL_INCLUDE_DIRS})
  10. # endif( PostgreSQL_FOUND )
  11. # ...
  12. # Remember to include ${PostgreSQL_LIBRARIES} in the target_link_libraries() statement.
  13. #
  14. #
  15. # In Windows, we make the assumption that, if the PostgreSQL files are installed, the default directory
  16. # will be C:\Program Files\PostgreSQL.
  17. #
  18. #=============================================================================
  19. # Copyright 2004-2009 Kitware, Inc.
  20. #
  21. # Distributed under the OSI-approved BSD License (the "License");
  22. # see accompanying file Copyright.txt for details.
  23. #
  24. # This software is distributed WITHOUT ANY WARRANTY; without even the
  25. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  26. # See the License for more information.
  27. #=============================================================================
  28. # (To distribute this file outside of CMake, substitute the full
  29. # License text for the above reference.)
  30. # ----------------------------------------------------------------------------
  31. # History:
  32. # This module is derived from the module originally found in the VTK source tree.
  33. #
  34. # ----------------------------------------------------------------------------
  35. # Note:
  36. # PostgreSQL_ADDITIONAL_VERSIONS is a variable that can be used to set the
  37. # version mumber of the implementation of PostgreSQL.
  38. # In Windows the default installation of PostgreSQL uses that as part of the path.
  39. # E.g C:\Program Files\PostgreSQL\8.4.
  40. # Currently, the following version numbers are known to this module:
  41. # "9.1" "9.0" "8.4" "8.3" "8.2" "8.1" "8.0"
  42. #
  43. # To use this variable just do something like this:
  44. # set(PostgreSQL_ADDITIONAL_VERSIONS "9.2" "8.4.4")
  45. # before calling FIND_PACKAGE(PostgreSQL) in your CMakeLists.txt file.
  46. # This will mean that the versions you set here will be found first in the order
  47. # specified before the default ones are searched.
  48. #
  49. # ----------------------------------------------------------------------------
  50. # You may need to manually set:
  51. # PostgreSQL_INCLUDE_DIR - the path to where the PostgreSQL include files are.
  52. # PostgreSQL_LIBRARY_DIR - The path to where the PostgreSQL library files are.
  53. # If FindPostgreSQL.cmake cannot find the include files or the library files.
  54. #
  55. # ----------------------------------------------------------------------------
  56. # The following variables are set if PostgreSQL is found:
  57. # PostgreSQL_FOUND - Set to true when PostgreSQL is found.
  58. # PostgreSQL_INCLUDE_DIRS - Include directories for PostgreSQL
  59. # PostgreSQL_LIBRARY_DIRS - Link directories for PostgreSQL libraries
  60. # PostgreSQL_LIBRARIES - The PostgreSQL libraries.
  61. #
  62. # ----------------------------------------------------------------------------
  63. # If you have installed PostgreSQL in a non-standard location.
  64. # (Please note that in the following comments, it is assumed that <Your Path>
  65. # points to the root directory of the include directory of PostgreSQL.)
  66. # Then you have three options.
  67. # 1) After CMake runs, set PostgreSQL_INCLUDE_DIR to <Your Path>/include and
  68. # PostgreSQL_LIBRARY_DIR to wherever the library pq (or libpq in windows) is
  69. # 2) Use CMAKE_INCLUDE_PATH to set a path to <Your Path>/PostgreSQL<-version>. This will allow find_path()
  70. # to locate PostgreSQL_INCLUDE_DIR by utilizing the PATH_SUFFIXES option. e.g. In your CMakeLists.txt file
  71. # SET(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "<Your Path>/include")
  72. # 3) Set an environment variable called ${PostgreSQL_ROOT} that points to the root of where you have
  73. # installed PostgreSQL, e.g. <Your Path>.
  74. #
  75. # ----------------------------------------------------------------------------
  76. set(PostgreSQL_INCLUDE_PATH_DESCRIPTION "top-level directory containing the PostgreSQL include directories. E.g /usr/local/include/PostgreSQL/8.4 or C:/Program Files/PostgreSQL/8.4/include")
  77. set(PostgreSQL_INCLUDE_DIR_MESSAGE "Set the PostgreSQL_INCLUDE_DIR cmake cache entry to the ${PostgreSQL_INCLUDE_PATH_DESCRIPTION}")
  78. set(PostgreSQL_LIBRARY_PATH_DESCRIPTION "top-level directory containing the PostgreSQL libraries.")
  79. set(PostgreSQL_LIBRARY_DIR_MESSAGE "Set the PostgreSQL_LIBRARY_DIR cmake cache entry to the ${PostgreSQL_LIBRARY_PATH_DESCRIPTION}")
  80. set(PostgreSQL_ROOT_DIR_MESSAGE "Set the PostgreSQL_ROOT system variable to where PostgreSQL is found on the machine E.g C:/Program Files/PostgreSQL/8.4")
  81. set(PostgreSQL_ROOT_DIRECTORIES $ENV{PostgreSQL_ROOT})
  82. if(PostgreSQL_ROOT_DIRECTORIES)
  83. file(TO_CMAKE_PATH ${PostgreSQL_ROOT_DIRECTORIES} PostgreSQL_ROOT_DIRECTORIES)
  84. endif(PostgreSQL_ROOT_DIRECTORIES)
  85. set(PostgreSQL_KNOWN_VERSIONS ${PostgreSQL_ADDITIONAL_VERSIONS}
  86. "9.1" "9.0" "8.4" "8.3" "8.2" "8.1" "8.0")
  87. # Define additional search paths for root directories.
  88. if ( WIN32 )
  89. foreach (suffix ${PostgreSQL_KNOWN_VERSIONS} )
  90. set(PostgreSQL_ADDITIONAL_SEARCH_PATHS ${PostgreSQL_ADDITIONAL_SEARCH_PATHS} "C:/Program Files/PostgreSQL/${suffix}" )
  91. endforeach(suffix)
  92. endif( WIN32 )
  93. set( PostgreSQL_ROOT_DIRECTORIES
  94. ${PostgreSQL_ROOT_DIRECTORIES}
  95. ${PostgreSQL_ROOT}
  96. ${PostgreSQL_ADDITIONAL_SEARCH_PATHS}
  97. )
  98. #
  99. # Look for an installation.
  100. #
  101. find_path(PostgreSQL_INCLUDE_DIR
  102. NAMES libpq-fe.h
  103. PATHS
  104. # Look in other places.
  105. ${PostgreSQL_ROOT_DIRECTORIES}
  106. PATH_SUFFIXES
  107. pgsql
  108. postgresql
  109. include
  110. # Help the user find it if we cannot.
  111. DOC "The ${PostgreSQL_INCLUDE_DIR_MESSAGE}"
  112. )
  113. find_path(PostgreSQL_TYPE_INCLUDE_DIR
  114. NAMES catalog/pg_type.h
  115. PATHS
  116. # Look in other places.
  117. ${PostgreSQL_ROOT_DIRECTORIES}
  118. PATH_SUFFIXES
  119. server
  120. pgsql
  121. postgresql
  122. include
  123. # Help the user find it if we cannot.
  124. DOC "The ${PostgreSQL_INCLUDE_DIR_MESSAGE}"
  125. )
  126. # The PostgreSQL library.
  127. set (PostgreSQL_LIBRARY_TO_FIND pq)
  128. # Setting some more prefixes for the library
  129. set (PostgreSQL_LIB_PREFIX "")
  130. if ( WIN32 )
  131. set (PostgreSQL_LIB_PREFIX ${PostgreSQL_LIB_PREFIX} "lib")
  132. set ( PostgreSQL_LIBRARY_TO_FIND ${PostgreSQL_LIB_PREFIX}${PostgreSQL_LIBRARY_TO_FIND})
  133. endif()
  134. find_library( PostgreSQL_LIBRARY
  135. NAMES ${PostgreSQL_LIBRARY_TO_FIND}
  136. PATHS
  137. ${PostgreSQL_ROOT_DIRECTORIES}
  138. PATH_SUFFIXES
  139. lib
  140. )
  141. get_filename_component(PostgreSQL_LIBRARY_DIR ${PostgreSQL_LIBRARY} PATH)
  142. # Did we find anything?
  143. include(FindPackageHandleStandardArgs)
  144. find_package_handle_standard_args(PostgreSQL DEFAULT_MSG
  145. PostgreSQL_INCLUDE_DIR PostgreSQL_TYPE_INCLUDE_DIR PostgreSQL_LIBRARY)
  146. set( PostgreSQL_FOUND ${POSTGRESQL_FOUND})
  147. # Now try to get the include and library path.
  148. if(PostgreSQL_FOUND)
  149. set(PostgreSQL_INCLUDE_DIRS ${PostgreSQL_INCLUDE_DIR} ${PostgreSQL_TYPE_INCLUDE_DIR} )
  150. set(PostgreSQL_LIBRARY_DIRS ${PostgreSQL_LIBRARY_DIR} )
  151. set(PostgreSQL_LIBRARIES ${PostgreSQL_LIBRARY_TO_FIND})
  152. #message("Final PostgreSQL include dir: ${PostgreSQL_INCLUDE_DIRS}")
  153. #message("Final PostgreSQL library dir: ${PostgreSQL_LIBRARY_DIRS}")
  154. #message("Final PostgreSQL libraries: ${PostgreSQL_LIBRARIES}")
  155. endif(PostgreSQL_FOUND)
  156. mark_as_advanced(PostgreSQL_INCLUDE_DIR PostgreSQL_TYPE_INCLUDE_DIR PostgreSQL_LIBRARY )