A series of improvements: - Improved Protobuf module compatibility (disabled by default); - Hide advanced settings; - Added build tree configuration; - Added build of examples.pull/1642/head
parent
20b532544f
commit
71556295ff
9 changed files with 312 additions and 69 deletions
@ -0,0 +1,10 @@ |
|||||||
|
if(protobuf_VERBOSE) |
||||||
|
message(STATUS "Protocol Buffers Examples Configuring...") |
||||||
|
endif() |
||||||
|
|
||||||
|
# Add examples subproject |
||||||
|
add_subdirectory(../examples examples) |
||||||
|
|
||||||
|
if(protobuf_VERBOSE) |
||||||
|
message(STATUS "Protocol Buffers Examples Configuring done") |
||||||
|
endif() |
@ -1,19 +1,10 @@ |
|||||||
# Version info variables |
# User options |
||||||
set(PROTOBUF_VERSION "@protobuf_VERSION@") |
include("${CMAKE_CURRENT_LIST_DIR}/protobuf-options.cmake") |
||||||
set(PROTOBUF_VERSION_STRING "@protobuf_VERSION_STRING@") |
|
||||||
|
|
||||||
# Imported targets |
# Imported targets |
||||||
include("${CMAKE_CURRENT_LIST_DIR}/protobuf-targets.cmake") |
include("${CMAKE_CURRENT_LIST_DIR}/protobuf-targets.cmake") |
||||||
|
|
||||||
# Compute the installation prefix relative to this file. |
|
||||||
get_filename_component(_PROTOBUF_IMPORT_PREFIX |
|
||||||
"${_PROTOBUF_PACKAGE_PREFIX}" PATH) |
|
||||||
get_filename_component(_PROTOBUF_IMPORT_PREFIX |
|
||||||
"${_PROTOBUF_IMPORT_PREFIX}" PATH) |
|
||||||
get_filename_component(_PROTOBUF_IMPORT_PREFIX |
|
||||||
"${_PROTOBUF_IMPORT_PREFIX}" PATH) |
|
||||||
|
|
||||||
# CMake FindProtobuf module compatible file |
# CMake FindProtobuf module compatible file |
||||||
if(NOT DEFINED PROTOBUF_MODULE_COMPATIBLE OR "${PROTOBUF_MODULE_COMPATIBLE}") |
if(protobuf_MODULE_COMPATIBLE) |
||||||
include("${_PROTOBUF_PACKAGE_PREFIX}/protobuf-module.cmake") |
include("${CMAKE_CURRENT_LIST_DIR}/protobuf-module.cmake") |
||||||
endif() |
endif() |
||||||
|
@ -0,0 +1,7 @@ |
|||||||
|
# Verbose output |
||||||
|
option(protobuf_VERBOSE "Enable for verbose output" OFF) |
||||||
|
mark_as_advanced(protobuf_VERBOSE) |
||||||
|
|
||||||
|
# FindProtobuf module compatibel |
||||||
|
option(protobuf_MODULE_COMPATIBLE "CMake build-in FindProtobuf.cmake module compatible" OFF) |
||||||
|
mark_as_advanced(protobuf_MODULE_COMPATIBLE) |
@ -0,0 +1,17 @@ |
|||||||
|
# Library aliases |
||||||
|
foreach(_library |
||||||
|
libprotobuf-lite |
||||||
|
libprotobuf |
||||||
|
libprotoc) |
||||||
|
if(TARGET ${_library} AND NOT TARGET protobuf::${_library}) |
||||||
|
add_library(protobuf::${_library} ALIAS ${_library}) |
||||||
|
endif() |
||||||
|
endforeach() |
||||||
|
|
||||||
|
# Executable aliases |
||||||
|
foreach(_executable |
||||||
|
protoc) |
||||||
|
if(TARGET ${_executable} AND NOT TARGET protobuf::${_executable}) |
||||||
|
add_executable(protobuf::${_executable} ALIAS ${_executable}) |
||||||
|
endif() |
||||||
|
endforeach() |
@ -0,0 +1,79 @@ |
|||||||
|
# Minimum CMake required |
||||||
|
cmake_minimum_required(VERSION 2.8.12) |
||||||
|
|
||||||
|
# Project |
||||||
|
project(addressbook) |
||||||
|
|
||||||
|
# Find required protobuf package |
||||||
|
find_package(protobuf 3 CONFIG REQUIRED) |
||||||
|
|
||||||
|
if(protobuf_VERBOSE) |
||||||
|
message(STATUS "Using Protocol Buffers ${Protobuf_VERSION}") |
||||||
|
endif() |
||||||
|
|
||||||
|
file(GLOB SRC_LIST "*.cc") |
||||||
|
|
||||||
|
file(GLOB PROTO_LIST "*.proto") |
||||||
|
|
||||||
|
# |
||||||
|
# Code generation |
||||||
|
# |
||||||
|
|
||||||
|
if(protobuf_MODULE_COMPATIBLE) # Old school |
||||||
|
|
||||||
|
include_directories(${Protobuf_INCLUDE_DIRS}) |
||||||
|
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${PROTO_LIST}) |
||||||
|
|
||||||
|
else() # New style |
||||||
|
|
||||||
|
set(PROTO_SRCS) |
||||||
|
set(PROTO_HDRS) |
||||||
|
|
||||||
|
foreach(FIL ${PROTO_LIST}) |
||||||
|
|
||||||
|
get_filename_component(ABS_FIL ${FIL} ABSOLUTE) |
||||||
|
get_filename_component(FIL_WE ${FIL} NAME_WE) |
||||||
|
|
||||||
|
list(APPEND PROTO_SRCS "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc") |
||||||
|
list(APPEND PROTO_HDRS "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h") |
||||||
|
|
||||||
|
add_custom_command( |
||||||
|
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc" |
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h" |
||||||
|
COMMAND protobuf::protoc |
||||||
|
ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} -I ${CMAKE_CURRENT_SOURCE_DIR} |
||||||
|
${ABS_FIL} |
||||||
|
DEPENDS ${ABS_FIL} |
||||||
|
COMMENT "Running C++ protocol buffer compiler on ${FIL}" |
||||||
|
VERBATIM) |
||||||
|
|
||||||
|
endforeach() |
||||||
|
|
||||||
|
endif() |
||||||
|
|
||||||
|
include_directories(${CMAKE_CURRENT_BINARY_DIR}) |
||||||
|
|
||||||
|
include(GNUInstallDirs) |
||||||
|
|
||||||
|
foreach(FIL ${SRC_LIST}) |
||||||
|
|
||||||
|
get_filename_component(FIL_NAME_WE ${FIL} NAME_WE) |
||||||
|
|
||||||
|
set(APP ${FIL_NAME_WE}_cpp) |
||||||
|
|
||||||
|
add_executable(${APP} ${FIL} ${PROTO_SRCS} ${PROTO_HDRS}) |
||||||
|
|
||||||
|
# |
||||||
|
# Link libraries |
||||||
|
# |
||||||
|
|
||||||
|
if(protobuf_MODULE_COMPATIBLE) # Old school |
||||||
|
target_link_libraries(${APP} ${Protobuf_LIBRARIES}) |
||||||
|
else() # New style |
||||||
|
target_link_libraries(${APP} protobuf::libprotobuf) |
||||||
|
endif() |
||||||
|
|
||||||
|
install(TARGETS ${APP} |
||||||
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT ${APP}) |
||||||
|
|
||||||
|
endforeach() |
Loading…
Reference in new issue