diff options
author | Konstantin Podsvirov <konstantin@podsvirov.pro> | 2016-06-01 17:00:08 +0300 |
---|---|---|
committer | Konstantin Podsvirov <konstantin@podsvirov.pro> | 2016-06-04 00:10:07 +0300 |
commit | 71556295ffe315be34ce70e1a6821860fb088f07 (patch) | |
tree | 2429940c0d78972693670df9aea755cf23ec9d59 /examples/CMakeLists.txt | |
parent | 20b532544fde1dff34429b52db95c3a96409b73c (diff) | |
download | protobuf-71556295ffe315be34ce70e1a6821860fb088f07.tar.gz protobuf-71556295ffe315be34ce70e1a6821860fb088f07.tar.bz2 protobuf-71556295ffe315be34ce70e1a6821860fb088f07.zip |
CMake project updates
A series of improvements:
- Improved Protobuf module compatibility (disabled by default);
- Hide advanced settings;
- Added build tree configuration;
- Added build of examples.
Diffstat (limited to 'examples/CMakeLists.txt')
-rw-r--r-- | examples/CMakeLists.txt | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 00000000..b4796f1c --- /dev/null +++ b/examples/CMakeLists.txt @@ -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()
|