From 82983433cf6fdc9857a5ca57f281ad0b5f41817c Mon Sep 17 00:00:00 2001 From: Konstantin Podsvirov Date: Fri, 31 Jul 2015 23:36:00 +0300 Subject: Install protobuf from cmake project Additional export as "protobuf" package for importing from other cmake projects --- cmake/CMakeLists.txt | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'cmake/CMakeLists.txt') diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index d36292df..dbcf3490 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -1,13 +1,35 @@ +# Minimum CMake required cmake_minimum_required(VERSION 2.8) +# Project project(protobuf C CXX) +# Options option(BUILD_TESTING "Build tests" ON) option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF) if (MSVC) option(ZLIB "Build with zlib support" OFF) endif (MSVC) +# Path to common header +set(protobuf_COMMON_HEADER "../src/google/protobuf/stubs/common.h") + +# Parse version from common header +file(STRINGS "${protobuf_COMMON_HEADER}" protobuf_VERSION_LINE + LIMIT_COUNT 1 + REGEX "^#define GOOGLE_PROTOBUF_VERSION [0-9]+$") +string(REGEX REPLACE "^.*PROTOBUF_VERSION ([0-9]+).*$" "\\1" + protobuf_VERSION_NUMBER "${protobuf_VERSION_LINE}") +math(EXPR protobuf_VERSION_MICRO + "${protobuf_VERSION_NUMBER} % 1000") +math(EXPR protobuf_VERSION_MINOR + "(${protobuf_VERSION_NUMBER} - ${protobuf_VERSION_MICRO}) % 1000000 / 1000") +math(EXPR protobuf_VERSION_MAJOR + "(${protobuf_VERSION_NUMBER} - ${protobuf_VERSION_MINOR} * 1000 - ${protobuf_VERSION_MICRO}) % 1000000000 / 1000000") +set(protobuf_VERSION_PATCH ${protobuf_VERSION_MICRO}) +set(protobuf_VERSION + "${protobuf_VERSION_MAJOR}.${protobuf_VERSION_MINOR}.${protobuf_VERSION_MICRO}") + add_definitions(-DGOOGLE_PROTOBUF_CMAKE_BUILD) find_package(Threads REQUIRED) @@ -73,6 +95,9 @@ include(libprotobuf-lite.cmake) include(libprotobuf.cmake) include(libprotoc.cmake) include(protoc.cmake) + if (BUILD_TESTING) include(tests.cmake) endif (BUILD_TESTING) + +include(install.cmake) -- cgit v1.2.3 From 743ec448c5358a95d10e655ab256d7911e2145d5 Mon Sep 17 00:00:00 2001 From: Konstantin Podsvirov Date: Sat, 1 Aug 2015 02:01:42 +0300 Subject: Parsing version from configure.ac for CMake project --- cmake/CMakeLists.txt | 37 ++++++++++++++++++++++--------------- cmake/protobuf-config.cmake.in | 2 ++ 2 files changed, 24 insertions(+), 15 deletions(-) (limited to 'cmake/CMakeLists.txt') diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index dbcf3490..1b477762 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -11,24 +11,31 @@ if (MSVC) option(ZLIB "Build with zlib support" OFF) endif (MSVC) -# Path to common header -set(protobuf_COMMON_HEADER "../src/google/protobuf/stubs/common.h") +# Path to main configure script +set(protobuf_CONFIGURE_SCRIPT "../configure.ac") -# Parse version from common header -file(STRINGS "${protobuf_COMMON_HEADER}" protobuf_VERSION_LINE +# Parse version from configure script +file(STRINGS "${protobuf_CONFIGURE_SCRIPT}" protobuf_VERSION_LINE LIMIT_COUNT 1 - REGEX "^#define GOOGLE_PROTOBUF_VERSION [0-9]+$") -string(REGEX REPLACE "^.*PROTOBUF_VERSION ([0-9]+).*$" "\\1" - protobuf_VERSION_NUMBER "${protobuf_VERSION_LINE}") -math(EXPR protobuf_VERSION_MICRO - "${protobuf_VERSION_NUMBER} % 1000") -math(EXPR protobuf_VERSION_MINOR - "(${protobuf_VERSION_NUMBER} - ${protobuf_VERSION_MICRO}) % 1000000 / 1000") -math(EXPR protobuf_VERSION_MAJOR - "(${protobuf_VERSION_NUMBER} - ${protobuf_VERSION_MINOR} * 1000 - ${protobuf_VERSION_MICRO}) % 1000000000 / 1000000") -set(protobuf_VERSION_PATCH ${protobuf_VERSION_MICRO}) + REGEX "^AC_INIT") +# Replace special characters +string(REPLACE "(" "_" protobuf_VERSION_LINE ${protobuf_VERSION_LINE}) +string(REPLACE ")" "_" protobuf_VERSION_LINE ${protobuf_VERSION_LINE}) +string(REPLACE "[" "_" protobuf_VERSION_LINE ${protobuf_VERSION_LINE}) +string(REPLACE "]" "_" protobuf_VERSION_LINE ${protobuf_VERSION_LINE}) +# Parse version string +string(REGEX REPLACE "^AC_INIT__Protocol Buffers_,_([^_]+).*$" "\\1" + protobuf_VERSION_STRING "${protobuf_VERSION_LINE}") +# 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 - "${protobuf_VERSION_MAJOR}.${protobuf_VERSION_MINOR}.${protobuf_VERSION_MICRO}") + "${protobuf_VERSION_MAJOR}.${protobuf_VERSION_MINOR}.${protobuf_VERSION_PATCH}") add_definitions(-DGOOGLE_PROTOBUF_CMAKE_BUILD) diff --git a/cmake/protobuf-config.cmake.in b/cmake/protobuf-config.cmake.in index 6ae09d59..38fa58da 100644 --- a/cmake/protobuf-config.cmake.in +++ b/cmake/protobuf-config.cmake.in @@ -1 +1,3 @@ +set(protobuf_VERSION_STRING "@protobuf_VERSION_STRING@") + include("${CMAKE_CURRENT_LIST_DIR}/protobuf-targets.cmake") -- cgit v1.2.3