My cmake configuration does not generate protobuf src and header files. I already checked if 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 checked FindProtobuf.cmake and halfway 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 that I added 4 message commands, the script reaches this point, and the variables show good values. Proto files matter to the library, so the command must be executed !?
Any ideas on this issue?
Update
replacing add_custom_command with
EXEC_PROGRAM(${PROTOBUF_PROTOC_EXECUTABLE} ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${ABS_FIL}
creates source and header files, do I have to manually activate custom_commmands?
Regards Auke
source share