Skip to content

Commit ee7ce20

Browse files
author
Garrett Brown
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.
1 parent c8e278d commit ee7ce20

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
@@ -46,8 +46,13 @@ function(add_flag flag)
4646
endfunction()
4747

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

5257
if (NOT Protobuf_PROTOC_EXECUTABLE)
5358
message(FATAL_ERROR "Protobuf_PROTOC_EXECUTABLE is empty")
@@ -73,7 +78,7 @@ function(compile_proto_to_cpp PB_H PB_CC PROTO)
7378
COMMAND ${GEN_COMMAND}
7479
ARGS -I${PROJECT_SOURCE_DIR}/core -I${GEN_ARGS} -I${CMAKE_CURRENT_SOURCE_DIR} --cpp_out=${SCHEMA_OUT_DIR} ${PROTO_ABS}
7580
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
76-
DEPENDS protobuf::protoc
81+
DEPENDS ${PROTOBUF_DEPENDS}
7782
VERBATIM
7883
)
7984

0 commit comments

Comments
 (0)