Skip to content

Commit

Permalink
Fix CMake proto_path
Browse files Browse the repository at this point in the history
  • Loading branch information
Mizux committed Apr 19, 2018
1 parent 230835a commit 9e07fd6
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cmake/cpp.cmake
Expand Up @@ -100,6 +100,15 @@ add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
set(PROTO_HDRS)
set(PROTO_SRCS)
file(GLOB_RECURSE proto_files RELATIVE ${PROJECT_SOURCE_DIR} "ortools/*.proto")

# Get Protobuf include dir
get_target_property(protobuf_dirs protobuf::libprotobuf INTERFACE_INCLUDE_DIRECTORIES)
foreach(dir ${protobuf_dirs})
if ("${dir}" MATCHES "BUILD_INTERFACE")
list(APPEND PROTO_DIRS "--proto_path=${dir}")
endif()
endforeach()

foreach (PROTO_FILE ${proto_files})
#message(STATUS "protoc proto(cc): ${PROTO_FILE}")
get_filename_component(PROTO_DIR ${PROTO_FILE} DIRECTORY)
Expand All @@ -112,6 +121,7 @@ foreach (PROTO_FILE ${proto_files})
OUTPUT ${PROTO_SRC} ${PROTO_HDR}
COMMAND protobuf::protoc
"--proto_path=${PROJECT_SOURCE_DIR}"
"${PROTO_DIRS}"
"--cpp_out=${PROJECT_BINARY_DIR}"
${PROTO_FILE}
DEPENDS ${PROTO_FILE} protobuf::protoc
Expand Down

0 comments on commit 9e07fd6

Please sign in to comment.