Commit 743ec448 authored by Konstantin Podsvirov's avatar Konstantin Podsvirov

Parsing version from configure.ac for CMake project

parent 82983433
...@@ -11,24 +11,31 @@ if (MSVC) ...@@ -11,24 +11,31 @@ if (MSVC)
option(ZLIB "Build with zlib support" OFF) option(ZLIB "Build with zlib support" OFF)
endif (MSVC) endif (MSVC)
# Path to common header # Path to main configure script
set(protobuf_COMMON_HEADER "../src/google/protobuf/stubs/common.h") set(protobuf_CONFIGURE_SCRIPT "../configure.ac")
# Parse version from common header # Parse version from configure script
file(STRINGS "${protobuf_COMMON_HEADER}" protobuf_VERSION_LINE file(STRINGS "${protobuf_CONFIGURE_SCRIPT}" protobuf_VERSION_LINE
LIMIT_COUNT 1 LIMIT_COUNT 1
REGEX "^#define GOOGLE_PROTOBUF_VERSION [0-9]+$") REGEX "^AC_INIT")
string(REGEX REPLACE "^.*PROTOBUF_VERSION ([0-9]+).*$" "\\1" # Replace special characters
protobuf_VERSION_NUMBER "${protobuf_VERSION_LINE}") string(REPLACE "(" "_" protobuf_VERSION_LINE ${protobuf_VERSION_LINE})
math(EXPR protobuf_VERSION_MICRO string(REPLACE ")" "_" protobuf_VERSION_LINE ${protobuf_VERSION_LINE})
"${protobuf_VERSION_NUMBER} % 1000") string(REPLACE "[" "_" protobuf_VERSION_LINE ${protobuf_VERSION_LINE})
math(EXPR protobuf_VERSION_MINOR string(REPLACE "]" "_" protobuf_VERSION_LINE ${protobuf_VERSION_LINE})
"(${protobuf_VERSION_NUMBER} - ${protobuf_VERSION_MICRO}) % 1000000 / 1000") # Parse version string
math(EXPR protobuf_VERSION_MAJOR string(REGEX REPLACE "^AC_INIT__Protocol Buffers_,_([^_]+).*$" "\\1"
"(${protobuf_VERSION_NUMBER} - ${protobuf_VERSION_MINOR} * 1000 - ${protobuf_VERSION_MICRO}) % 1000000000 / 1000000") protobuf_VERSION_STRING "${protobuf_VERSION_LINE}")
set(protobuf_VERSION_PATCH ${protobuf_VERSION_MICRO}) # Parse version tweaks
string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\\.([0-9]+).*$" "\\1"
protobuf_VERSION_MAJOR "${protobuf_VERSION_STRING}")
string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\\.([0-9]+).*$" "\\2"
protobuf_VERSION_MINOR "${protobuf_VERSION_STRING}")
string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\\.([0-9]+).*$" "\\3"
protobuf_VERSION_PATCH "${protobuf_VERSION_STRING}")
# Package version
set(protobuf_VERSION set(protobuf_VERSION
"${protobuf_VERSION_MAJOR}.${protobuf_VERSION_MINOR}.${protobuf_VERSION_MICRO}") "${protobuf_VERSION_MAJOR}.${protobuf_VERSION_MINOR}.${protobuf_VERSION_PATCH}")
add_definitions(-DGOOGLE_PROTOBUF_CMAKE_BUILD) add_definitions(-DGOOGLE_PROTOBUF_CMAKE_BUILD)
......
set(protobuf_VERSION_STRING "@protobuf_VERSION_STRING@")
include("${CMAKE_CURRENT_LIST_DIR}/protobuf-targets.cmake") include("${CMAKE_CURRENT_LIST_DIR}/protobuf-targets.cmake")
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment