1 # Locate and configure the Google Protocol Buffers library.
2 # Defines the following variables:
4 # PROTOBUF_FOUND - Found the Google Protocol Buffers library
5 # PROTOBUF_INCLUDE_DIRS - Include directories for Google Protocol Buffers
6 # PROTOBUF_LIBRARIES - The protobuf library
8 # The following cache variables are also defined:
9 # PROTOBUF_LIBRARY - The protobuf library
10 # PROTOBUF_PROTOC_LIBRARY - The protoc library
11 # PROTOBUF_INCLUDE_DIR - The include directory for protocol buffers
12 # PROTOBUF_PROTOC_EXECUTABLE - The protoc compiler
14 #====================================================================
17 # find_package(Protobuf REQUIRED)
18 # include_directories(${PROTOBUF_INCLUDE_DIRS})
20 # include_directories(${CMAKE_CURRENT_BINARY_DIR})
21 # PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS foo.proto)
22 # add_executable(bar bar.cc ${PROTO_SRCS} ${PROTO_HDRS})
23 # target_link_libraries(bar ${PROTOBUF_LIBRARY})
25 # NOTE: You may need to link against pthreads, depending
27 #====================================================================
29 # PROTOBUF_GENERATE_CPP (public function)
30 # SRCS = Variable to define with autogenerated
32 # HDRS = Variable to define with autogenerated
36 #====================================================================
38 # Esben Mose Hansen <[EMAIL PROTECTED]>, (c) Ange Optimization ApS 2008
39 # Adapted by Philip Lowman <philip@yhbt.com> (c) 2009
41 # Redistribution and use is allowed according to the terms of the BSD license.
42 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
44 function(PROTOBUF_GENERATE_CPP SRCS HDRS)
46 message(SEND_ERROR "Error: PROTOBUF_GENERATE_CPP() called without any proto files")
53 get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
54 get_filename_component(FIL_WE ${FIL} NAME_WE)
56 list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc")
57 list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h")
60 OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc"
61 "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h"
62 COMMAND ${PROTOBUF_PROTOC_EXECUTABLE}
63 ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} --proto_path ${CMAKE_CURRENT_SOURCE_DIR} ${ABS_FIL}
65 COMMENT "Running C++ protocol buffer compiler on ${FIL}"
69 set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE)
70 set(${SRCS} ${${SRCS}} PARENT_SCOPE)
71 set(${HDRS} ${${HDRS}} PARENT_SCOPE)
75 find_path(PROTOBUF_INCLUDE_DIR google/protobuf/service.h)
77 # Google's provided vcproj files generate libraries with a "lib"
80 set(PROTOBUF_ORIG_FIND_LIBRARY_PREFIXES "${CMAKE_FIND_LIBRARY_PREFIXES}")
81 set(CMAKE_FIND_LIBRARY_PREFIXES "lib" "")
84 find_library(PROTOBUF_LIBRARY NAMES protobuf
85 DOC "The Google Protocol Buffers Library"
87 find_library(PROTOBUF_PROTOC_LIBRARY NAMES protoc
88 DOC "The Google Protocol Buffers Compiler Library"
90 find_program(PROTOBUF_PROTOC_EXECUTABLE NAMES protoc
91 DOC "The Google Protocol Buffers Compiler"
94 mark_as_advanced(PROTOBUF_INCLUDE_DIR
96 PROTOBUF_PROTOC_LIBRARY
97 PROTOBUF_PROTOC_EXECUTABLE)
99 # Restore original find library prefixes
101 set(CMAKE_FIND_LIBRARY_PREFIXES "${PROTOBUF_ORIG_FIND_LIBRARY_PREFIXES}")
104 include(FindPackageHandleStandardArgs)
105 FIND_PACKAGE_HANDLE_STANDARD_ARGS(PROTOBUF DEFAULT_MSG
106 PROTOBUF_LIBRARY PROTOBUF_INCLUDE_DIR)
109 set(PROTOBUF_INCLUDE_DIRS ${PROTOBUF_INCLUDE_DIR})
110 set(PROTOBUF_LIBRARIES ${PROTOBUF_LIBRARY})