1

I have a gRPC 1.23.0 compiled by conan(and all dependencies also resolved by conan). And I have a CMake project, that use grpc library:

set (LIB_DEPS
  protobuf::libprotobuf
  gRPC::grpc++
)
target_link_libraries(${PROJECT_NAME} PUBLIC ${LIB_DEPS})

When I generate a VS project from this CMakeLists.txt in Linker - Input - Addition Dependencies property, I have there next value:

C:\.conan\data\protobuf\3.9.1\kpa_conan\stable\package\b786e9ece960c3a76378ca4d5b0d0e922f4cedc1\lib\libprotobufd.lib <-- (1)
C:\.conan\data\grpc\1.23.0\kpa_conan\stable\package\d85cccdf40588ac852bd1445d45838487543194f\lib\grpc++.lib
libprotocd.lib   <-- (2)
libprotobufd.lib  <-- (3)
C:\.conan\data\grpc\1.23.0\kpa_conan\stable\package\d85cccdf40588ac852bd1445d45838487543194f\lib\grpc.lib
C:\.conan\data\grpc\1.23.0\kpa_conan\stable\package\d85cccdf40588ac852bd1445d45838487543194f\lib\gpr.lib
C:\.conan\data\c-ares\1.15.0\kpa_conan\stable\package\b786e9ece960c3a76378ca4d5b0d0e922f4cedc1\lib\cares.lib
C:\.conan\data\grpc\1.23.0\kpa_conan\stable\package\d85cccdf40588ac852bd1445d45838487543194f\lib\address_sorting.lib
wsock32.lib
kernel32.lib

(1) - expected valid path, that I add in CMakeLists.txt

(2),(3) - unexpected and invalid path, that added by gRPC::grpc++ in CMakeLists.txt. If I change gRPC::grpc++ to gRPC::grpc, lines (2) and (3) will disappear, but path to grpc++.lib will disappear too, but I need it.

How to avoid this strange invalid path to libprotocd.lib and libprotobufd.lib?

hdnn
  • 1,807
  • 3
  • 13
  • 20

2 Answers2

2

To properly link against grpc targets you can use:

target_link_libraries(${PROJECT_NAME} PUBLIC CONAN_PKG::grpc)

This should contain everything required. More details on this approach here: https://docs.conan.io/en/latest/integrations/build_system/cmake/cmake_generator.html#targets-approach

ymochurad
  • 941
  • 7
  • 15
0

I have found workaround solution:

find_library(GRPC_GRPC++_LIBRARY NAMES grpc++)
set (LIB_DEPS
  protobuf::libprotobuf
  gRPC::grpc
  ${GRPC_GRPC++_LIBRARY NAMES}
)
target_link_libraries(${PROJECT_NAME} PUBLIC ${LIB_DEPS})

And opened the issue about it in gRPC repository: https://github.com/grpc/grpc/issues/20578

hdnn
  • 1,807
  • 3
  • 13
  • 20
  • Did you try to just do `target_link_libraries(${PROJECT_NAME} PUBLIC ${CONAN_PKG::grpc})`? – ymochurad Oct 24 '19 at 20:38
  • ```Syntax error in cmake code at CMakeLists.txt:66 when parsing string ${CONAN_PKG::grpc} Invalid character (':') in a variable name: 'CONAN_PKG'``` – hdnn Oct 25 '19 at 12:55
  • 1
    Sorry I made a typo there. The command should be like: `target_link_libraries(${PROJECT_NAME} PUBLIC CONAN_PKG::grpc)`. Without the curly braces. More details on this approach here: https://docs.conan.io/en/latest/integrations/build_system/cmake/cmake_generator.html#targets-approach – ymochurad Oct 25 '19 at 13:14