summaryrefslogtreecommitdiff
path: root/cmake
diff options
context:
space:
mode:
authorSander Vrijders <sander.vrijders@intec.ugent.be>2016-03-25 19:13:32 +0100
committerSander Vrijders <sander.vrijders@intec.ugent.be>2016-03-25 19:13:32 +0100
commitd37add0f20c93432c0b4c12866810c124a7a18ec (patch)
treee6d115d469ce95627fc802b8ee454614e826059a /cmake
parent35b00759a9616033aa19177ba3281eb9643509d2 (diff)
downloadouroboros-d37add0f20c93432c0b4c12866810c124a7a18ec.tar.gz
ouroboros-d37add0f20c93432c0b4c12866810c124a7a18ec.zip
build: Add protobuf-c commands for cmake
This adds a cmake file so that the build can ask to generate protobuf-c files from .proto files. The messages between the IRM and the library are compiled into the library.
Diffstat (limited to 'cmake')
-rw-r--r--cmake/FindProtobufC.cmake72
1 files changed, 72 insertions, 0 deletions
diff --git a/cmake/FindProtobufC.cmake b/cmake/FindProtobufC.cmake
new file mode 100644
index 00000000..cae9f1c3
--- /dev/null
+++ b/cmake/FindProtobufC.cmake
@@ -0,0 +1,72 @@
+function(PROTOBUF_GENERATE_C SRCS HDRS)
+ if(NOT ARGN)
+ message(SEND_ERROR "Error: PROTOBUF_GENERATE_C() called without any proto files")
+ return()
+ endif()
+
+ if(PROTOBUF_GENERATE_C_APPEND_PATH)
+ # Create an include path for each file specified
+ foreach(FIL ${ARGN})
+ get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
+ get_filename_component(ABS_PATH ${ABS_FIL} PATH)
+ list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
+ if(${_contains_already} EQUAL -1)
+ list(APPEND _protobuf_include_path -I ${ABS_PATH})
+ endif()
+ endforeach()
+ else()
+ set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR})
+ endif()
+
+ set(${SRCS})
+ set(${HDRS})
+ foreach(FIL ${ARGN})
+ get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
+ get_filename_component(FIL_WE ${FIL} NAME_WE)
+
+ list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb-c.cc")
+ list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb-c.h")
+
+ add_custom_command(
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb-c.cc"
+ "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb-c.h"
+ COMMAND ${PROTOBUF_PROTOC_C_EXECUTABLE}
+ ARGS --c_out=${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${ABS_FIL}
+ DEPENDS ${ABS_FIL} ${PROTOBUF_PROTOC_C_EXECUTABLE}
+ COMMENT "Running C protocol buffer compiler on ${FIL}"
+ VERBATIM )
+ endforeach()
+
+ set_source_files_properties(${${SRCS}} ${${HDRS}} PROPERTIES GENERATED TRUE)
+ set(${SRCS} ${${SRCS}} PARENT_SCOPE)
+ set(${HDRS} ${${HDRS}} PARENT_SCOPE)
+endfunction()
+
+# By default have PROTOBUF_GENERATE_C macro pass -I to protoc
+# for each directory where a proto file is referenced.
+if(NOT DEFINED PROTOBUF_GENERATE_C_APPEND_PATH)
+ set(PROTOBUF_GENERATE_C_APPEND_PATH TRUE)
+endif()
+
+# Find library
+find_library(PROTOBUF_C_LIBRARY
+ NAMES libprotobuf-c.so libprotobuf-c
+)
+mark_as_advanced(PROTOBUF_C_LIBRARY)
+
+# Find the include directory
+find_path(PROTOBUF_C_INCLUDE_DIR
+ google/protobuf-c/protobuf-c.h
+)
+mark_as_advanced(PROTOBUF_C_INCLUDE_DIR)
+
+# Find the protoc-c Executable
+find_program(PROTOBUF_PROTOC_C_EXECUTABLE
+ NAMES protoc-c
+ DOC "The Google Protocol Buffers C Compiler"
+)
+mark_as_advanced(PROTOBUF_PROTOC_C_EXECUTABLE)
+
+find_package(PackageHandleStandardArgs)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(ProtobufC DEFAULT_MSG
+ PROTOBUF_C_LIBRARY PROTOBUF_C_INCLUDE_DIR PROTOBUF_PROTOC_C_EXECUTABLE)