From 67d70862aa2b2c2e925a2b1262c9934ea0f9a873 Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Wed, 23 Jul 2014 12:38:22 +0200 Subject: [PATCH] CMake: robust version extraction for P4Est Make the version extraction in P4Est more robust: We should not rely on the version string to define SUBMINOR and PATCH - this doesn't have to be the case. So, always set P4EST_VERSION_SUBMINOR and P4EST_VERSION_PATCH to "0" in FindP4EST.cmake if no valid number could be extracted. --- cmake/modules/FindP4EST.cmake | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/cmake/modules/FindP4EST.cmake b/cmake/modules/FindP4EST.cmake index f2bf417e16..44846c7930 100644 --- a/cmake/modules/FindP4EST.cmake +++ b/cmake/modules/FindP4EST.cmake @@ -134,15 +134,20 @@ IF(EXISTS ${P4EST_INCLUDE_DIR}/p4est_config.h) STRING(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" P4EST_VERSION_SUBMINOR "${P4EST_VERSION}") - - # Now for the patch number such as in 0.3.4.1. If there - # is no patch number, then REGEX REPLACE will set - # P4EST_VERSION_PATCH to an empty string. If that - # is the case, then set the patch number to zero STRING(REGEX REPLACE - "^[0-9]+\\.[0-9]+\\.[0-9]+\\.?(([0-9]+)?).*$" "\\1" + "^[0-9]+\\.[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" P4EST_VERSION_PATCH "${P4EST_VERSION}") - IF("${P4EST_VERSION_PATCH}" STREQUAL "") + + # + # We cannot rely on the fact that SUBMINOR or PATCH are defined. + # Nevertheless, we need a full version number for our preprocessor macros + # to work. Therefore, set those numbers to 0 if necessary. + # + IF("${P4EST_VERSION_SUBMINOR}" MATCHES "^(|${P4EST_VERSION})$") + SET(P4EST_VERSION_SUBMINOR "0") + ENDIF() + + IF("${P4EST_VERSION_PATCH}" MATCHES "^(|${P4EST_VERSION})$") SET(P4EST_VERSION_PATCH "0") ENDIF() ENDIF() -- 2.39.5