]> granicus.if.org Git - graphviz/commitdiff
Make CMake get Graphviz version from autogen.sh by parsing it
authorMagnus Jacobsson <magnus.jacobsson@berotec.se>
Thu, 18 Jun 2020 11:08:04 +0000 (13:08 +0200)
committerMagnus Jacobsson <magnus.jacobsson@berotec.se>
Mon, 29 Jun 2020 04:29:23 +0000 (06:29 +0200)
This will make autotools and CMake builds have a single source of
truth for the Graphviz version.

First, the major, minor and patch versions are retrieved. If the patch
version is "$GRAPHVIZ_VERSION_DATE", the patch version is set to the
committer date of the latest commit. This effectively repeals part of
the intention of 266ff5ee80b2d91231907e90ec650154f5225aa5: "Don't
encode build date stamp in it to be able to create reproducable
builds".

.gitlab-ci.yml
CMakeLists.txt

index 755209045335618181800c66d2b01fa2c212b6c3..4e7beed1b059465d7ecb11aa2b7fea75055aeae4 100644 (file)
@@ -58,6 +58,7 @@ portable-source:
         # Install and set PATH
         - choco install --no-progress -y activeperl
         - choco install --no-progress -y python3
+        - choco install --no-progress -y grep
         - $Env:Path += ";C:\Python38"
         - $Env:Path += ";$env:CI_PROJECT_DIR\windows\dependencies\graphviz-build-utilities"
         - $Env:Path += ";C:\Program Files\CMake\bin"
index 0ae3072d284557fbc832a7ea9c00226ef1757a4f..6fd6573b6d98ba1a2f7ecf2366856080d8594d70 100644 (file)
@@ -97,13 +97,63 @@ if (WIN32)
 endif()
 
 # ============================ Set Graphviz version ============================
-set(GRAPHVIZ_VERSION_MAJOR 2)
-set(GRAPHVIZ_VERSION_MINOR 45)
-set(GRAPHVIZ_VERSION_PATCH 0)
-set(GRAPHVIZ_VERSION_STRING "${GRAPHVIZ_VERSION_MAJOR}.${GRAPHVIZ_VERSION_MINOR}.${GRAPHVIZ_VERSION_PATCH}")
 configure_file(graphviz_version.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/graphviz_version.h @ONLY)
 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/graphviz_version.h DESTINATION ${HEADER_INSTALL_DIR})
 
+execute_process(
+    COMMAND           grep "^m4_define.*graphviz_version_major" autogen.sh
+    WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
+    RESULT_VARIABLE   major_version_result
+    OUTPUT_VARIABLE   AUTOGEN_MAJOR_VERSION_LINE
+    ERROR_VARIABLE    major_version_error
+    OUTPUT_STRIP_TRAILING_WHITESPACE
+    ERROR_STRIP_TRAILING_WHITESPACE
+)
+if (major_version_result EQUAL 0)
+    string(REGEX REPLACE ".*\\[([0-9]*)\\].*"
+       "\\1" GRAPHVIZ_VERSION_MAJOR
+       ${AUTOGEN_MAJOR_VERSION_LINE})
+else()
+    message(FATAL_ERROR "Failed to set major version: ${major_version_error}")
+    set(GRAPHVIZ_VERSION_MAJOR {$major_version_result})
+endif()
+
+execute_process(
+    COMMAND           grep "^m4_define.*graphviz_version_minor" autogen.sh
+    WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
+    RESULT_VARIABLE   minor_version_result
+    OUTPUT_VARIABLE   AUTOGEN_MINOR_VERSION_LINE
+    ERROR_VARIABLE    minor_version_error
+    OUTPUT_STRIP_TRAILING_WHITESPACE
+    ERROR_STRIP_TRAILING_WHITESPACE
+)
+if (minor_version_result EQUAL 0)
+    string(REGEX REPLACE ".*\\[([0-9]*)\\].*"
+       "\\1" GRAPHVIZ_VERSION_MINOR
+       ${AUTOGEN_MINOR_VERSION_LINE})
+else()
+    message(FATAL_ERROR "Failed to set minor version: ${minor_version_error}")
+    set(GRAPHVIZ_VERSION_MINOR {$minor_version_result})
+endif()
+
+execute_process(
+    COMMAND           grep "^m4_define.*graphviz_version_micro" autogen.sh
+    WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
+    RESULT_VARIABLE   patch_version_result
+    OUTPUT_VARIABLE   AUTOGEN_PATCH_VERSION_LINE
+    ERROR_VARIABLE    patch_version_error
+    OUTPUT_STRIP_TRAILING_WHITESPACE
+    ERROR_STRIP_TRAILING_WHITESPACE
+)
+if (patch_version_result EQUAL 0)
+    string(REGEX REPLACE ".*,\\[(.*)\\].*"
+       "\\1" GRAPHVIZ_VERSION_PATCH
+       ${AUTOGEN_PATCH_VERSION_LINE})
+else()
+    message(FATAL_ERROR "Failed to set patch version: ${patch_version_error}")
+    set(GRAPHVIZ_VERSION_PATCH {$patch_version_result})
+endif()
+
 # Set GRAPHVIZ_VERSION_BUILD to time of last commit, or to 0 if that fails.
 execute_process(
     COMMAND           "${GIT_EXECUTABLE}" log -n 1 --format=%cd --date=format:%Y%m%d.%H%M
@@ -119,6 +169,11 @@ if(NOT git_result EQUAL 0)
     set(GRAPHVIZ_VERSION_BUILD 0)
 endif()
 
+if (GRAPHVIZ_VERSION_PATCH STREQUAL "\$GRAPHVIZ_VERSION_DATE")
+    set(GRAPHVIZ_VERSION_PATCH ${GRAPHVIZ_VERSION_BUILD})
+endif()
+
+set(GRAPHVIZ_VERSION_STRING "${GRAPHVIZ_VERSION_MAJOR}.${GRAPHVIZ_VERSION_MINOR}.${GRAPHVIZ_VERSION_PATCH}")
 set(GRAPHVIZ_VERSION_FULL "${GRAPHVIZ_VERSION_MAJOR}.${GRAPHVIZ_VERSION_MINOR}.${GRAPHVIZ_VERSION_BUILD}")
 file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/builddate.h "#define BUILDDATE \"${GRAPHVIZ_VERSION_BUILD}\"")