Skip to content

Commit

Permalink
The current logic to get the version from the version string depends
Browse files Browse the repository at this point in the history
on the position (11) which may not work with other postgres variants
because of the different strings they may carry like EnterpriseDB for
an example.

So instead of of using string substring to parse the version, use
string regex match. Also, move up the code to replace the strings
alpha/beta/rc a bit to support the patch

Tested on Linux
  • Loading branch information
sandeep-edb authored and cvvergara committed Oct 6, 2022
1 parent fe7878c commit 2000b3f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,16 @@ if(NOT POSTGRESQL_FOUND OR NOT POSTGRESQL_VERSION_STRING)
message(FATAL_ERROR "PostgreSQL not found - Please check your PostgreSQL installation.")
endif()

# for XbetaY XalphaY XrcY -> X.Y
string(REGEX REPLACE "([0-9]+)[beta|alpha|rc|devel].*" "\\1.0" POSTGRESQL_VERSION_STRING ${POSTGRESQL_VERSION_STRING})
message(STATUS "POSTGRESQL_VERSION_STRING=${POSTGRESQL_VERSION_STRING}")
string(SUBSTRING "${POSTGRESQL_VERSION_STRING}" 11 -1 POSTGRESQL_VERSION)

# for XbetaY XalphaY XrcY -> X.Y
string(REGEX REPLACE "^([0-9]+)[beta|alpha|rc|devel].*" "\\1.0" POSTGRESQL_VERSION ${POSTGRESQL_VERSION})
STRING(REGEX MATCH "([0-9]+)\.([0-9]+)" POSTGRESQL_VERSION "${POSTGRESQL_VERSION_STRING}")
message(STATUS "POSTGRESQL_VERSION=${POSTGRESQL_VERSION}")

#for X.Y.Z -> XY Y<10
string(REGEX REPLACE "^([0-9]+)\\.([0-9]+).*" "\\1\\2" PGSQL_VERSION ${POSTGRESQL_VERSION})

#message(STATUS "PGSQL_VERSION=${PGSQL_VERSION}")

if("${POSTGRESQL_VERSION}" VERSION_LESS "${POSTGRESQL_MINIMUM_VERSION}")
message(FATAL_ERROR " PostgreSQL ${POSTGRESQL_MINIMUM_VERSION} or greater is required.")
Expand Down

0 comments on commit 2000b3f

Please sign in to comment.