From 4d4d10e95dbfdbc11a3d60737c74fe64f5e4d979 Mon Sep 17 00:00:00 2001 From: Peter Kokot Date: Wed, 30 Jul 2025 03:01:16 +0200 Subject: [PATCH] FindPostgreSQL: Add PostgreSQL_VERSION This deprecates the PostgreSQL_VERSION_STRING result variable. Issue: #27088 --- Help/release/dev/find-modules.rst | 4 ++ Modules/FindPostgreSQL.cmake | 39 +++++++++++++++---- Tests/CMakeOnly/AllFindModules/CMakeLists.txt | 2 +- Tests/FindPostgreSQL/Test/CMakeLists.txt | 2 +- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/Help/release/dev/find-modules.rst b/Help/release/dev/find-modules.rst index ff9ca6dadf..70ecbb089e 100644 --- a/Help/release/dev/find-modules.rst +++ b/Help/release/dev/find-modules.rst @@ -3,3 +3,7 @@ Find Modules * The :module:`FindBZip2` module now provides a ``BZip2_VERSION`` result variable. The ``BZIP2_VERSION`` result variable is deprecated. + +* The :module:`FindPostgreSQL` module now provides a ``PostgreSQL_VERSION`` + result variable. The ``PostgreSQL_VERSION_STRING`` result variable is + deprecated. diff --git a/Modules/FindPostgreSQL.cmake b/Modules/FindPostgreSQL.cmake index ede8f0d640..11368d3510 100644 --- a/Modules/FindPostgreSQL.cmake +++ b/Modules/FindPostgreSQL.cmake @@ -6,7 +6,11 @@ FindPostgreSQL -------------- Finds the PostgreSQL installation - the client library (``libpq``) and -optionally the server. +optionally the server: + +.. code-block:: cmake + + find_package(PostgreSQL [] [...]) Imported Targets ^^^^^^^^^^^^^^^^ @@ -28,14 +32,21 @@ This module defines the following variables: ``PostgreSQL_FOUND`` Boolean indicating whether the minimum required version and components of PostgreSQL have been found. + +``PostgreSQL_VERSION`` + .. versionadded:: 4.2 + + The version of PostgreSQL found. + ``PostgreSQL_LIBRARIES`` The PostgreSQL libraries needed for linking. + ``PostgreSQL_INCLUDE_DIRS`` The include directories containing PostgreSQL headers. + ``PostgreSQL_LIBRARY_DIRS`` The directories containing PostgreSQL libraries. -``PostgreSQL_VERSION_STRING`` - The version of PostgreSQL found. + ``PostgreSQL_TYPE_INCLUDE_DIR`` The include directory containing PostgreSQL server headers. @@ -51,6 +62,17 @@ This module supports the following additional components: ``PostgreSQL_TYPE_INCLUDE_DIR`` variable is set regardless of whether this component is specified in the ``find_package()`` call. +Deprecated Variables +^^^^^^^^^^^^^^^^^^^^ + +The following variables are provided for backward compatibility: + +``PostgreSQL_VERSION_STRING`` + .. deprecated:: 4.2 + Superseded by the ``PostgreSQL_VERSION``. + + The version of PostgreSQL found. + Examples ^^^^^^^^ @@ -288,14 +310,16 @@ if (PostgreSQL_INCLUDE_DIR) math(EXPR _PostgreSQL_major_version "${_PostgreSQL_VERSION_NUM} / 10000") math(EXPR _PostgreSQL_minor_version "${_PostgreSQL_VERSION_NUM} % 10000 / 100") math(EXPR _PostgreSQL_patch_version "${_PostgreSQL_VERSION_NUM} % 100") - set(PostgreSQL_VERSION_STRING "${_PostgreSQL_major_version}.${_PostgreSQL_minor_version}.${_PostgreSQL_patch_version}") + set(PostgreSQL_VERSION "${_PostgreSQL_major_version}.${_PostgreSQL_minor_version}.${_PostgreSQL_patch_version}") + set(PostgreSQL_VERSION_STRING "${PostgreSQL_VERSION}") unset(_PostgreSQL_major_version) unset(_PostgreSQL_minor_version) unset(_PostgreSQL_patch_version) else () 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}") + set(PostgreSQL_VERSION "${_PostgreSQL_major_version}.${_PostgreSQL_minor_version}") + set(PostgreSQL_VERSION_STRING "${PostgreSQL_VERSION}") unset(_PostgreSQL_major_version) unset(_PostgreSQL_minor_version) endif () @@ -306,7 +330,8 @@ if (PostgreSQL_INCLUDE_DIR) REGEX "^#define[\t ]+PG_VERSION[\t ]+\".*\"") if(pgsql_version_str) string(REGEX REPLACE "^#define[\t ]+PG_VERSION[\t ]+\"([^\"]*)\".*" - "\\1" PostgreSQL_VERSION_STRING "${pgsql_version_str}") + "\\1" PostgreSQL_VERSION "${pgsql_version_str}") + set(PostgreSQL_VERSION_STRING "${PostgreSQL_VERSION}") break() endif() endif() @@ -328,7 +353,7 @@ include(FindPackageHandleStandardArgs) find_package_handle_standard_args(PostgreSQL REQUIRED_VARS PostgreSQL_LIBRARY PostgreSQL_INCLUDE_DIR HANDLE_COMPONENTS - VERSION_VAR PostgreSQL_VERSION_STRING) + VERSION_VAR PostgreSQL_VERSION) function(__postgresql_import_library _target _var _config) if(_config) diff --git a/Tests/CMakeOnly/AllFindModules/CMakeLists.txt b/Tests/CMakeOnly/AllFindModules/CMakeLists.txt index 1b6e506550..becebbd376 100644 --- a/Tests/CMakeOnly/AllFindModules/CMakeLists.txt +++ b/Tests/CMakeOnly/AllFindModules/CMakeLists.txt @@ -120,7 +120,7 @@ foreach( JPEG LibArchive LIBLZMA OPENSCENEGRAPH - Protobuf + PostgreSQL Protobuf Ruby RUBY SWIG ZLIB diff --git a/Tests/FindPostgreSQL/Test/CMakeLists.txt b/Tests/FindPostgreSQL/Test/CMakeLists.txt index 1bc5c56d45..1e1d2153a0 100644 --- a/Tests/FindPostgreSQL/Test/CMakeLists.txt +++ b/Tests/FindPostgreSQL/Test/CMakeLists.txt @@ -4,7 +4,7 @@ include(CTest) find_package(PostgreSQL REQUIRED COMPONENTS Server) -add_definitions(-DCMAKE_EXPECTED_POSTGRESQL_VERSION="${PostgreSQL_VERSION_STRING}") +add_definitions(-DCMAKE_EXPECTED_POSTGRESQL_VERSION="${PostgreSQL_VERSION}") add_executable(test_tgt main.c) target_link_libraries(test_tgt PostgreSQL::PostgreSQL)