>My question now is how I should include these gRPC-generated files? I tried including them as LIBRARIES_TO_LINK, but I would get undefined references to the gRPC-generated interface classes.
># hw_grpc_proto
>add_library(hw_grpc_proto # this is a cmake target
> ${hw_grpc_srcs}
> ${hw_grpc_hdrs}
> ${hw_proto_srcs}
> ${hw_proto_hdrs}
>)
>...
>#grpc libs
>list (APPEND link_libs
> ${hw_grpc_proto} # this is you trying to dereference a variable with the cmake target, should be empty
> absl::flags
> absl::flags_parse
> ${_REFLECTION}
> ${_GRPC_GRPCPP}
> ${_PROTOBUF_LIBPROTOBUF}
> )
Try removing the ${} wrapping hw_grpc_proto in linked libs and it should work.
>I also tried including them as header and source files, but I don't think that should be the way. And the cmake would just lose sight of their dependencies anyway and give me complaints about the included header not existing.
It should work. However you need to establish the dependency chain.
In your first example you clearly had a complete chain.
xhaul depends on hw_grpc_proto (remember to remove the ${})
hw_grpc_proto depends on ${hw_grpc_srcs} ${hw_grpc_hdrs} ${hw_proto_srcs} ${hw_proto_hdrs}, which are outputs from the add_custom_command
add_custom_command outputs depend on ${hw_proto}, which is a file that when altered, will trigger the custom command
If you want to add the grpc_srcs and grpc_hdrs directly to the xhaul library, you will need to set the dependencies manually to make its intermediate object library depend on these output files.
set_target_properties(${libxhaul-obj} PROPERTIES OBJECT_DEPENDS "${hw_grpc_srcs};${hw_grpc_hdrs};${hw_proto_srcs};${hw_proto_hdrs}")
If you are working with Xcode, we don't explicitly declare the object libraries, so try adding the dependencies directly to the shared library target.
set_target_properties(${libxhaul} PROPERTIES OBJECT_DEPENDS "${hw_grpc_srcs};${hw_grpc_hdrs};${hw_proto_srcs};${hw_proto_hdrs}")