protobuf and .proto with multiple extensions (+patch proposal)
Hello,
the following does not work :
protobuf_generate_cpp(PROTO_SRCS PROTO_HRDS PROTO_PATH ${CMAKE_SOURCE_DIR} service.requests.proto)
add_library(proto STATIC ${PROTO_SRCS} ${PROTO_HRDS})
target_include_directories(proto PUBLIC ${CMAKE_BINARY_DIR})
target_link_libraries(proto PUBLIC protobuf::libprotobuf)
as FindProtobuf.cmake will use
get_filename_component(FIL_WE ${FIL} NAME_WE)
to extract the name without extension which in that case will return "service" instead of "service.requests".
protoc will generate files service.requests.pb.cc and service.requests.pb.h while PROTO_SRCS will contain service.pb.cc and PROTO_HRDS will contain service.pb.h
The following patch will resolve the issue
$ diff -bup cmake-3.10/Modules/FindProtobuf.cmake.orig cmake-3.10/Modules/FindProtobuf.cmake
--- cmake-3.10/Modules/FindProtobuf.cmake.orig 2018-08-29 09:04:57.119432067 +0100
+++ cmake-3.10/Modules/FindProtobuf.cmake 2018-09-05 10:42:24.054659476 +0100
@@ -168,7 +168,11 @@ function(PROTOBUF_GENERATE_CPP SRCS HDRS
foreach(FIL ${PROTO_FILES})
get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
- get_filename_component(FIL_WE ${FIL} NAME_WE)
+ #get_filename_component(FIL_WE ${FIL} NAME_WE)
+ # NAME_WE is longest extension, we want shortest extension, so need to recode it
+ get_filename_component(FIL_NAME ${FIL} NAME)
+ string(REGEX REPLACE "\\.[^.]*$" "" FIL_NAME_WE ${FIL_NAME})
+ set(FIL_WE "${FIL_NAME_WE}")
if(NOT PROTOBUF_GENERATE_CPP_APPEND_PATH)
get_filename_component(FIL_DIR ${FIL} DIRECTORY)
if(FIL_DIR)