From c0e5c73716dcbf03dfa9c2093cfe5a63a9460ca0 Mon Sep 17 00:00:00 2001 From: Christina Sander Date: Thu, 31 Aug 2023 11:07:31 +0200 Subject: [PATCH] MOD: Modifies cmake include for protobuf - sets the protoc path in CMakeLists.txt file so it can also be used in top level projects - sets the proto source file path so it can be used in top level projects - uses cmake variable PROTO_SRC_PATH defined in CMakeLists for the custom command in the protobuf.cmake file --- CMakeLists.txt | 2 ++ cmake/Modules/protobuf.cmake | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a839860..fa6c26b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,6 +65,8 @@ IF(NOT TARGET protobuf) SET(protobuf_BUILD_SHARED_LIBS OFF CACHE BOOL "disable shared libraries") #SET(WITH_PROTOC ON CACHE BOOL "enable building of protoc") add_subdirectory(libs/protobuf EXCLUDE_FROM_ALL) + set(PROTOC ${CMAKE_CURRENT_BINARY_DIR}/libs/protobuf/protoc CACHE INTERNAL "" ) + set(PROTO_SRC_PATH ${CMAKE_CURRENT_SOURCE_DIR}/libs/protobuf/src CACHE INTERNAL "" ) ENDIF() # we are building with c++20 diff --git a/cmake/Modules/protobuf.cmake b/cmake/Modules/protobuf.cmake index e2fd5f4..6ecc308 100644 --- a/cmake/Modules/protobuf.cmake +++ b/cmake/Modules/protobuf.cmake @@ -13,8 +13,6 @@ function(protobuf_generate_cpp) ${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) @@ -25,7 +23,7 @@ function(protobuf_generate_cpp) 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" + COMMAND ${PROTOC} --cpp_out=${protoDIR} --proto_path=${protoDIR} --proto_path=${PROTO_SRC_PATH} "${protoDIR}/${protoFILENAME}.proto" ) ENDFOREACH(proto) -- 2.45.2