ADD: added protbuf libs dependencies in CMakeLists.txt

This commit is contained in:
Henry Winkel
2022-10-22 15:12:29 +02:00
parent fab18d7d55
commit 22d06a02db
2 changed files with 46 additions and 0 deletions

View File

@@ -24,6 +24,13 @@ IF(NOT TARGET cppzmq)
add_subdirectory(libs/cppzmq EXCLUDE_FROM_ALL)
ENDIF()
set(protobuf_BUILD_TESTS OFF CACHE INTERNAL "")
set(protobuf_BUILD_EXAMPLES OFF CACHE INTERNAL "")
add_subdirectory(libs/protobuf EXCLUDE_FROM_ALL)
include(protobuf)
protobuf_generate_cpp(PROTO_PATH tests/protos CPP_PATH tests/protos/src HPP_PATH tests/protos/include)
add_library(whisper-com STATIC
include/WHISPER/whisper.hpp
@@ -37,6 +44,8 @@ target_link_libraries(whisper-com
libzmq
)
add_dependencies(whisper-com protoc)
target_include_directories(whisper-com PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:include>

View File

@@ -0,0 +1,37 @@
function(protobuf_generate_cpp)
set(OPTIONS)
set(SINGLE_VALUE_KEYWORDS
PROTO_PATH
CPP_PATH
HPP_PATH
)
set(MULTI_VALUE_KEYWORDS)
cmake_parse_arguments(protobuf
"${OPTIONS}"
"${SINGLE_VALUE_KEYWORDS}"
"${MULTI_VALUE_KEYWORDS}"
${ARGN})
FILE(GLOB PROTO_FILES ${protobuf_PROTO_PATH}/*.proto)
set(PROTOC ${CMAKE_BINARY_DIR}/libs/protobuf/protoc)
# set(PROTOC protoc)
FOREACH(proto ${PROTO_FILES})
FILE(TO_NATIVE_PATH ${proto} proto_native)
get_filename_component(protoFILENAME ${proto} NAME_WLE )
get_filename_component(protoDIR ${proto} DIRECTORY)
add_custom_command(
OUTPUT "${protoDIR}/${protoFILENAME}.pb.cc"
DEPENDS "${protoDIR}/${protoFILENAME}.proto"
COMMAND ${PROTOC} --cpp_out=${protoDIR} --proto_path=${protoDIR} --proto_path="${CMAKE_SOURCE_DIR}/libs/protobuf/src" "${protoDIR}/${protoFILENAME}.proto"
)
ENDFOREACH(proto)
endfunction()