FindProtobuf need add dir of /path/to/libprotoc.so to LD_LIBRARY_PATH, in case of use specified Protobuf which is not installed globaly.
set(CMAKE_PREFIX_PATH ${THIRD_PARTY_DIR})
find_package(Protobuf)
...
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${ProtoFiles})
will get error as follows:
../build/3rdparty/bin/protoc: error while loading shared libraries: libprotoc.so.15: cannot open shared object file: No such file or directory
then I modify Modules/FindProtobuf.cmake from
add_custom_command(
OUTPUT ${_generated_srcs}
COMMAND protobuf::protoc
ARGS --${protobuf_generate_LANGUAGE}_out ${_dll_export_decl}${protobuf_generate_PROTOC_OUT_DIR} ${_dll_desc_out} ${_protobuf_include_path} ${_abs_file}
DEPENDS ${_abs_file} protobuf::protoc
COMMENT "Running ${protobuf_generate_LANGUAGE} protocol buffer compiler on ${_proto}"
VERBATIM )
TO
add_custom_command(
OUTPUT ${_generated_srcs}
# Only Next Line Changed
COMMAND ${CMAKE_COMMAND} -E env "LD_LIBRARY_PATH=${Protobuf_INCLUDE_DIR}/../lib" ${Protobuf_PROTOC_EXECUTABLE}
ARGS --${protobuf_generate_LANGUAGE}_out ${_dll_export_decl}${protobuf_generate_PROTOC_OUT_DIR} ${_dll_desc_out} ${_protobuf_include_path} ${_abs_file}
DEPENDS ${_abs_file} protobuf::protoc
COMMENT "Running ${protobuf_generate_LANGUAGE} protocol buffer compiler on ${_proto}"
VERBATIM )
Now I can build successfully. My change only considered Linux, May be it is better to make this improvement at officially way.