Commit db014600 authored by Konstantin Podsvirov's avatar Konstantin Podsvirov

Improved configure.ac parsing

parent 0087da9d
...@@ -5,6 +5,7 @@ cmake_minimum_required(VERSION 2.8) ...@@ -5,6 +5,7 @@ cmake_minimum_required(VERSION 2.8)
project(protobuf C CXX) project(protobuf C CXX)
# Options # Options
option(protobuf_VERBOSE "Enable for verbose output" OFF)
option(BUILD_TESTING "Build tests" ON) option(BUILD_TESTING "Build tests" ON)
option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF) option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF)
if (MSVC) if (MSVC)
...@@ -14,29 +15,40 @@ endif (MSVC) ...@@ -14,29 +15,40 @@ endif (MSVC)
# Path to main configure script # Path to main configure script
set(protobuf_CONFIGURE_SCRIPT "../configure.ac") set(protobuf_CONFIGURE_SCRIPT "../configure.ac")
# Parse version from configure script # Parse configure script
file(STRINGS "${protobuf_CONFIGURE_SCRIPT}" protobuf_VERSION_LINE set(protobuf_AC_INIT_REGEX
LIMIT_COUNT 1 "^AC_INIT\\(\\[([^]]+)\\],\\[([^]]+)\\],\\[([^]]+)\\],\\[([^]]+)\\]\\)$")
REGEX "^AC_INIT") file(STRINGS "${protobuf_CONFIGURE_SCRIPT}" protobuf_AC_INIT_LINE
# Replace special characters LIMIT_COUNT 1 REGEX "^AC_INIT")
string(REPLACE "(" "_" protobuf_VERSION_LINE ${protobuf_VERSION_LINE}) # Description
string(REPLACE ")" "_" protobuf_VERSION_LINE ${protobuf_VERSION_LINE}) string(REGEX REPLACE "${protobuf_AC_INIT_REGEX}" "\\1"
string(REPLACE "[" "_" protobuf_VERSION_LINE ${protobuf_VERSION_LINE}) protobuf_DESCRIPTION "${protobuf_AC_INIT_LINE}")
string(REPLACE "]" "_" protobuf_VERSION_LINE ${protobuf_VERSION_LINE}) # Version
# Parse version string string(REGEX REPLACE "${protobuf_AC_INIT_REGEX}" "\\2"
string(REGEX REPLACE "^AC_INIT__Protocol Buffers_,_([^_]+).*$" "\\1" protobuf_VERSION_STRING "${protobuf_AC_INIT_LINE}")
protobuf_VERSION_STRING "${protobuf_VERSION_LINE}") # Contact
string(REGEX REPLACE "${protobuf_AC_INIT_REGEX}" "\\3"
protobuf_CONTACT "${protobuf_AC_INIT_LINE}")
# Parse version tweaks # Parse version tweaks
string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\\.([0-9]+).*$" "\\1" set(protobuf_VERSION_REGEX "^([0-9]+)\\.([0-9]+)\\.([0-9]+).*$")
string(REGEX REPLACE "${protobuf_VERSION_REGEX}" "\\1"
protobuf_VERSION_MAJOR "${protobuf_VERSION_STRING}") protobuf_VERSION_MAJOR "${protobuf_VERSION_STRING}")
string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\\.([0-9]+).*$" "\\2" string(REGEX REPLACE "${protobuf_VERSION_REGEX}" "\\2"
protobuf_VERSION_MINOR "${protobuf_VERSION_STRING}") protobuf_VERSION_MINOR "${protobuf_VERSION_STRING}")
string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\\.([0-9]+).*$" "\\3" string(REGEX REPLACE "${protobuf_VERSION_REGEX}" "\\3"
protobuf_VERSION_PATCH "${protobuf_VERSION_STRING}") protobuf_VERSION_PATCH "${protobuf_VERSION_STRING}")
# Package version # Package version
set(protobuf_VERSION set(protobuf_VERSION
"${protobuf_VERSION_MAJOR}.${protobuf_VERSION_MINOR}.${protobuf_VERSION_PATCH}") "${protobuf_VERSION_MAJOR}.${protobuf_VERSION_MINOR}.${protobuf_VERSION_PATCH}")
if(protobuf_VERBOSE)
message(STATUS "Configuration script parsing status [")
message(STATUS " Description : ${protobuf_DESCRIPTION}")
message(STATUS " Version : ${protobuf_VERSION} (${protobuf_VERSION_STRING})")
message(STATUS " Contact : ${protobuf_CONTACT}")
message(STATUS "]")
endif()
add_definitions(-DGOOGLE_PROTOBUF_CMAKE_BUILD) add_definitions(-DGOOGLE_PROTOBUF_CMAKE_BUILD)
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
......
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