1

I have a project with a structure like:

Project_Root:

- CMakeLists.txt
- src
    * src_file.cpp
    * CMakeLists.txt
- proto
    * proto_file.proto
    * CMakeLists.txt

I am having problems compiling the proto files.

    Error: PROTOBUF_GENERATE_CPP() called without any proto files

The CMakeLists.txtx file in the "proto" folder has a structure like:

    find_package( Protobuf REQUIRED ) 
    include_directories(${PROTOBUF_INCLUDE_DIR})
    include_directories( ${CMAKE_CURRENT_BINARY_DIR} )

    protobuf_generate_cpp(
    PROTO_SRCS
    PROTO_HDRS
    proto_file.proto )

    add_library( proto_lib} 
     ${PROTO_SRCS} 
     ${PROTO_HDRS} )

    target_link_libraries( proto_lib } 
      ${EXTRA_LIBS} 
      )

Any ideas?

Thanks in advance.

user1835630
  • 251
  • 2
  • 6
  • 17
  • Which version of cmake are you using? Could you be experiencing [this bug](http://www.cmake.org/Bug/view.php?id=10997)? – Erik Gillespie Jul 01 '14 at 16:48
  • Thanks. I am using version 2.8.12.2. I don't think it is due to that bug because the files .proto are in the same directory as the CMakeLists file which is supposed to compile them. – user1835630 Jul 01 '14 at 16:55
  • Sorry if this sounds like an ignorant question, but are PROTO_SRCS and PROTO_HDRS defined properly as lists? – Erik Gillespie Jul 01 '14 at 17:01
  • I did not define them as lists because, as far as I understood from the few examples I found, the call does not ask for the values of PROTO_SRCS and PROTO_HDRS. But it is the first time I am using cmake, so I could be deeply wrong. However, I had the doubt at some point and tried to give them values and I was getting an error like "incorrect arguments for the function.. ". – user1835630 Jul 01 '14 at 17:51
  • Try changing `proto_file.proto` to `proto/proto_file.proto` in the `protobuf_generate_cpp` call. – Fraser Jul 01 '14 at 17:53
  • Just tried.. it didn't work. I also tried: `file(GLOB PROTO_SRC_FILE "${CMAKE_CURRENT_SOURCE_DIR}/*.proto")` using then `PROTO_SRC_FILE` in the `protobuf_generate_cpp` , but nothing.. – user1835630 Jul 01 '14 at 18:06
  • How do you include proto/CMakeLists.txt in the top level one? Is it using `include` or `add_subdirectory`? – Fraser Jul 01 '14 at 22:00
  • Ok, it seems I overcame that problem. I do not understand exactly why, but when I added the `OUTPATH` to the `protobuf_generate_cpp`, the error disappeared. Still, I can not generate the relative proto files. I put the folder "proto" in "src" and tried what proposed here [http://stackoverflow.com/questions/19343018/cmake-and-findprotobuf] but nothing.. – user1835630 Jul 02 '14 at 12:52

1 Answers1

1

Try something like this:

SET(args 
   PROTOFILES proto_file.proto 
   OUTPATH ${CMAKE_CURRENT_SOURCE_DIR}
)
protobuf_generate_cpp(
PROTO_SRCS
PROTO_HDRS
${args})
Markus
  • 3,225
  • 6
  • 35
  • 47
Xavi Gonzalvo
  • 149
  • 1
  • 3