2018-06-03 18:17:50 +02:00
# TODO(Bjoe) This is taken from cmake 3.10. For poco we need some changes here. Maybe we create an issue on cmake project
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
#.rst:
# FindPostgreSQL
# --------------
#
# Find the PostgreSQL installation.
#
# This module defines
2012-06-26 14:37:02 +02:00
#
2018-06-03 18:17:50 +02:00
# ::
#
# PostgreSQL_LIBRARIES - the PostgreSQL libraries needed for linking
# PostgreSQL_INCLUDE_DIRS - the directories of the PostgreSQL headers
# PostgreSQL_LIBRARY_DIRS - the link directories for PostgreSQL libraries
2018-10-10 13:43:34 +02:00
# PostgreSQL_VERSION - the version of PostgreSQL found (since CMake 2.8.8)
2012-06-26 14:37:02 +02:00
2018-06-03 18:17:50 +02:00
# ----------------------------------------------------------------------------
# History:
# This module is derived from the module originally found in the VTK source tree.
#
# ----------------------------------------------------------------------------
# Note:
# PostgreSQL_ADDITIONAL_VERSIONS is a variable that can be used to set the
# version mumber of the implementation of PostgreSQL.
# In Windows the default installation of PostgreSQL uses that as part of the path.
# E.g C:\Program Files\PostgreSQL\8.4.
# Currently, the following version numbers are known to this module:
# "9.6" "9.5" "9.4" "9.3" "9.2" "9.1" "9.0" "8.4" "8.3" "8.2" "8.1" "8.0"
#
# To use this variable just do something like this:
# set(PostgreSQL_ADDITIONAL_VERSIONS "9.2" "8.4.4")
# before calling find_package(PostgreSQL) in your CMakeLists.txt file.
# This will mean that the versions you set here will be found first in the order
# specified before the default ones are searched.
#
# ----------------------------------------------------------------------------
# You may need to manually set:
2018-10-10 13:43:34 +02:00
# PostgreSQL_ROOT_DIR - that points to the root of where you have installed PostgreSQL
2018-06-03 18:17:50 +02:00
# PostgreSQL_INCLUDE_DIR - the path to where the PostgreSQL include files are.
# PostgreSQL_LIBRARY_DIR - The path to where the PostgreSQL library files are.
# If FindPostgreSQL.cmake cannot find the include files or the library files.
#
# ----------------------------------------------------------------------------
# The following variables are set if PostgreSQL is found:
# PostgreSQL_FOUND - Set to true when PostgreSQL is found.
# PostgreSQL_INCLUDE_DIRS - Include directories for PostgreSQL
# PostgreSQL_LIBRARY_DIRS - Link directories for PostgreSQL libraries
# PostgreSQL_LIBRARIES - The PostgreSQL libraries.
#
# ----------------------------------------------------------------------------
# If you have installed PostgreSQL in a non-standard location.
# (Please note that in the following comments, it is assumed that <Your Path>
# points to the root directory of the include directory of PostgreSQL.)
# Then you have three options.
# 1) After CMake runs, set PostgreSQL_INCLUDE_DIR to <Your Path>/include and
# PostgreSQL_LIBRARY_DIR to wherever the library pq (or libpq in windows) is
# 2) Use CMAKE_INCLUDE_PATH to set a path to <Your Path>/PostgreSQL<-version>. This will allow find_path()
# to locate PostgreSQL_INCLUDE_DIR by utilizing the PATH_SUFFIXES option. e.g. In your CMakeLists.txt file
# set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "<Your Path>/include")
2018-10-10 13:43:34 +02:00
# 3) Set an environment variable called ${PostgreSQL_ROOT} / ${PostgreSQL_ROOT_DIR} that points to the root of where you have
2018-06-03 18:17:50 +02:00
# installed PostgreSQL, e.g. <Your Path>.
#
# ----------------------------------------------------------------------------
2012-06-26 14:37:02 +02:00
2018-06-03 18:17:50 +02:00
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" )
set ( PostgreSQL_INCLUDE_DIR_MESSAGE "Set the PostgreSQL_INCLUDE_DIR cmake cache entry to the ${PostgreSQL_INCLUDE_PATH_DESCRIPTION}" )
set ( PostgreSQL_LIBRARY_PATH_DESCRIPTION "top-level directory containing the PostgreSQL libraries." )
set ( PostgreSQL_LIBRARY_DIR_MESSAGE "Set the PostgreSQL_LIBRARY_DIR cmake cache entry to the ${PostgreSQL_LIBRARY_PATH_DESCRIPTION}" )
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" )
2012-06-26 14:37:02 +02:00
2018-06-03 18:17:50 +02:00
set ( PostgreSQL_KNOWN_VERSIONS ${ PostgreSQL_ADDITIONAL_VERSIONS }
2018-10-18 07:07:46 +02:00
" 1 0 " " 9 . 6 " " 9 . 5 " " 9 . 4 " " 9 . 3 " " 9 . 2 " " 9 . 1 " " 9 . 0 " " 8 . 4 " " 8 . 3 " " 8 . 2 " " 8 . 1 " " 8 . 0 " )
2018-06-03 18:17:50 +02:00
# Define additional search paths for root directories.
2020-02-14 11:07:32 +01:00
set ( PostgreSQL_ROOT_DIRECTORIES
E N V P o s t g r e S Q L _ R O O T
$ { P o s t g r e S Q L _ R O O T }
$ { P o s t g r e S Q L _ R O O T _ D I R }
2012-06-26 14:37:02 +02:00
)
2018-06-03 18:17:50 +02:00
foreach ( suffix ${ PostgreSQL_KNOWN_VERSIONS } )
2020-02-14 11:07:32 +01:00
if ( WIN32 )
list ( APPEND PostgreSQL_LIBRARY_ADDITIONAL_SEARCH_SUFFIXES
" P o s t g r e S Q L / $ { s u f f i x } / l i b " )
list ( APPEND PostgreSQL_INCLUDE_ADDITIONAL_SEARCH_SUFFIXES
" P o s t g r e S Q L / $ { s u f f i x } / i n c l u d e " )
list ( APPEND PostgreSQL_TYPE_ADDITIONAL_SEARCH_SUFFIXES
" P o s t g r e S Q L / $ { s u f f i x } / i n c l u d e / s e r v e r " )
endif ( )
if ( UNIX )
list ( APPEND PostgreSQL_LIBRARY_ADDITIONAL_SEARCH_SUFFIXES
" p g s q l - $ { s u f f i x } / l i b " )
list ( APPEND PostgreSQL_INCLUDE_ADDITIONAL_SEARCH_SUFFIXES
" p g s q l - $ { s u f f i x } / i n c l u d e " )
list ( APPEND PostgreSQL_TYPE_ADDITIONAL_SEARCH_SUFFIXES
" p o s t g r e s q l / $ { s u f f i x } / s e r v e r "
" p g s q l - $ { s u f f i x } / i n c l u d e / s e r v e r " )
endif ( )
2018-06-03 18:17:50 +02:00
endforeach ( )
if ( UNIX )
2020-02-14 11:07:32 +01:00
list ( APPEND PostgreSQL_ROOT_DIRECTORIES
2018-06-03 18:17:50 +02:00
" / u s r " )
list ( APPEND PostgreSQL_INCLUDE_ADDITIONAL_SEARCH_SUFFIXES
" i n c l u d e / p o s t g r e s q l " )
endif ( )
#
# Look for an installation.
#
find_path ( PostgreSQL_INCLUDE_DIR
2020-02-14 11:07:32 +01:00
N A M E S l i b p q - f e . h
H I N T S
$ { P o s t g r e S Q L _ R O O T _ I N C L U D E _ D I R S }
P A T H S
# Look in other places.
$ { P o s t g r e S Q L _ R O O T _ D I R E C T O R I E S }
P A T H _ S U F F I X E S
p g s q l
p o s t g r e s q l
i n c l u d e
$ { P o s t g r e S Q L _ I N C L U D E _ A D D I T I O N A L _ S E A R C H _ S U F F I X E S }
# Help the user find it if we cannot.
D O C " T h e $ { P o s t g r e S Q L _ I N C L U D E _ D I R _ M E S S A G E } "
2012-06-26 14:37:02 +02:00
)
2018-06-03 18:17:50 +02:00
# TODO(Bjoe) It is not needed to build an PostgreSQL client. Maybe create an issue on cmake project
# find_path(PostgreSQL_TYPE_INCLUDE_DIR
# NAMES catalog/pg_type.h
# PATHS
# # Look in other places.
# ${PostgreSQL_ROOT_DIRECTORIES}
# PATH_SUFFIXES
# postgresql
# pgsql/server
# postgresql/server
# include/server
# ${PostgreSQL_TYPE_ADDITIONAL_SEARCH_SUFFIXES}
# # Help the user find it if we cannot.
# DOC "The ${PostgreSQL_INCLUDE_DIR_MESSAGE}"
# )
2012-06-26 14:37:02 +02:00
2018-06-03 18:17:50 +02:00
# The PostgreSQL library.
2020-02-14 11:07:32 +01:00
set ( PostgreSQL_LIBRARY_TO_FIND pq )
2018-06-03 18:17:50 +02:00
# Setting some more prefixes for the library
2020-02-14 11:07:32 +01:00
set ( PostgreSQL_LIB_PREFIX "" )
if ( WIN32 )
set ( PostgreSQL_LIB_PREFIX ${ PostgreSQL_LIB_PREFIX } "lib" )
set ( PostgreSQL_LIBRARY_TO_FIND ${ PostgreSQL_LIB_PREFIX } ${ PostgreSQL_LIBRARY_TO_FIND } )
2018-06-03 18:17:50 +02:00
endif ( )
2012-06-26 14:37:02 +02:00
2018-06-03 18:17:50 +02:00
find_library ( PostgreSQL_LIBRARY
2020-02-14 11:07:32 +01:00
N A M E S $ { P o s t g r e S Q L _ L I B R A R Y _ T O _ F I N D }
H I N T S
$ { P o s t g r e S Q L _ R O O T _ L I B R A R Y _ D I R S }
P A T H S
$ { P o s t g r e S Q L _ R O O T _ D I R E C T O R I E S }
P A T H _ S U F F I X E S
l i b
$ { P o s t g r e S Q L _ L I B R A R Y _ A D D I T I O N A L _ S E A R C H _ S U F F I X E S }
# Help the user find it if we cannot.
D O C " T h e $ { P o s t g r e S Q L _ L I B R A R Y _ D I R _ M E S S A G E } "
2012-06-26 14:37:02 +02:00
)
2018-06-03 18:17:50 +02:00
get_filename_component ( PostgreSQL_LIBRARY_DIR ${ PostgreSQL_LIBRARY } PATH )
2020-02-14 11:07:32 +01:00
if ( PostgreSQL_INCLUDE_DIR )
# Some platforms include multiple pg_config.hs for multi-lib configurations
# This is a temporary workaround. A better solution would be to compile
# a dummy c file and extract the value of the symbol.
file ( GLOB _PG_CONFIG_HEADERS "${PostgreSQL_INCLUDE_DIR}/pg_config*.h" )
foreach ( _PG_CONFIG_HEADER ${ _PG_CONFIG_HEADERS } )
if ( EXISTS "${_PG_CONFIG_HEADER}" )
file ( STRINGS "${_PG_CONFIG_HEADER}" pgsql_version_str
R E G E X " ^ #define[\t ]+PG_VERSION[\t ]+\".*\"")
if ( pgsql_version_str )
string ( REGEX REPLACE "^#define[\t ]+PG_VERSION[\t ]+\" ( [^\ "]*)\" .* "
" \ \ 1 " P o s t g r e S Q L _ V E R S I O N " $ { p g s q l _ v e r s i o n _ s t r } " )
break ( )
endif ( )
endif ( )
endforeach ( )
unset ( pgsql_version_str )
2018-06-03 18:17:50 +02:00
endif ( )
# Did we find anything?
include ( FindPackageHandleStandardArgs )
2020-02-14 11:07:32 +01:00
find_package_handle_standard_args (
P o s t g r e S Q L
R E Q U I R E D _ V A R S P o s t g r e S Q L _ L I B R A R Y P o s t g r e S Q L _ I N C L U D E _ D I R #PostgreSQL_TYPE_INCLUDE_DIR
V E R S I O N _ V A R P o s t g r e S Q L _ V E R S I O N
)
2018-06-03 18:17:50 +02:00
set ( PostgreSQL_FOUND ${ POSTGRESQL_FOUND } )
# Now try to get the include and library path.
if ( PostgreSQL_FOUND )
2020-02-14 11:07:32 +01:00
set ( PostgreSQL_INCLUDE_DIRS ${ PostgreSQL_INCLUDE_DIR } ) #${PostgreSQL_TYPE_INCLUDE_DIR} )
set ( PostgreSQL_LIBRARY_DIRS ${ PostgreSQL_LIBRARY_DIR } )
set ( PostgreSQL_LIBRARIES ${ PostgreSQL_LIBRARY } )
2018-06-03 18:17:50 +02:00
endif ( )
2018-10-10 13:43:34 +02:00
if ( PostgreSQL_FOUND AND NOT TARGET PostgreSQL::client )
2020-02-14 11:07:32 +01:00
add_library ( PostgreSQL::client UNKNOWN IMPORTED )
set_target_properties ( PostgreSQL::client PROPERTIES
I M P O R T E D _ L O C A T I O N " $ { P o s t g r e S Q L _ L I B R A R Y } "
I N T E R F A C E _ I N C L U D E _ D I R E C T O R I E S " $ { P o s t g r e S Q L _ I N C L U D E _ D I R } "
)
2018-10-10 13:43:34 +02:00
endif ( )
2018-06-03 18:17:50 +02:00
mark_as_advanced ( PostgreSQL_INCLUDE_DIR PostgreSQL_LIBRARY ) #PostgreSQL_TYPE_INCLUDE_DIR