Skip to content

Commit 50acdd5

Browse files
committed
CMake: Allow build system to provide protobuf compiler
When building without Hunter, it is desirable to pass the path to protoc and the protobuf include directory from the build system. Allow these variables to be overridden. Fixes the error: | CMake Error at cmake/functions.cmake:52 (message): | Protobuf_PROTOC_EXECUTABLE is empty | Call Stack (most recent call first): | cmake/functions.cmake:96 (compile_proto_to_cpp) | src/crypto/protobuf/CMakeLists.txt:6 (add_proto_library)
1 parent e572ecb commit 50acdd5

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

cmake/functions.cmake

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,13 @@ function(add_flag flag)
4545
endfunction()
4646

4747
function(compile_proto_to_cpp PROTO_LIBRARY_NAME PB_H PB_CC PROTO)
48-
get_target_property(Protobuf_INCLUDE_DIR protobuf::libprotobuf INTERFACE_INCLUDE_DIRECTORIES)
49-
get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc IMPORTED_LOCATION_RELEASE)
48+
if (NOT Protobuf_INCLUDE_DIR)
49+
get_target_property(Protobuf_INCLUDE_DIR protobuf::libprotobuf INTERFACE_INCLUDE_DIRECTORIES)
50+
endif()
51+
if (NOT Protobuf_PROTOC_EXECUTABLE)
52+
get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc IMPORTED_LOCATION_RELEASE)
53+
set(PROTOBUF_DEPENDS protobuf::protoc)
54+
endif()
5055

5156
if (NOT Protobuf_PROTOC_EXECUTABLE)
5257
message(FATAL_ERROR "Protobuf_PROTOC_EXECUTABLE is empty")
@@ -78,7 +83,7 @@ function(compile_proto_to_cpp PROTO_LIBRARY_NAME PB_H PB_CC PROTO)
7883
COMMAND ${GEN_COMMAND}
7984
ARGS -I${PROJECT_SOURCE_DIR}/src -I${GEN_ARGS} --cpp_out=${SCHEMA_OUT_DIR} ${PROTO_ABS}
8085
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
81-
DEPENDS protobuf::protoc
86+
DEPENDS ${PROTOBUF_DEPENDS}
8287
VERBATIM
8388
)
8489

0 commit comments

Comments
 (0)