Directory:
|test
--|build
--|msg
--|proto
----|test.poto
--|CMakeLists.txt
--|test.bat
this is my CMakeLists.txt
cmake_minimum_required(VERSION 3.0.0)
project(test)
message(STATUS "source path: ${PROJECT_SOURCE_DIR}")
file(GLOB PROTO_FILE proto/*.proto)
if(NOT WIN32)
message("if NOT WIN32")
message("NOT WIN32 ${PROTO_FILE}---------------")
find_package(Protobuf REQUIRED)
SET_SOURCE_FILES_PROPERTIES(${PROTO_SRC} ${PROTO_INCL} PROPERTIES GENERATED TRUE)
#include_directories(${Protobuf_INCLUDE_DIRS})
#include_directories(${CMAKE_CURRENT_BINARY_DIR})
# PROTOBUF_GENERATE_CPP(PROTO_SRCS PROTO_HDRS ${PROTO_FILE})
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ./proto/test.proto)
else(NOT WIN32)
message("else NOT WIN32 ${PROTO_FILE}---------------")
foreach(proto ${PROTO_FILE})
execute_process(
COMMAND protoc --cpp_out=./ --proto_path=${CMAKE_CURRENT_SOURCE_DIR} ${proto}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
endforeach()
# message("else NOT WIN32 ${PROTO_FILE}---------------")
# execute_process(
# COMMAND cmd /c "test.bat"
# WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
# RESULT_VARIABLE CMD_RESULT
# )
# if (CMD_RESULT EQUAL 0)
# message("Script executed successfully.")
# else()
# message("Script execution failed with error code: ${CMD_RESULT}")
# endif()
endif()
in buid i excute cmake … output:
-- source path: /data/cmake
if NOT WIN32
NOT WIN32 /data/cmake/proto/test.proto---------------
-- Configuring done
-- Generating done
-- Build files have been written to: /data/cmake/build
but it does not generating src and header files i try like:add a line SET_SOURCE_FILES_PROPERTIES(${PROTO_SRC} ${PROTO_INCL} PROPERTIES GENERATED TRUE) not work
But i excute protoc -I ./ *.proto --cpp_out=./ in proto it succ,so i wanna know why PROTOBUF_GENERATE_CPP not generating src and header files
trys:
add a line
SET_SOURCE_FILES_PROPERTIES(${PROTO_SRC} ${PROTO_INCL} PROPERTIES GENERATED TRUE)
not work
i see this:
PROTOBUF_GENERATE_CPP not generating src and header files
cmake protobuf_generate_cpp not invoking protoc wants:
PROTOBUF_GENERATE_CPP generate src and header files