I am trying to compile a .proto file on Windows using CMake (version 3.23.1). To this aim, I am using documentations that can be found here and here. But at the end, the .cc
and .h
files are not generated. Here is my CMakeLists.txt file:
project(test_proto)
cmake_minimum_required(VERSION 3.23)
set(Protobuf_DIR "C:/grpc/debug/cmake")
set(gRPC_DIR "C:/grpc/debug/lib/cmake/grpc")
set(ZLIB_ROOT "C:/zlib/debug")
set(c-ares_DIR "C:/grpc/debug/lib/cmake/c-ares")
find_package(Protobuf CONFIG REQUIRED)
find_package(gRPC CONFIG REQUIRED)
set(PROTO_FILES ${CMAKE_CURRENT_SOURCE_DIR}/proto/server.proto)
add_library(test_proto ${PROTO_FILES})
target_link_libraries(test_proto
PUBLIC protobuf::libprotobuf
PUBLIC gRPC::grpc
PUBLIC gRPC::grpc++
)
set(PROTO_BINARY_DIR "${CMAKE_CURRENT_SOURCE_DIR}/tmp")
set(PROTO_IMPORT_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/proto")
get_target_property(grpc_cpp_plugin_location gRPC::grpc_cpp_plugin LOCATION)
message(STATUS " The value of grpc cpp location is: ${grpc_cpp_plugin_location}")
protobuf_generate(
TARGET test_proto
LANGUAGE cpp
OUT_VAR PROTO_GENERATED_FILES
IMPORT_DIRS ${PROTO_IMPORT_DIRS}
PROTOC_OUT_DIR "${PROTO_BINARY_DIR}")
protobuf_generate(
TARGET test_proto
OUT_VAR PROTO_GENERATED_FILES
LANGUAGE grpc
GENERATE_EXTENSIONS .grpc.pb.h .grpc.pb.cc
PLUGIN "protoc-gen-grpc=${grpc_cpp_plugin_location}"
IMPORT_DIRS ${PROTO_IMPORT_DIRS}
PROTOC_OUT_DIR "${PROTO_BINARY_DIR}")
message(STATUS " The generated files are located in: ${PROTO_GENERATED_FILES}")
After running the above CMake file using this command:
cmake.exe -D CMAKE_BUILD_TYPE=Debug -G "Visual Studio 16 2019" -S D:\cmake-test -B D:\cmake-test
I am getting this output:
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19042.
-- The C compiler identification is MSVC 19.29.30137.0
-- The CXX compiler identification is MSVC 19.29.30137.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: c:/VS/MVS16117/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: c:/VS/MVS16117/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found ZLIB: C:/zlib/debug/lib/zlibd.lib (found version "1.2.11")
-- Found OpenSSL: optimized;C:/Program Files/OpenSSL-Win64/lib/VC/libcrypto64MD.lib;debug;C:/Program Files/OpenSSL-Win64/lib/VC/libcrypto64MDd.lib (found version "3.0.3")
-- The value of grpc cpp location is: C:/grpc/debug/bin/grpc_cpp_plugin.exe
-- The generated files are located in: D:/cmake-test/tmp/proto/server.grpc.pb.h;D:/cmake-test/tmp/proto/server.grpc.pb.cc;D:/cmake-test/tmp/proto/serverPLUGIN;D:/cmake-test/tmp/proto/serverprotoc-gen-grpc=C:/data/tools/grpc/v1.15.1-2/win64/release/bin/grpc_cpp_plugin.exe
-- Configuring done
-- Generating done
-- Build files have been written to: D:/cmake-test
without any errors. But the .h and .cc files are not generated. Any ideas?
The main issue of my problem was related to having an old version of gRPC. By migrating to a new version (v1.56.0), everything is working as expected.
In addition, as mentioned in the comments, the generated files are created at build time. For more info check here.