티스토리 뷰

한국어는 아래에 있습니다.

I covered "How to generate protobuf code(except Service) with CMake and prtoto buffer compiler(protoc) 

This post is going to cover generate gRPC service code. So, You have to read previous post to understand 

what this post's code exactly indicates(If you are not accustomed to CMake).

https://4whomtbts.tistory.com/75

 

[CMake,ENG/KOR] compile protobuf with CMake

한글은 아래에 있습니다. This post deals with "How to trigger protoc with your CMake". I struggled to trigger my protoc with my CMake, I refered to some projects's CMake files that are expected to us..

4whomtbts.tistory.com

Prerequisites 

You have to have "grpc_cpp_plugin", and gRPC, protoc 

grpc_cpp_plugin

foreach(__proto_file ${_all_proto_files})
    execute_process(COMMAND protoc -I=${proto_dir}
            --grpc_out=${proto_gen_dir}
            --cpp_out=${proto_gen_dir}
            --plugin=protoc-gen-grpc=/usr/local/bin/grpc_cpp_plugin
            ${__proto_file}
            WORKING_DIRECTORY ${proto_dir})
endforeach(__proto_file)

That's all. (__proto_file, __all_proto_files, proto_gen_dir and proto_dir depend on you.) 

Differences between this with previous source code are "--grpc_out=${proto_gen_dir} and

--plugin=protoc-gen-grpc=/usr/local/bin/grpc_cpp_plugin" 

--grpc_out : literally indicates where byproducts are supposed to be placed.

--plugin=protoc-gen-grpc=/usr/local/bin/grpc_cpp_plugin  : This specifies plugin(In this case, grpc_cpp_plugin) 

RESULT

한국어

이번에는 proto buffer에서 gRPC에서 사용할 service code를 만들어보겠습니다.

https://4whomtbts.tistory.com/75

 

 

준비물

grpc_cpp_plugin과 gRPC, protoc가 필요합니다. 아래 경로에서 확인해보세요

grpc_cpp_plugin

저번 포스팅에서는 CMake랑 protoc를 이용해서 protobuf c++ 코드를 만들었습니다.

foreach(__proto_file ${_all_proto_files})
    execute_process(COMMAND protoc -I=${proto_dir}
            --grpc_out=${proto_gen_dir}
            --cpp_out=${proto_gen_dir}
            --plugin=protoc-gen-grpc=/usr/local/bin/grpc_cpp_plugin
            ${__proto_file}
            WORKING_DIRECTORY ${proto_dir})
endforeach(__proto_file)

끝입니다.

저번 포스팅이랑 달라진건 

 "--grpc_out=${proto_gen_dir} and --plugin=protoc-gen-grpc=/usr/local/bin/grpc_cpp_plugin" 

--grpc_out 는 만들어진 소스코드들이 들어갈 경로입니다.

--plugin=protoc-gen-grpc=/usr/local/bin/grpc_cpp_plugin : 무슨 플러그인을 사용할지 명시합니다.

결과

'cmake' 카테고리의 다른 글

[CMake, ENG] Let's use "FUNCTION" in CMake  (0) 2019.12.27
[CMake,ENG/KOR] compile protobuf with CMake  (0) 2019.12.24
[CMake, KOR] get_filename_component  (0) 2019.12.23
[CMake, KOR] foreach - 1  (0) 2019.12.23
[CMake,KOR] LIST  (0) 2019.12.23
댓글