Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PROTOBUF_GENERATE_CPP not generating src and header files

My cmake configuration is not generating any protobuf src and header files. I've already checked if the proto files can be found.

Cmakelists.txt

cmake_minimum_required(VERSION 3.0.2)
..
include(FindProtobuf REQUIRED)
file(GLOB PROTO_DEF "${CMAKE_CURRENT_SOURCE_DIR}/protobuf/*/*.proto")

foreach(file ${PROTO_DEF})    
    if(EXISTS ${file})
        MESSAGE("YES")
    else()
        MESSAGE("NO")
    endif()
endforeach()
SET(PROTOBUF_GENERATE_CPP_APPEND_PATH PROTOBUF)
SET(PROTOBUF_PROTOC_EXECUTABLE protoc.exe)

..
PROTOBUF_GENERATE_CPP(PROTO_SRC PROTO_INCL ${PROTO_DEF})
..
add_library(${PROJECT_NAME} STATIC ${INCLUDES} ${INTERNAL_INCLUDES} ${SRC} ${PROTO_SRC} ${PROTO_INCL})
target_link_libraries(${PROJECT_NAME} ${PROTOBUF_LIBRARIES})

I have checked the FindProtobuf.cmake and half way through:

foreach(FIL ${ARGN})
    get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
    get_filename_component(FIL_WE ${FIL} NAME_WE)

    list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc")
    list(APPEND ${HDRS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h")
    
    MESSAGE(1 ${CMAKE_CURRENT_BINARY_DIR})
    MESSAGE(2 ${_protobuf_include_path})
    MESSAGE(3 ${ABS_FIL})
    MESSAGE(4 ${PROTOBUF_PROTOC_EXECUTABLE})
    
    add_custom_command(
      OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc"
             "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h"
      COMMAND  ${PROTOBUF_PROTOC_EXECUTABLE}
      ARGS --cpp_out  ${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${ABS_FIL}
      DEPENDS ${ABS_FIL}
      COMMENT "Running C++ protocol buffer compiler on ${FIL}"
      VERBATIM )
      
  endforeach()

You can see i've added the 4 message commands, the script reaches this point and variables show good values. The proto files do have a depencency to the library, thus the command should get executed !?

Any ideas on this problem?

update

replacing the add_custom_command with

EXEC_PROGRAM(${PROTOBUF_PROTOC_EXECUTABLE} ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${ABS_FIL}

does generate the source and header files, must i manually activate the custom_commmands?

Regards Auke

like image 826
user1875444 Avatar asked Mar 30 '15 12:03

user1875444


2 Answers

The add_custom_command is fired (for my project) during compilation time. Adding

SET_SOURCE_FILES_PROPERTIES(${PROTO_SRC} ${PROTO_INCL} PROPERTIES GENERATED TRUE)

gives cmake info that the files will be generated.

like image 196
user1875444 Avatar answered Oct 19 '22 23:10

user1875444


Alternative if you have an external proto folder:

file(GLOB PROTOBUF_FILELIST ${PROTO_INCLUDE_DIR}/*.proto)
foreach( proto_file ${PROTOBUF_FILELIST} )
   get_filename_component(proto_name ${proto_file} NAME_WE)
   get_filename_component(proto_path ${PROTO_INCLUDE_DIR} ABSOLUTE)
   set_source_files_properties("${proto_path}/${proto_name}.pb.cc"
                               "${proto_path}/${proto_name}.pb.h"
                               PROPERTIES GENERATED TRUE)
endforeach()
like image 23
TheoretiCAL Avatar answered Oct 19 '22 23:10

TheoretiCAL