I tries to use FOREACH to generated several pb files. And make two list names PROTO_SRCS & PROTO_HDRS like below.
I can use it in the main CMakeLists. Like add_executable(a SHARED ${PROTO_SRCS} main.cpp).
But I can not use this param in subdirectories to make a library. when I type “cmake ..” in main CMakelists build dir. It shown that “Cannot find source file: a.pb.cc”.

main CMakeLists.txt

add_library(xxx SHARED ${PROTO_SRCS})
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/src/back back)

in src/back CMakeLists.txt

add_executable(yyy ${PROTO_SRCS})

and I can use message to show ${PROTO_SRCS} in subdir so it pass into successfully.

Please help me to point out the problem. Thx a lot