MantisBT - CMake
View Issue Details
0010997CMakeModulespublic2010-07-15 17:112011-11-11 10:45
bcmpinc 
Philip Lowman 
normalminoralways
closedfixed 
CMake-2-8 
CMake 2.8.5CMake 2.8.5 
0010997: PROTOBUF_GENERATE_CPP returns wrong path.
The PROTOBUF_GENERATE_CPP returns the wrong paths when the *.proto file is not in the same directory as the CMakeLists.txt.

Steps to reproduce:
- Create a CMakeLists.txt file in /tmp containing:
CMAKE_MINIMUM_REQUIRED(VERSION 2.8)
FIND_PACKAGE(Protobuf)
PROTOBUF_GENERATE_CPP(src h sub/dir/file.proto)
MESSAGE("Generated file: ${src}")
ADD_EXECUTABLE(test ${src})
- Create an empty file at /tmp/sub/dir/file.proto
- cd to /tmp and run 'cmake .'
- Run 'make'

Actual result:
CMake prints 'Generated file: /tmp/file.pb.cc', however
Protoc creates the file /tmp/sub/dir/file.pb.cc

Expected result:
CMake prints 'Generated file: /tmp/sub/dir/file.pb.cc'
Protoc creates the file /tmp/sub/dir/file.pb.cc
No tags attached.
patch FindProtobuf_subdirs.patch (507) 2010-07-20 17:01
https://public.kitware.com/Bug/file/3254/FindProtobuf_subdirs.patch
? FindProtobuf.cmake (5,329) 2011-05-26 00:07
https://public.kitware.com/Bug/file/3898/FindProtobuf.cmake
Issue History
2010-07-15 17:11bcmpincNew Issue
2010-07-20 17:01bcmpincFile Added: FindProtobuf_subdirs.patch
2010-07-20 17:02bcmpincNote Added: 0021433
2010-08-19 08:13Philip LowmanStatusnew => assigned
2010-08-19 08:13Philip LowmanAssigned To => Philip Lowman
2011-05-25 22:46Philip LowmanNote Added: 0026604
2011-05-25 22:46Philip LowmanStatusassigned => resolved
2011-05-25 22:46Philip LowmanResolutionopen => fixed
2011-05-25 22:46Philip LowmanFixed in Version => CMake 2.8.5
2011-05-25 22:46Philip LowmanTarget Version => CMake 2.8.5
2011-05-26 00:05Philip LowmanNote Added: 0026605
2011-05-26 00:05Philip LowmanStatusresolved => feedback
2011-05-26 00:05Philip LowmanResolutionfixed => reopened
2011-05-26 00:07Philip LowmanFile Added: FindProtobuf.cmake
2011-05-26 00:10Philip LowmanNote Added: 0026606
2011-05-26 00:10Philip LowmanStatusfeedback => confirmed
2011-05-26 00:10Philip LowmanResolutionreopened => open
2011-05-26 00:10Philip LowmanFixed in VersionCMake 2.8.5 =>
2011-06-07 01:20Philip LowmanNote Added: 0026732
2011-06-07 01:20Philip LowmanStatusconfirmed => resolved
2011-06-07 01:20Philip LowmanResolutionopen => fixed
2011-06-07 01:20Philip LowmanFixed in Version => CMake 2.8.5
2011-11-11 10:45David ColeNote Added: 0027761
2011-11-11 10:45David ColeStatusresolved => closed

Notes
(0021433)
bcmpinc   
2010-07-20 17:02   
I've added a patch that fixes this bug.
(0026604)
Philip Lowman   
2011-05-25 22:46   
Thanks for the patch. Your fix will be in 2.8.5 RC02
(0026605)
Philip Lowman   
2011-05-26 00:05   
Unfortunately, the fix doesn't appear to work when using the include directive.
Example:

<subdir/Person.proto>:
message Person {
  required int32 id = 1;
}

<subdir/SmallGroup.proto>:
import "Person.proto";
message SmallGroup {
    repeated Person grp = 1;
}

<person_exec.cc>:
#include <iostream>
#include "Person.pb.h"
int main() {
    Person p;
    p.set_id(15);
    return 0;
}

<CMakeLists.txt>:
project(foo)
cmake_minimum_required(VERSION 2.6)
find_package(Protobuf)
include_directories(${PROTOBUF_INCLUDE_DIRS})
include_directories(${CMAKE_CURRENT_BINARY_DIR})
PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS subdir/Person.proto subdir/SmallGroup.proto)

add_executable(person person_exec.cc ${PROTO_SRCS} ${PROTO_HDRS})
target_link_libraries(person ${PROTOBUF_LIBRARIES})

if(UNIX)
  target_link_libraries(person pthread)
endif()



<OUTPUT>:
lowman@lowman-desktop:~/cmaketests/proto/build$ make
[ 20%] Running C++ protocol buffer compiler on subdir/SmallGroup.proto
[ 40%] Running C++ protocol buffer compiler on subdir/Person.proto
[ 60%] Building CXX object CMakeFiles/person.dir/person_exec.cc.o
[ 80%] Building CXX object CMakeFiles/person.dir/subdir/Person.pb.cc.o
[100%] Building CXX object CMakeFiles/person.dir/subdir/SmallGroup.pb.cc.o
/home/lowman/cmaketests/proto/build/subdir/SmallGroup.pb.cc: In function ‘void protobuf_AddDesc_subdir_2fSmallGroup_2eproto()’:
/home/lowman/cmaketests/proto/build/subdir/SmallGroup.pb.cc:72: error: ‘::protobuf_AddDesc_Person_2eproto’ has not been declared
make[2]: *** [CMakeFiles/person.dir/subdir/SmallGroup.pb.cc.o] Error 1
make[1]: *** [CMakeFiles/person.dir/all] Error 2
make: *** [all] Error 2
(0026606)
Philip Lowman   
2011-05-26 00:10   
What do you think about the attached version? I've made it so -I with the directory is passed for each proto file included in the macro. This appears to resolve this issue, as well as 11148 (specifying proto files outside of project directory).
(0026732)
Philip Lowman   
2011-06-07 01:20   
Merge topic '10997_PROTOBDUF_GENERATE_CPP_returns_wrong_path' into next

Allow proto files outside of the current source directory to be compiled in the PROTOBUF_GENERATE_CPP module. This is accomplished by using the -I flag for each path where proto files are being compiled.
(0027761)
David Cole   
2011-11-11 10:45   
Closing resolved issues that have not been updated in more than 4 months.