<div dir="ltr">Hi all,<div><br></div><div>I've been fighting against this error for the last two hours.</div><div><br></div><div>When I try to setup a cmake-based project which builds some protobuf related stuff, something strange happens.</div>
<div><br></div><div>My sample cmake directives follow:</div><div><br></div><div>================================</div><div><div><font face="courier new, monospace" size="1">find_package(Protobuf REQUIRED)</font></div><div>
<font face="courier new, monospace" size="1"><br></font></div><div><font face="courier new, monospace" size="1">include_directories(${PROTOBUF_INCLUDE_DIRS})</font></div><div><font face="courier new, monospace" size="1"><br>
</font></div><div><font face="courier new, monospace" size="1">PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS </font></div><div><font face="courier new, monospace" size="1"> ${CMAKE_SRC_DIR}/Libraries/FileA.proto</font></div>
<div><font face="courier new, monospace" size="1"> ${CMAKE_SRC_DIR}/Libraries/FileB.proto</font></div><div><font face="courier new, monospace" size="1">)</font></div><div><font face="courier new, monospace" size="1"><br>
</font></div><div><font face="courier new, monospace" size="1">add_library(MyLibrary SHARED</font></div><div><font face="courier new, monospace" size="1"> ${PROTO_SRCS}</font></div><div><font face="courier new, monospace" size="1">)</font></div>
<div><font face="courier new, monospace" size="1"><br></font></div><div><font face="courier new, monospace" size="1">target_link_libraries(MyLibrary</font></div><div><font face="courier new, monospace" size="1"> ${PROTOBUF_LIBRARIES}</font></div>
<div><font face="courier new, monospace" size="1">)</font></div><div>================================</div></div><div><br></div><div style>When building this code, the build system was silently failing at building the pb.h and pb.cc files. I followed all the code path within the module and found that the problem is related to the _protobuf_include_path not being given any value before the PROBUF_GENERATE_CPP call, so that the row</div>
<div style><br></div><div style><font face="courier new, monospace" size="1">list(APPEND _protobuf_include_path -I ${ABS_PATH})</font><br></div><div style><font face="courier new, monospace" size="1"><br></font></div><div style>
<font face="arial, helvetica, sans-serif">translates to </font></div><div style><font face="arial, helvetica, sans-serif"><br></font></div><div style><font face="courier new, monospace" size="1">-I ;/the/path/in/abs_path </font></div>
<div style><font face="arial, helvetica, sans-serif"><br></font></div><div style><font face="arial, helvetica, sans-serif">with the semi-colon between the -I and the path. This gives rise to problems in protoc invocation.</font></div>
<div style><font face="arial, helvetica, sans-serif"><br></font></div><div style><font face="arial, helvetica, sans-serif">I solved this by introducing the following if-then-else:</font></div><div style><font face="courier new, monospace" size="1"><br>
</font></div><div style><div style="font-family:'courier new',monospace;font-size:x-small">list(LENGTH _protobuf_include_path _list_num)</div><div style="font-family:'courier new',monospace;font-size:x-small">
if(${_list_num} EQUAL 0)</div><div style="font-family:'courier new',monospace;font-size:x-small"> set(_protobuf_include_path -I ${ABS_PATH})</div><div style="font-family:'courier new',monospace;font-size:x-small">
else()</div><div style="font-family:'courier new',monospace;font-size:x-small"> list(APPEND _protobuf_include_path -I ${ABS_PATH})</div><div style="font-family:'courier new',monospace;font-size:x-small">
endif()</div><div style="font-family:'courier new',monospace;font-size:x-small"><br></div><div style><font face="arial, helvetica, sans-serif">but I'd like to understand what I'm doing wrong and why I'm seeing this.</font></div>
<div style><font face="arial, helvetica, sans-serif"><br></font></div><div style><font face="arial, helvetica, sans-serif">Thanks all!</font></div><div style><font face="arial, helvetica, sans-serif"><br></font></div><div style>
<font face="arial, helvetica, sans-serif">A.</font></div><div style="font-family:'courier new',monospace;font-size:x-small"><br></div></div><div><br></div></div>