diff options
author | Ben Boeckel <ben.boeckel@kitware.com> | 2018-11-01 18:45:25 (GMT) |
---|---|---|
committer | Ben Boeckel <ben.boeckel@kitware.com> | 2018-11-05 16:13:33 (GMT) |
commit | 575e2cc35da7cef40c521bccf0512483012bc136 (patch) | |
tree | ee5d51f45082c24ececa891d98d17167aa6ea3d8 /Modules/FindPostgreSQL.cmake | |
parent | 7413f29fe63296cf34176c5fc68c2c5354b43202 (diff) | |
download | CMake-575e2cc35da7cef40c521bccf0512483012bc136.zip CMake-575e2cc35da7cef40c521bccf0512483012bc136.tar.gz CMake-575e2cc35da7cef40c521bccf0512483012bc136.tar.bz2 |
FindPostgreSQL: extract the actual version number
The `PG_VERSION` variable can be mangled by distributions to indicate
things like the name of the distro and package build numbers.
However, `PG_VERSION_NUM` is new in 8.2 (2006), so keep the old
extraction code around for old versions.
Diffstat (limited to 'Modules/FindPostgreSQL.cmake')
-rw-r--r-- | Modules/FindPostgreSQL.cmake | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/Modules/FindPostgreSQL.cmake b/Modules/FindPostgreSQL.cmake index 6832bbe..4b5e60e 100644 --- a/Modules/FindPostgreSQL.cmake +++ b/Modules/FindPostgreSQL.cmake @@ -175,14 +175,34 @@ if (PostgreSQL_INCLUDE_DIR) foreach(_PG_CONFIG_HEADER ${_PG_CONFIG_HEADERS}) if(EXISTS "${_PG_CONFIG_HEADER}") file(STRINGS "${_PG_CONFIG_HEADER}" pgsql_version_str - REGEX "^#define[\t ]+PG_VERSION[\t ]+\".*\"") + REGEX "^#define[\t ]+PG_VERSION_NUM[\t ]+.*") if(pgsql_version_str) - string(REGEX REPLACE "^#define[\t ]+PG_VERSION[\t ]+\"([^\"]*)\".*" - "\\1" PostgreSQL_VERSION_STRING "${pgsql_version_str}") + string(REGEX REPLACE "^#define[\t ]+PG_VERSION_NUM[\t ]+([0-9]*).*" + "\\1" _PostgreSQL_VERSION_NUM "${pgsql_version_str}") break() endif() 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) + else () + foreach(_PG_CONFIG_HEADER ${_PG_CONFIG_HEADERS}) + if(EXISTS "${_PG_CONFIG_HEADER}") + file(STRINGS "${_PG_CONFIG_HEADER}" pgsql_version_str + 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}") + break() + endif() + endif() + endforeach() + endif () + unset(_PostgreSQL_VERSION_NUM) unset(pgsql_version_str) endif() |