2016-09-27 19:01:08 +00:00
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file Copyright.txt or https://cmake.org/licensing for details.
2018-10-22 14:31:08 +00:00
#[=======================================================================[.rst:
F i n d P o s t g r e S Q L
- - - - - - - - - - - - - -
F i n d t h e P o s t g r e S Q L i n s t a l l a t i o n .
2018-10-31 18:36:27 +00:00
I M P O R T E D T a r g e t s
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
T h i s m o d u l e d e f i n e s : p r o p _ t g t : ` I M P O R T E D ` t a r g e t ` ` P o s t g r e S Q L : : P o s t g r e S Q L ` `
i f P o s t g r e S Q L h a s b e e n f o u n d .
2018-11-01 17:21:45 +00:00
R e s u l t V a r i a b l e s
^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
2018-10-22 14:31:08 +00:00
2018-11-01 17:21:45 +00:00
T h i s m o d u l e w i l l s e t t h e f o l l o w i n g v a r i a b l e s i n y o u r p r o j e c t :
2018-10-22 14:31:08 +00:00
2018-11-01 17:21:45 +00:00
` ` P o s t g r e S Q L _ F O U N D ` `
T r u e i f P o s t g r e S Q L i s f o u n d .
` ` P o s t g r e S Q L _ L I B R A R I E S ` `
t h e P o s t g r e S Q L l i b r a r i e s n e e d e d f o r l i n k i n g
` ` P o s t g r e S Q L _ I N C L U D E _ D I R S ` `
t h e d i r e c t o r i e s o f t h e P o s t g r e S Q L h e a d e r s
` ` P o s t g r e S Q L _ L I B R A R Y _ D I R S ` `
t h e l i n k d i r e c t o r i e s f o r P o s t g r e S Q L l i b r a r i e s
` ` P o s t g r e S Q L _ V E R S I O N _ S T R I N G ` `
t h e v e r s i o n o f P o s t g r e S Q L f o u n d
2018-10-22 14:31:08 +00:00
#]=======================================================================]
2010-07-08 00:24:52 +00:00
2010-07-07 23:49:15 +00: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
2018-01-03 12:09:54 +00:00
# version number of the implementation of PostgreSQL.
2010-07-07 23:49:15 +00:00
# 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:
2018-10-30 09:04:09 +00:00
# "11" "10" "9.6" "9.5" "9.4" "9.3" "9.2" "9.1" "9.0" "8.4" "8.3" "8.2" "8.1" "8.0"
2010-07-07 23:49:15 +00:00
#
# To use this variable just do something like this:
# set(PostgreSQL_ADDITIONAL_VERSIONS "9.2" "8.4.4")
2012-08-13 17:47:32 +00:00
# before calling find_package(PostgreSQL) in your CMakeLists.txt file.
2010-07-07 23:49:15 +00:00
# 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:
# 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.
#
2018-10-31 18:36:27 +00:00
# The ``PostgreSQL::PostgreSQL`` imported target is also created.
#
2010-07-07 23:49:15 +00:00
# ----------------------------------------------------------------------------
# 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
2012-08-13 17:47:32 +00:00
# set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "<Your Path>/include")
2010-07-07 23:49:15 +00:00
# 3) Set an environment variable called ${PostgreSQL_ROOT} that points to the root of where you have
# installed PostgreSQL, e.g. <Your Path>.
#
# ----------------------------------------------------------------------------
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" )
set ( PostgreSQL_KNOWN_VERSIONS ${ PostgreSQL_ADDITIONAL_VERSIONS }
2018-10-30 09:04:09 +00:00
" 1 1 " " 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 " )
2010-07-07 23:49:15 +00:00
# Define additional search paths for root directories.
set ( PostgreSQL_ROOT_DIRECTORIES
2012-03-28 22:00:54 +00:00
E N V P o s t g r e S Q L _ R O O T
2010-07-07 23:49:15 +00:00
$ { P o s t g r e S Q L _ R O O T }
)
2015-05-30 13:17:47 +00:00
foreach ( suffix ${ PostgreSQL_KNOWN_VERSIONS } )
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 )
2016-12-29 10:05:36 +00:00
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 " )
2015-05-30 13:17:47 +00:00
list ( APPEND PostgreSQL_TYPE_ADDITIONAL_SEARCH_SUFFIXES
2016-12-29 10:05:36 +00:00
" 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 " )
2015-05-30 13:17:47 +00:00
endif ( )
endforeach ( )
2010-07-07 23:49:15 +00:00
#
# Look for an installation.
#
find_path ( PostgreSQL_INCLUDE_DIR
N A M E S l i b p q - f e . h
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
2011-07-28 21:14:52 +00:00
p g s q l
p o s t g r e s q l
i n c l u d e
2015-05-30 13:17:47 +00:00
$ { 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 }
2011-07-28 21:14:52 +00:00
# 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 } "
)
find_path ( PostgreSQL_TYPE_INCLUDE_DIR
N A M E S c a t a l o g / p g _ t y p e . h
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
2012-10-15 19:28:13 +00:00
p o s t g r e s q l
2011-07-29 19:13:52 +00:00
p g s q l / s e r v e r
p o s t g r e s q l / s e r v e r
i n c l u d e / s e r v e r
2015-05-30 13:17:47 +00:00
$ { P o s t g r e S Q L _ T Y P 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 }
2010-07-07 23:49:15 +00:00
# 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 } "
)
# The PostgreSQL library.
set ( PostgreSQL_LIBRARY_TO_FIND pq )
# Setting some more prefixes for the library
set ( PostgreSQL_LIB_PREFIX "" )
if ( WIN32 )
set ( PostgreSQL_LIB_PREFIX ${ PostgreSQL_LIB_PREFIX } "lib" )
2015-05-30 13:17:47 +00:00
set ( PostgreSQL_LIBRARY_TO_FIND ${ PostgreSQL_LIB_PREFIX } ${ PostgreSQL_LIBRARY_TO_FIND } )
2010-07-07 23:49:15 +00:00
endif ( )
2019-05-09 17:17:28 +00:00
function ( __postgresql_find_library _name )
find_library ( ${ _name }
N A M E S $ { A R G N }
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 } "
)
endfunction ( )
# For compatibility with versions prior to this multi-config search, honor
# any PostgreSQL_LIBRARY that is already specified and skip the search.
if ( PostgreSQL_LIBRARY )
set ( PostgreSQL_LIBRARIES "${PostgreSQL_LIBRARY}" )
else ( )
__postgresql_find_library ( PostgreSQL_LIBRARY_RELEASE ${ PostgreSQL_LIBRARY_TO_FIND } )
__postgresql_find_library ( PostgreSQL_LIBRARY_DEBUG ${ PostgreSQL_LIBRARY_TO_FIND } d )
include ( ${ CMAKE_CURRENT_LIST_DIR } /SelectLibraryConfigurations.cmake )
select_library_configurations ( PostgreSQL )
mark_as_advanced ( PostgreSQL_LIBRARY_RELEASE PostgreSQL_LIBRARY_DEBUG )
endif ( )
2010-07-07 23:49:15 +00:00
get_filename_component ( PostgreSQL_LIBRARY_DIR ${ PostgreSQL_LIBRARY } PATH )
2014-08-31 23:52:04 +00: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
2018-11-01 18:45:25 +00:00
R E G E X " ^ #define[\t ]+PG_VERSION_NUM[\t ]+.*")
2014-08-31 23:52:04 +00:00
if ( pgsql_version_str )
2018-11-01 18:45:25 +00:00
string ( REGEX REPLACE "^#define[\t ]+PG_VERSION_NUM[\t ]+([0-9]*).*"
" \ \ 1 " _ P o s t g r e S Q L _ V E R S I O N _ N U M " $ { p g s q l _ v e r s i o n _ s t r } " )
2014-08-31 23:52:04 +00:00
break ( )
endif ( )
endif ( )
endforeach ( )
2018-11-01 18:45:25 +00:00
if ( _PostgreSQL_VERSION_NUM )
math ( EXPR _PostgreSQL_major_version "${_PostgreSQL_VERSION_NUM} / 10000" )
math ( EXPR _PostgreSQL_minor_version "${_PostgreSQL_VERSION_NUM} % 10000" )
set ( PostgreSQL_VERSION_STRING "${_PostgreSQL_major_version}.${_PostgreSQL_minor_version}" )
unset ( _PostgreSQL_major_version )
unset ( _PostgreSQL_minor_version )
else ( )
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 _ S T R I N G " $ { p g s q l _ v e r s i o n _ s t r } " )
break ( )
endif ( )
endif ( )
endforeach ( )
endif ( )
unset ( _PostgreSQL_VERSION_NUM )
2012-01-26 18:35:47 +00:00
unset ( pgsql_version_str )
endif ( )
2010-07-07 23:49:15 +00:00
# Did we find anything?
2012-09-08 17:03:26 +00:00
include ( ${ CMAKE_CURRENT_LIST_DIR } /FindPackageHandleStandardArgs.cmake )
2012-01-26 18:35:47 +00:00
find_package_handle_standard_args ( PostgreSQL
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 P o s t g r e S Q L _ T Y P E _ I N C L U D E _ D I R
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 _ S T R I N G )
2015-05-30 13:17:47 +00:00
set ( PostgreSQL_FOUND ${ POSTGRESQL_FOUND } )
2010-07-07 23:49:15 +00:00
2019-05-09 17:17:28 +00:00
function ( __postgresql_import_library _target _var _config )
if ( _config )
set ( _config_suffix "_${_config}" )
else ( )
set ( _config_suffix "" )
endif ( )
set ( _lib "${${_var}${_config_suffix}}" )
if ( EXISTS "${_lib}" )
if ( _config )
set_property ( TARGET ${ _target } APPEND PROPERTY
I M P O R T E D _ C O N F I G U R A T I O N S $ { _ c o n f i g } )
endif ( )
set_target_properties ( ${ _target } PROPERTIES
I M P O R T E D _ L O C A T I O N $ { _ c o n f i g _ s u f f i x } " $ { _ l i b } " )
endif ( )
endfunction ( )
2010-07-07 23:49:15 +00:00
# Now try to get the include and library path.
if ( PostgreSQL_FOUND )
2018-10-31 18:36:27 +00:00
if ( NOT TARGET PostgreSQL::PostgreSQL )
add_library ( PostgreSQL::PostgreSQL UNKNOWN IMPORTED )
set_target_properties ( PostgreSQL::PostgreSQL PROPERTIES
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 } ; $ { P o s t g r e S Q L _ T Y P E _ I N C L U D E _ D I R } " )
2019-05-09 17:17:28 +00:00
__postgresql_import_library ( PostgreSQL::PostgreSQL PostgreSQL_LIBRARY "" )
__postgresql_import_library ( PostgreSQL::PostgreSQL PostgreSQL_LIBRARY "RELEASE" )
__postgresql_import_library ( PostgreSQL::PostgreSQL PostgreSQL_LIBRARY "DEBUG" )
2018-10-31 18:36:27 +00:00
endif ( )
2011-07-28 21:19:52 +00:00
set ( PostgreSQL_INCLUDE_DIRS ${ PostgreSQL_INCLUDE_DIR } ${ PostgreSQL_TYPE_INCLUDE_DIR } )
set ( PostgreSQL_LIBRARY_DIRS ${ PostgreSQL_LIBRARY_DIR } )
2012-08-13 17:50:14 +00:00
endif ( )
2011-08-01 20:27:50 +00:00
2019-05-09 17:17:28 +00:00
mark_as_advanced ( PostgreSQL_INCLUDE_DIR PostgreSQL_TYPE_INCLUDE_DIR )