Skip to content

Commit

Permalink
update output_zmqserver for CMake
Browse files Browse the repository at this point in the history
  • Loading branch information
machinekoder committed Jul 14, 2018
1 parent 080aec5 commit 8943c44
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 28 deletions.
1 change: 1 addition & 0 deletions mjpg-streamer-experimental/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ add_subdirectory(plugins/output_http)
add_subdirectory(plugins/output_rtsp)
add_subdirectory(plugins/output_udp)
add_subdirectory(plugins/output_viewer)
add_subdirectory(plugins/output_zmqserver)

#
# mjpg_streamer executable
Expand Down
86 changes: 86 additions & 0 deletions mjpg-streamer-experimental/cmake/FindProtobuf-c.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# PROTOBUF_C_FOUND - System has libprotobuf-c
# PROTOBUF_C_INCLUDE_DIRS - The libprotobuf-c include directories
# PROTOBUF_C_LIBRARIES - The libraries needed to use libprotobuf-c
# PROTOBUF_C_DEFINITIONS - Compiler switches required for using libprotobuf-c

function(PROTOBUF_C_GENERATE SRCS HDRS)
if(NOT ARGN)
message(SEND_ERROR "Error: PROTOBUFC_GENERATE() called without any proto files")
return()
endif()

if(PROTOBUF_C_GENERATE_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()

if(DEFINED PROTOBUFC_IMPORT_DIRS)
foreach(DIR ${PROTOBUF_IMPORT_DIRS})
get_filename_component(ABS_PATH ${DIR} ABSOLUTE)
list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
if(${_contains_already} EQUAL -1)
list(APPEND _protobuf_include_path -I ${ABS_PATH})
endif()
endforeach()
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.c")
list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb-c.h")

add_custom_command(
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb-c.c"
"${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb-c.h"
COMMAND ${PROTOBUFC_PROTOC_EXECUTABLE}
ARGS --c_out ${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${ABS_FIL}
DEPENDS ${ABS_FIL}
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()

# Find the protoc Executable
find_program(PROTOBUFC_PROTOC_EXECUTABLE
NAMES protoc-c
DOC "protoc-c compiler"
)

find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_check_modules(PC_PROTOBUF_C QUIET protobuf-c)
set(PROTOBUF_C_DEFINITIONS ${PC_PROTOBUF_C_CFLAGS_OTHER})
endif()

find_path(PROTOBUF_C_INCLUDE_DIR protobuf-c/protobuf-c.h
HINTS ${PC_PROTOBUF_C_INCLUDEDIR} ${PC_PROTOBUF_C_INCLUDE_DIRS}
PATH_SUFFIXES protobuf-c)

find_library(PROTOBUF_C_LIBRARY NAMES protobuf-c
HINTS ${PC_PROTOBUF_C_LIBDIR} ${PC_PROTOBUF_C_LIBRARY_DIRS})

set(PROTOBUF_C_LIBRARIES ${PROTOBUF_C_LIBRARY} )
set(PROTOBUF_C_INCLUDE_DIRS ${PROTOBUF_C_INCLUDE_DIR})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(protobuf-c DEFAULT_MSG
PROTOBUF_C_LIBRARY PROTOBUF_C_INCLUDE_DIR)

mark_as_advanced(PROTOBUF_C_INCLUDE_DIR YANG_LIBRARY)
19 changes: 19 additions & 0 deletions mjpg-streamer-experimental/cmake/FindZeroMQ.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## load in pkg-config support
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
## use pkg-config to get hints for 0mq locations
pkg_check_modules(PC_ZeroMQ QUIET zmq)
set(PROTOBUF_C_DEFINITIONS ${PC_PROTOBUF_C_CFLAGS_OTHER})
endif()

## use the hint from above to find where 'zmq.hpp' is located
find_path(ZeroMQ_INCLUDE_DIR
NAMES zmq.hpp
HINTS ${PC_ZeroMQ_INCLUDEDIR} ${PC_ZeroMQ_INCLUDE_DIRS}
)

## use the hint from about to find the location of libzmq
find_library(ZeroMQ_LIBRARY
NAMES zmq
HINTS ${PC_ZeroMQ_C_LIBDIR} ${PC_ZeroMQ_C_LIBRARY_DIRS}
)
22 changes: 22 additions & 0 deletions mjpg-streamer-experimental/plugins/output_zmqserver/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
include(FindZeroMQ)
include(FindProtobuf-c)

MJPG_STREAMER_PLUGIN_OPTION(output_zmqserver "ZMQ Server output plugin"
ONLYIF ZeroMQ_LIBRARY PROTOBUF_C_LIBRARY)

if (NOT ZeroMQ_LIBRARY)
message(WARNING Optional dependency ZeroMQ not found)
endif()

if (NOT PROTOBUF_C_LIBRARY)
message(WARNING Optional dependency Protobuf-c not found)
endif()

if (PLUGIN_OUTPUT_ZMQSERVER)
protobuf_c_generate(PROTO_SRC PROTO_HEADER package.proto)
include_directories(${ZeroMQ_INCLUDE_DIR})
include_directories(${PROTOBUF_C_INCLUDE_DIR})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
MJPG_STREAMER_PLUGIN_COMPILE(output_zmqserver ${PROTO_SRC} output_zmqserver.c)
target_link_libraries(output_zmqserver ${ZeroMQ_LIBRARY} ${PROTOBUF_C_LIBRARY})
endif()
28 changes: 0 additions & 28 deletions mjpg-streamer-experimental/plugins/output_zmqserver/Makefile

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
syntax = "proto2";
package pb;

message Package {
Expand Down

0 comments on commit 8943c44

Please sign in to comment.