Commit 82983433 authored by Konstantin Podsvirov's avatar Konstantin Podsvirov

Install protobuf from cmake project

Additional export as "protobuf" package
for importing from other cmake projects
parent c20f67fd
# Minimum CMake required
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 2.8)
# Project
project(protobuf C CXX) project(protobuf C CXX)
# Options
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)
option(ZLIB "Build with zlib support" OFF) option(ZLIB "Build with zlib support" OFF)
endif (MSVC) 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) add_definitions(-DGOOGLE_PROTOBUF_CMAKE_BUILD)
find_package(Threads REQUIRED) find_package(Threads REQUIRED)
...@@ -73,6 +95,9 @@ include(libprotobuf-lite.cmake) ...@@ -73,6 +95,9 @@ include(libprotobuf-lite.cmake)
include(libprotobuf.cmake) include(libprotobuf.cmake)
include(libprotoc.cmake) include(libprotoc.cmake)
include(protoc.cmake) include(protoc.cmake)
if (BUILD_TESTING) if (BUILD_TESTING)
include(tests.cmake) include(tests.cmake)
endif (BUILD_TESTING) endif (BUILD_TESTING)
include(install.cmake)
include(GNUInstallDirs)
foreach(_library
libprotobuf-lite
libprotobuf
libprotoc)
set_property(TARGET ${_library}
PROPERTY INTERFACE_INCLUDE_DIRECTORIES $<INSTALL_INTERFACE:include>)
install(TARGETS ${_library} EXPORT protobuf-targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${_library}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${_library}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT ${_library})
endforeach()
install(TARGETS protoc EXPORT protobuf-targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT protoc)
if(MSVC)
file(STRINGS extract_includes.bat.in _extract_strings
REGEX "^copy")
foreach(_extract_string ${_extract_strings})
string(REPLACE "copy \${PROTOBUF_SOURCE_WIN32_PATH}\\" ""
_extract_string ${_extract_string})
string(REPLACE "\\" "/" _extract_string ${_extract_string})
string(REGEX MATCH "^[^ ]+"
_extract_from ${_extract_string})
string(REGEX REPLACE "^${_extract_from} ([^$]+)" "\\1"
_extract_to ${_extract_string})
get_filename_component(_extract_from "${protobuf_SOURCE_DIR}/${_extract_from}" ABSOLUTE)
get_filename_component(_extract_name ${_extract_to} NAME)
get_filename_component(_extract_to ${_extract_to} PATH)
if(EXISTS "${_extract_from}")
install(FILES "${_extract_from}"
DESTINATION "${_extract_to}"
COMPONENT protobuf-headers
RENAME "${_extract_name}")
else()
message(AUTHOR_WARNING "The file \"${_extract_from}\" is listed in "
"\"${protobuf_SOURCE_DIR}/cmake/extract_includes.bat.in\" "
"but there not exists. The file will not be installed.")
endif()
endforeach()
endif()
install(EXPORT protobuf-targets
DESTINATION "lib/cmake/protobuf"
COMPONENT protobuf-export)
configure_file(protobuf-config.cmake.in
protobuf-config.cmake @ONLY)
configure_file(protobuf-config-version.cmake.in
protobuf-config-version.cmake @ONLY)
install(FILES
"${protobuf_BINARY_DIR}/protobuf-config.cmake"
"${protobuf_BINARY_DIR}/protobuf-config-version.cmake"
DESTINATION "lib/cmake/protobuf"
COMPONENT protobuf-export)
set(PACKAGE_VERSION @protobuf_VERSION@)
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