|
|
|
@ -4,39 +4,65 @@ cmake_minimum_required(VERSION 2.8) |
|
|
|
|
# Project |
|
|
|
|
project(protobuf C CXX) |
|
|
|
|
|
|
|
|
|
# CMake policies |
|
|
|
|
cmake_policy(SET CMP0022 NEW) |
|
|
|
|
|
|
|
|
|
# Options |
|
|
|
|
option(BUILD_TESTING "Build tests" ON) |
|
|
|
|
option(BUILD_SHARED_LIBS "Build Shared Libraries" OFF) |
|
|
|
|
option(protobuf_VERBOSE "Enable for verbose output" OFF) |
|
|
|
|
option(protobuf_BUILD_TESTS "Build tests" ON) |
|
|
|
|
if (BUILD_SHARED_LIBS) |
|
|
|
|
set(protobuf_BUILD_SHARED_LIBS_DEFAULT ON) |
|
|
|
|
else (BUILD_SHARED_LIBS) |
|
|
|
|
set(protobuf_BUILD_SHARED_LIBS_DEFAULT OFF) |
|
|
|
|
endif (BUILD_SHARED_LIBS) |
|
|
|
|
option(protobuf_BUILD_SHARED_LIBS "Build Shared Libraries" ${protobuf_BUILD_SHARED_LIBS_DEFAULT}) |
|
|
|
|
option(protobuf_MSVC_STATIC_RUNTIME "Link static runtime libraries" ON) |
|
|
|
|
if (MSVC) |
|
|
|
|
option(ZLIB "Build with zlib support" OFF) |
|
|
|
|
set(protobuf_WITH_ZLIB_DEFAULT OFF) |
|
|
|
|
else (MSVC) |
|
|
|
|
set(protobuf_WITH_ZLIB_DEFAULT ON) |
|
|
|
|
endif (MSVC) |
|
|
|
|
option(protobuf_WITH_ZLIB "Build with zlib support" ${protobuf_WITH_ZLIB_DEFAULT}) |
|
|
|
|
set(protobuf_DEBUG_POSTFIX "d" |
|
|
|
|
CACHE STRING "Default debug postfix") |
|
|
|
|
|
|
|
|
|
# Path to main configure script |
|
|
|
|
set(protobuf_CONFIGURE_SCRIPT "../configure.ac") |
|
|
|
|
|
|
|
|
|
# Parse version from configure script |
|
|
|
|
file(STRINGS "${protobuf_CONFIGURE_SCRIPT}" protobuf_VERSION_LINE |
|
|
|
|
LIMIT_COUNT 1 |
|
|
|
|
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 configure script |
|
|
|
|
set(protobuf_AC_INIT_REGEX |
|
|
|
|
"^AC_INIT\\(\\[([^]]+)\\],\\[([^]]+)\\],\\[([^]]+)\\],\\[([^]]+)\\]\\)$") |
|
|
|
|
file(STRINGS "${protobuf_CONFIGURE_SCRIPT}" protobuf_AC_INIT_LINE |
|
|
|
|
LIMIT_COUNT 1 REGEX "^AC_INIT") |
|
|
|
|
# Description |
|
|
|
|
string(REGEX REPLACE "${protobuf_AC_INIT_REGEX}" "\\1" |
|
|
|
|
protobuf_DESCRIPTION "${protobuf_AC_INIT_LINE}") |
|
|
|
|
# Version |
|
|
|
|
string(REGEX REPLACE "${protobuf_AC_INIT_REGEX}" "\\2" |
|
|
|
|
protobuf_VERSION_STRING "${protobuf_AC_INIT_LINE}") |
|
|
|
|
# Contact |
|
|
|
|
string(REGEX REPLACE "${protobuf_AC_INIT_REGEX}" "\\3" |
|
|
|
|
protobuf_CONTACT "${protobuf_AC_INIT_LINE}") |
|
|
|
|
# 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}") |
|
|
|
|
string(REGEX REPLACE "^([0-9]+)\\.([0-9]+)\\.([0-9]+).*$" "\\2" |
|
|
|
|
string(REGEX REPLACE "${protobuf_VERSION_REGEX}" "\\2" |
|
|
|
|
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}") |
|
|
|
|
# Package version |
|
|
|
|
set(protobuf_VERSION |
|
|
|
|
"${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) |
|
|
|
|
|
|
|
|
|
find_package(Threads REQUIRED) |
|
|
|
@ -44,18 +70,17 @@ if (CMAKE_USE_PTHREADS_INIT) |
|
|
|
|
add_definitions(-DHAVE_PTHREAD) |
|
|
|
|
endif (CMAKE_USE_PTHREADS_INIT) |
|
|
|
|
|
|
|
|
|
if (MSVC) |
|
|
|
|
if (ZLIB) |
|
|
|
|
set(HAVE_ZLIB 1) |
|
|
|
|
find_path(ZLIB_INCLUDE_DIRECTORIES zlib.h ${protobuf_SOURCE_DIR}) |
|
|
|
|
find_library(ZLIB_LIBRARIES zdll ${protobuf_SOURCE_DIR}) |
|
|
|
|
else (ZLIB) |
|
|
|
|
set(HAVE_ZLIB 0) |
|
|
|
|
endif (ZLIB) |
|
|
|
|
else (MSVC) |
|
|
|
|
if (protobuf_WITH_ZLIB) |
|
|
|
|
find_package(ZLIB) |
|
|
|
|
if (ZLIB_FOUND) |
|
|
|
|
set(HAVE_ZLIB 1) |
|
|
|
|
# FindZLIB module define ZLIB_INCLUDE_DIRS variable |
|
|
|
|
# Set ZLIB_INCLUDE_DIRECTORIES for compatible |
|
|
|
|
set(ZLIB_INCLUDE_DIRECTORIES ${ZLIB_INCLUDE_DIRECTORIES} ${ZLIB_INCLUDE_DIRS}) |
|
|
|
|
# Using imported target if exists |
|
|
|
|
if (TARGET ZLIB::ZLIB) |
|
|
|
|
set(ZLIB_LIBRARIES ZLIB::ZLIB) |
|
|
|
|
endif (TARGET ZLIB::ZLIB) |
|
|
|
|
else (ZLIB_FOUND) |
|
|
|
|
set(HAVE_ZLIB 0) |
|
|
|
|
# Explicitly set these to empty (override NOT_FOUND) so cmake doesn't |
|
|
|
@ -63,21 +88,22 @@ else (MSVC) |
|
|
|
|
set(ZLIB_INCLUDE_DIRECTORIES) |
|
|
|
|
set(ZLIB_LIBRARIES) |
|
|
|
|
endif (ZLIB_FOUND) |
|
|
|
|
endif (MSVC) |
|
|
|
|
endif (protobuf_WITH_ZLIB) |
|
|
|
|
|
|
|
|
|
if (HAVE_ZLIB) |
|
|
|
|
add_definitions(-DHAVE_ZLIB) |
|
|
|
|
endif (HAVE_ZLIB) |
|
|
|
|
|
|
|
|
|
if (MSVC) |
|
|
|
|
if (BUILD_SHARED_LIBS) |
|
|
|
|
add_definitions(-DPROTOBUF_USE_DLLS) |
|
|
|
|
else (BUILD_SHARED_LIBS) |
|
|
|
|
if (protobuf_BUILD_SHARED_LIBS) |
|
|
|
|
set(protobuf_SHARED_OR_STATIC "SHARED") |
|
|
|
|
else (protobuf_BUILD_SHARED_LIBS) |
|
|
|
|
set(protobuf_SHARED_OR_STATIC "STATIC") |
|
|
|
|
# In case we are building static libraries, link also the runtime library statically |
|
|
|
|
# so that MSVCR*.DLL is not required at runtime. |
|
|
|
|
# https://msdn.microsoft.com/en-us/library/2kzt1wy3.aspx |
|
|
|
|
# This is achieved by replacing msvc option /MD with /MT and /MDd with /MTd |
|
|
|
|
# http://www.cmake.org/Wiki/CMake_FAQ#How_can_I_build_my_MSVC_application_with_a_static_runtime.3F |
|
|
|
|
if (MSVC AND protobuf_MSVC_STATIC_RUNTIME) |
|
|
|
|
foreach(flag_var |
|
|
|
|
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE |
|
|
|
|
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO) |
|
|
|
@ -85,11 +111,11 @@ if (MSVC) |
|
|
|
|
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}") |
|
|
|
|
endif(${flag_var} MATCHES "/MD") |
|
|
|
|
endforeach(flag_var) |
|
|
|
|
endif (BUILD_SHARED_LIBS) |
|
|
|
|
add_definitions(/wd4244 /wd4267 /wd4018 /wd4355 /wd4800 /wd4251 /wd4996 /wd4146 /wd4305) |
|
|
|
|
endif (MSVC) |
|
|
|
|
endif (MSVC AND protobuf_MSVC_STATIC_RUNTIME) |
|
|
|
|
endif (protobuf_BUILD_SHARED_LIBS) |
|
|
|
|
|
|
|
|
|
if (MSVC) |
|
|
|
|
add_definitions(/wd4244 /wd4267 /wd4018 /wd4355 /wd4800 /wd4251 /wd4996 /wd4146 /wd4305) |
|
|
|
|
string(REPLACE "/" "\\" PROTOBUF_SOURCE_WIN32_PATH ${protobuf_SOURCE_DIR}) |
|
|
|
|
string(REPLACE "/" "\\" PROTOBUF_BINARY_WIN32_PATH ${protobuf_BINARY_DIR}) |
|
|
|
|
configure_file(extract_includes.bat.in extract_includes.bat) |
|
|
|
@ -116,8 +142,8 @@ include(libprotobuf.cmake) |
|
|
|
|
include(libprotoc.cmake) |
|
|
|
|
include(protoc.cmake) |
|
|
|
|
|
|
|
|
|
if (BUILD_TESTING) |
|
|
|
|
if (protobuf_BUILD_TESTS) |
|
|
|
|
include(tests.cmake) |
|
|
|
|
endif (BUILD_TESTING) |
|
|
|
|
endif (protobuf_BUILD_TESTS) |
|
|
|
|
|
|
|
|
|
include(install.cmake) |
|
|
|
|