From dc32ac5c6153a4f5a3fc966e4cc941e5bf3af234 Mon Sep 17 00:00:00 2001 From: Garrett Brown Date: Sun, 16 Feb 2020 15:39:39 -0800 Subject: [PATCH] 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) --- cmake/functions.cmake | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/cmake/functions.cmake b/cmake/functions.cmake index 6d63b14543..b2212752c7 100644 --- a/cmake/functions.cmake +++ b/cmake/functions.cmake @@ -47,8 +47,13 @@ function(add_flag flag) endfunction() function(compile_proto_to_cpp PROTO_LIBRARY_NAME PB_H PB_CC PROTO) - get_target_property(Protobuf_INCLUDE_DIR protobuf::libprotobuf INTERFACE_INCLUDE_DIRECTORIES) - get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc IMPORTED_LOCATION_RELEASE) + if (NOT Protobuf_INCLUDE_DIR) + get_target_property(Protobuf_INCLUDE_DIR protobuf::libprotobuf INTERFACE_INCLUDE_DIRECTORIES) + endif() + if (NOT Protobuf_PROTOC_EXECUTABLE) + get_target_property(Protobuf_PROTOC_EXECUTABLE protobuf::protoc IMPORTED_LOCATION_RELEASE) + set(PROTOBUF_DEPENDS protobuf::protoc) + endif() if (NOT Protobuf_PROTOC_EXECUTABLE) message(FATAL_ERROR "Protobuf_PROTOC_EXECUTABLE is empty") @@ -80,7 +85,7 @@ function(compile_proto_to_cpp PROTO_LIBRARY_NAME PB_H PB_CC PROTO) COMMAND ${GEN_COMMAND} ARGS -I${PROJECT_SOURCE_DIR}/core -I${GEN_ARGS} --cpp_out=${SCHEMA_OUT_DIR} ${PROTO_ABS} WORKING_DIRECTORY ${CMAKE_BINARY_DIR} - DEPENDS protobuf::protoc + DEPENDS ${PROTOBUF_DEPENDS} VERBATIM )