source: nscp/build/cmake/NSCPPBuffer.cmake @ afd42f1

0.4.00.4.10.4.2
Last change on this file since afd42f1 was afd42f1, checked in by Michael Medin <michael@…>, 22 months ago

removed protobuf/log.proto.h and moved alll includes to target dir instead...

  • Property mode set to 100644
File size: 4.4 KB
Line 
1# Try to find protocol buffers (protobuf)
2#
3# Use as FIND_PACKAGE(ProtocolBuffers)
4#
5#  PROTOBUF_FOUND - system has the protocol buffers library
6#  PROTOBUF_INCLUDE_DIR - the zip include directory
7#  PROTOBUF_LIBRARY - Link this to use the zip library
8#  PROTOBUF_PROTOC_EXECUTABLE - executable protobuf compiler
9#
10# And the following command
11#
12#  WRAP_PROTO(VAR input1 input2 input3..)
13#
14# Which will run protoc on the input files and set VAR to the names of the created .cc files,
15# ready to be added to ADD_EXECUTABLE/ADD_LIBRARY. E.g,
16#
17#  WRAP_PROTO(PROTO_SRC myproto.proto external.proto)
18#  ADD_EXECUTABLE(server ${server_SRC} {PROTO_SRC})
19#
20# Author: Esben Mose Hansen <[EMAIL PROTECTED]>, (C) Ange Optimization ApS 2008
21#
22# Redistribution and use is allowed according to the terms of the BSD license.
23# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
24
25IF (PROTOBUF_LIBRARY AND PROTOBUF_INCLUDE_DIR AND PROTOBUF_PROTOC_EXECUTABLE)
26  # in cache already
27  SET(PROTOBUF_FOUND TRUE)
28  MESSAGE(STATUS "CACHED Protocol buffers was found!")
29ELSE (PROTOBUF_LIBRARY AND PROTOBUF_INCLUDE_DIR AND PROTOBUF_PROTOC_EXECUTABLE)
30        MESSAGE(STATUS "PROTOBUF Config: ${PROTOBUF_LIBRARY_PREFIX}...${PROTOBUF_LIBRARY_SUFFIX}, ${PROTOBUF_LIBRARY_PREFIX_DEBUG}...${PROTOBUF_LIBRARY_SUFFIX_DEBUG}" )
31
32  FIND_PATH(PROTOBUF_INCLUDE_DIR stubs/common.h
33    /usr/include/google/protobuf
34  )
35
36  FIND_LIBRARY(PROTOBUF_LIBRARY_RELEASE
37        NAMES ${PROTOBUF_LIBRARY_PREFIX}protobuf${PROTOBUF_LIBRARY_SUFFIX} ${PROTOBUF_LIBRARY_PREFIX}libprotobuf${PROTOBUF_LIBRARY_SUFFIX}
38    PATHS
39    ${GNUWIN32_DIR}/lib
40        ${PROTOBUF_LIBRARYDIR_RELEASE}
41        ${PROTOBUF_LIBRARYDIR}
42  )
43  FIND_LIBRARY(PROTOBUF_LIBRARY_DEBUG
44        NAMES ${PROTOBUF_LIBRARY_PREFIX_DEBUG}protobuf${PROTOBUF_LIBRARY_SUFFIX_DEBUG} ${PROTOBUF_LIBRARY_PREFIX_DEBUG}libprotobuf${PROTOBUF_LIBRARY_SUFFIX_DEBUG}
45    PATHS
46    ${GNUWIN32_DIR}/lib
47        ${PROTOBUF_LIBRARYDIR_DEBUG}
48        ${PROTOBUF_LIBRARYDIR}
49  )
50  SET(PROTOBUF_LIBRARY
51    debug ${PROTOBUF_LIBRARY_DEBUG}
52    optimized ${PROTOBUF_LIBRARY_RELEASE}
53  )
54 
55 
56  FIND_PROGRAM(PROTOBUF_PROTOC_EXECUTABLE protoc)
57  IF(NOT PROTOBUF_PROTOC_EXECUTABLE)
58        FIND_PROGRAM(PROTOBUF_PROTOC_EXECUTABLE protoc PATHS ${PROTOBUF_BINARYDIR})
59  ENDIF(NOT PROTOBUF_PROTOC_EXECUTABLE)
60
61  INCLUDE(FindPackageHandleStandardArgs)
62  FIND_PACKAGE_HANDLE_STANDARD_ARGS(protobuf DEFAULT_MSG PROTOBUF_INCLUDE_DIR PROTOBUF_LIBRARY PROTOBUF_PROTOC_EXECUTABLE)
63
64  # ensure that they are cached
65  SET(PROTOBUF_INCLUDE_DIR ${PROTOBUF_INCLUDE_DIR} CACHE INTERNAL "The protocol buffers include path")
66  SET(PROTOBUF_LIBRARY ${PROTOBUF_LIBRARY} CACHE INTERNAL "The libraries needed to use protocol buffers library")
67  SET(PROTOBUF_PROTOC_EXECUTABLE ${PROTOBUF_PROTOC_EXECUTABLE} CACHE INTERNAL "The protocol buffers compiler")
68
69  MESSAGE(STATUS "PROTOBUF_INCLUDE_DIR: ${PROTOBUF_INCLUDE_DIR}, PROTOBUF_LIBRARY: ${PROTOBUF_LIBRARY}, PROTOBUF_PROTOC_EXECUTABLE: ${PROTOBUF_PROTOC_EXECUTABLE}")
70
71ENDIF (PROTOBUF_LIBRARY AND PROTOBUF_INCLUDE_DIR AND PROTOBUF_PROTOC_EXECUTABLE)
72
73IF (PROTOBUF_FOUND)
74  MESSAGE(STATUS "Good: Protocol buffers was found (${PROTOBUF_INCLUDE_DIR})")
75  # Define the WRAP_PROTO function
76  SET(PROTOBUF_FOUND TRUE PARENT_SCOPE)
77  FUNCTION(WRAP_PROTO VAR)
78    IF (NOT ARGN)
79      MESSAGE(SEND_ERROR "Error: WRAP PROTO called without any proto files")
80      RETURN()
81    ENDIF(NOT ARGN)
82
83    SET(INCL)
84    SET(${VAR})
85    FOREACH(FIL ${ARGN})
86      GET_FILENAME_COMPONENT(ABS_FIL ${FIL} ABSOLUTE)
87      GET_FILENAME_COMPONENT(FIL_WE ${FIL} NAME_WE)
88      LIST(APPEND ${VAR} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc")
89      LIST(APPEND INCL "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h")
90         
91          SET(PB_TARGET_INCLUDE ${INCL})
92          #configure_file(${ABS_FIL}.h.in ${ABS_FIL}.h)
93
94      ADD_CUSTOM_COMMAND(
95        OUTPUT ${${VAR}} ${INCL}
96        COMMAND  ${PROTOBUF_PROTOC_EXECUTABLE}
97        ARGS --cpp_out  ${CMAKE_CURRENT_BINARY_DIR} --proto_path ${CMAKE_CURRENT_SOURCE_DIR} ${ABS_FIL}
98        DEPENDS ${ABS_FIL}
99        COMMENT "Running protocol buffer compiler on ${FIL} - ${PROTOBUF_PROTOC_EXECUTABLE}" VERBATIM )
100
101      SET_SOURCE_FILES_PROPERTIES(${${VAR}} ${INCL} PROPERTIES GENERATED TRUE)
102    ENDFOREACH(FIL)
103
104    SET(${VAR} ${${VAR}} PARENT_SCOPE)
105
106  ENDFUNCTION(WRAP_PROTO)
107ELSE(PROTOBUF_FOUND)
108  MESSAGE(WARNING "Error: Protocol buffers was not found!")
109ENDIF(PROTOBUF_FOUND)
Note: See TracBrowser for help on using the repository browser.