我的cmake配置没有生成任何protobuf src和头文件. 我已经检查过是否可以找到原型文件. Cmakelists.txtcmake_minimum_required(VERSION 3.0.2)..include(FindProtobuf REQUIRED)file(GLOB PROTO_DEF "${CMAKE_CURRENT_SOURCE_DI
我已经检查过是否可以找到原型文件.
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})
我已经检查了FindProtobuf.cmake和中途:
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()
您可以看到我添加了4条消息命令,脚本到达此点并且变量显示良好的值.
proto文件确实对库有依赖性,因此命令应该执行!
关于这个问题的任何想法?
更新
用add替换add_custom_command
EXEC_PROGRAM(${PROTOBUF_PROTOC_EXECUTABLE} ARGS --cpp_out ${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${ABS_FIL}
确实生成源文件和头文件,我必须手动激活custom_commmands吗?
关心奥克
在编译期间会触发add_custom_command(对于我的项目).添加
SET_SOURCE_FILES_PROPERTIES(${PROTO_SRC} ${PROTO_INCL} PROPERTIES GENERATED TRUE)
提供将生成文件的cmake信息.