mirror of
https://github.com/ttroy50/cmake-examples.git
synced 2025-12-18 04:14:34 +03:00
40 lines
854 B
CMake
40 lines
854 B
CMake
cmake_minimum_required(VERSION 3.5)
|
|
|
|
# Set the project name
|
|
project (protobuf_example)
|
|
|
|
# find the protobuf compiler and libraries
|
|
find_package(Protobuf REQUIRED)
|
|
|
|
# check if protobuf was found
|
|
if(PROTOBUF_FOUND)
|
|
message ("protobuf found")
|
|
else()
|
|
message (FATAL_ERROR "Cannot find Protobuf")
|
|
endif()
|
|
|
|
# Generate the .h and .cxx files
|
|
PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS AddressBook.proto)
|
|
|
|
# Print path to generated files
|
|
message ("PROTO_SRCS = ${PROTO_SRCS}")
|
|
message ("PROTO_HDRS = ${PROTO_HDRS}")
|
|
|
|
# Add an executable
|
|
add_executable(protobuf_example
|
|
main.cpp
|
|
${PROTO_SRCS}
|
|
${PROTO_HDRS})
|
|
|
|
target_include_directories(protobuf_example
|
|
PUBLIC
|
|
${PROTOBUF_INCLUDE_DIRS}
|
|
${CMAKE_CURRENT_BINARY_DIR}
|
|
)
|
|
|
|
# link the exe against the libraries
|
|
target_link_libraries(protobuf_example
|
|
PUBLIC
|
|
${PROTOBUF_LIBRARIES}
|
|
)
|