diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2019-11-04 21:37:06 (GMT) |
---|---|---|
committer | Ben Boeckel <ben.boeckel@kitware.com> | 2019-11-04 21:38:52 (GMT) |
commit | e992d62b7e15be28c8d560071bcf847f28d9fbb1 (patch) | |
tree | f6594716e50c74cd501ba1566960e27aa0eb232a /Tests/FindPostgreSQL | |
parent | c1d5d5eb11e0260ffadda0851ac844ab46b6b179 (diff) | |
download | CMake-e992d62b7e15be28c8d560071bcf847f28d9fbb1.zip CMake-e992d62b7e15be28c8d560071bcf847f28d9fbb1.tar.gz CMake-e992d62b7e15be28c8d560071bcf847f28d9fbb1.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
Diffstat (limited to 'Tests/FindPostgreSQL')
-rw-r--r-- | Tests/FindPostgreSQL/Test/main.c | 15 |
1 files changed, 12 insertions, 3 deletions
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); |