diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2019-11-04 21:37:06 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-11-07 14:24:12 (GMT) |
commit | aeae4182cb90cbf65b1c27cc877f62d2c7690aaf (patch) | |
tree | 63d19ce4a6412b7d212536ccae8c2623f5fe599b | |
parent | 6d01a8e004c5faf2d0b2c3b7c0645ce3726181b6 (diff) | |
download | CMake-aeae4182cb90cbf65b1c27cc877f62d2c7690aaf.zip CMake-aeae4182cb90cbf65b1c27cc877f62d2c7690aaf.tar.gz CMake-aeae4182cb90cbf65b1c27cc877f62d2c7690aaf.tar.bz2 |
FindPostgreSQL: support version encoding used in pre-10 releases
With the 10.x release, PostgreSQL upstream started encoding the version
as `MMmmmm` where `M` is major and `m` is minor. Prior to that, `MMmmPP`
was used where `P` was the patch number. Detect this difference and
decode it based on the used encoding.
Fixes: #19912
-rw-r--r-- | Modules/FindPostgreSQL.cmake | 21 | ||||
-rw-r--r-- | Tests/FindPostgreSQL/Test/main.c | 15 |
2 files changed, 28 insertions, 8 deletions
diff --git a/Modules/FindPostgreSQL.cmake b/Modules/FindPostgreSQL.cmake index 4b5e60e..1631c9c 100644 --- a/Modules/FindPostgreSQL.cmake +++ b/Modules/FindPostgreSQL.cmake @@ -184,11 +184,22 @@ if (PostgreSQL_INCLUDE_DIR) endif() endforeach() 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) + # 9.x and older encoding + if (_PostgreSQL_VERSION_NUM LESS 100000) + 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}") + 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}") + unset(_PostgreSQL_major_version) + unset(_PostgreSQL_minor_version) + endif () else () foreach(_PG_CONFIG_HEADER ${_PG_CONFIG_HEADERS}) if(EXISTS "${_PG_CONFIG_HEADER}") diff --git a/Tests/FindPostgreSQL/Test/main.c b/Tests/FindPostgreSQL/Test/main.c index 2cfeed0..a63377a 100644 --- a/Tests/FindPostgreSQL/Test/main.c +++ b/Tests/FindPostgreSQL/Test/main.c @@ -5,10 +5,19 @@ int main() { int version = PQlibVersion(); - int major = version / 10000; - int minor = version % 10000; char version_string[100]; - snprintf(version_string, sizeof(version_string), "%d.%d", major, minor); + // 9.x and older encoding. + if (version < 100000) { + int major = version / 10000; + int minor = version % 10000 / 100; + int patch = version % 100; + snprintf(version_string, sizeof(version_string), "%d.%d.%d", major, minor, + patch); + } else { + int major = version / 10000; + int minor = version % 10000; + snprintf(version_string, sizeof(version_string), "%d.%d", major, minor); + } printf("Found PostgreSQL version %s, expected version %s\n", version_string, CMAKE_EXPECTED_POSTGRESQL_VERSION); return strcmp(version_string, CMAKE_EXPECTED_POSTGRESQL_VERSION); |