cmake例子:使用protobuf和打包
2020-05-07 本文已影响0人
gb_QA_log
sudo apt-get install protobuf-compiler libprotobuf-dev
cmake_minimum_required(VERSION 3.5)
project (tensorflow)
# PROTOBUF_FOUND, PROTOBUF_INCLUDE_DIRS, PROTOBUF_LIBRARIES
find_package(Protobuf REQUIRED)
PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS AddressBook.proto)
# call protobuf compiler to compiling when `make`
add_library(addr_libarary SHARED
${PROTO_SRCS}
)
target_include_directories(addr_libarary
Public
${PROTO_HDRS}
)
add_executable(protobuf_example
main.cpp
)
target_link_libraries(tensorflow
PRIVATE
${PROTOBUF_LIBRARIES}
addr_libarary
)
# Create DEB
# Tell CPack to generate a .deb package
set(CPACK_GENERATOR "DEB")
# Set a Package Maintainer.
# This is required
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Thom Troy")
# Set a Package Version
set(CPACK_PACKAGE_VERSION ${deb_example_VERSION})
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "for test")
set(CPACK_PACKAGE_DESCRIPTION "nothing for test")
# Include CPack
include(CPack)
# @file: AddressBook.proto
package addressbook; # namespace::
message Person {
required string name = 1;
required int32 id = 2;
optional string email = 3;
enum PhoneType {
MOBILE = 0;
HOME = 1;
WORK = 2;
}
message PhoneNumber {
required string number = 1;
optional PhoneType type = 2 [default = HOME];
}
repeated PhoneNumber phone = 4;
}
message AddressBook {
repeated Person person = 1;
}
mkdir build && cd build
cmake .. -Ddeb_example_VERSION=0.1
make -j VERBOSE=1
make install
make package