Использование FetchContent для извлечения ProtoBuf и GRPC для компиляции во время сборки (герметика)C++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Использование FetchContent для извлечения ProtoBuf и GRPC для компиляции во время сборки (герметика)

Сообщение Anonymous »

Я пытаюсь сделать автономный файл cmakelists.txt, который будет создавать/установить Protobuf/grpc. Я пишу сообщение в блоге о GRPC Stuff, и мои читатели, возможно, не захотят устанавливать ProtoBuf/GRPC, чтобы поиграть с кодом в посте. Поэтому я пытаюсь полностью использовать Cmake's FetchContent для загрузки ProTBUF и GRPC, компилировать их и использовать их для создания другого кода в проекте. (Пользователи захотят просто скопировать и пройти через cmakelists.txt без широкой установки системы библиотек.) < /P>
У меня много проблем с получением кода для компиляции. После того, как я просмотрел многие ресурсы, это то, что у меня есть сейчас: < /p>

Код: Выделить всё

cmake_minimum_required(VERSION 3.15)
project(command_server)

include(FetchContent)
FetchContent_Declare(
absl
GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git
GIT_TAG        origin/master
OVERRIDE_FIND_PACKAGE
)
FetchContent_MakeAvailable(absl)

FetchContent_Declare(Protobuf
GIT_REPOSITORY git@github.com:protocolbuffers/protobuf.git
GIT_TAG        v23.3
SOURCE_SUBDIR  cmake
OVERRIDE_FIND_PACKAGE
)
FetchContent_MakeAvailable(Protobuf)

FetchContent_Declare(
gRPC
GIT_REPOSITORY git@github.com:grpc/grpc
GIT_TAG        v1.55.1  # e.g v1.28.0
OVERRIDE_FIND_PACKAGE
)
FetchContent_MakeAvailable(gRPC)

find_package(absl REQUIRED)
FetchContent_GetProperties(Protobuf SOURCE_DIR Protobuf_SOURCE_DIR)
include(${Protobuf_SOURCE_DIR}/cmake/protobuf-generate.cmake)

add_library(proto OBJECT "${CMAKE_CURRENT_LIST_DIR}/helloworld.proto")
target_link_libraries(proto PUBLIC protobuf::libprotobuf)
set(PROTO_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated")
target_include_directories(proto PUBLIC "$")

protobuf_generate(
TARGET proto
LANGUAGE grpc
GENERATE_EXTENSIONS .grpc.pb.h .grpc.pb.cc
PLUGIN "protoc-gen-grpc=$"
IMPORT_DIRS ${PROTO_IMPORT_DIRS}
PROTOC_OUT_DIR "${PROTO_BINARY_DIR}")

add_executable(my_exe greater_server.cc)
target_link_libraries(my_exe grpc++ proto)
< /code>
Однако это извергает тонны ошибок, таких как: < /p>
CMake Warning at build/_deps/absl-src/CMakeLists.txt:77 (message):
A future Abseil release will default ABSL_PROPAGATE_CXX_STD to ON for CMake
3.8 and up.  We recommend enabling this option to ensure your project still
builds correctly.

--
-- 23.1.0
CMake Deprecation Warning at build/_deps/grpc-src/third_party/zlib/CMakeLists.txt:1 (cmake_minimum_required):
Compatibility with CMake < 2.8.12 will be removed from a future version of
CMake.

Update the VERSION argument  value or use a ... suffix to tell
CMake that the project does not need compatibility with older versions.

-- Found systemd via pkg-config.
-- Configuring done
CMake Error: install(EXPORT "protobuf-targets" ...) includes target "libprotobuf-lite" which requires target "absl_absl_check" that is not in any export set.
CMake Error: install(EXPORT "protobuf-targets" ...) includes target "libprotobuf-lite" which requires target "absl_absl_log" that is not in any export set.

...  snipped ...

CMake Error: install(EXPORT "protobuf-targets" ...) includes target "libprotoc" which requires target "absl_memory" that is not in any export set.
CMake Error: install(EXPORT "protobuf-targets" ...) includes target "libprotoc" which requires target "absl_node_hash_map" that is not in any export set.
CMake Error: install(EXPORT "protobuf-targets" ...) includes target "libprotoc" which requires target "absl_node_hash_set" that is not in any export set.
CMake Error: install(EXPORT "protobuf-targets" ...) includes target "libprotoc" which requires target "absl_optional" that is not in any export set.
CMake Error: install(EXPORT "protobuf-targets" ...) includes target "libprotoc" which requires target "absl_span" that is not in any export set.
CMake Error: install(EXPORT "protobuf-targets" ...) includes target "libprotoc" which requires target "absl_status" that is not in any export set.
CMake Error: install(EXPORT "protobuf-targets" ...) includes target "libprotoc" which requires target "absl_statusor" that is not in any export set.
CMake Error: install(EXPORT "protobuf-targets" ...) includes target "libprotoc" which requires target "absl_strings" that is not in any export set.
CMake Error: install(EXPORT "protobuf-targets" ...) includes target "libprotoc" which requires target "absl_synchronization" that is not in any export set.
CMake Error: install(EXPORT "protobuf-targets" ...) includes target "libprotoc" which requires target "absl_time" that is not in any export set.
CMake Error: install(EXPORT "protobuf-targets" ...) includes target "libprotoc" which requires target "absl_type_traits" that is not in any export set.
CMake Error: install(EXPORT "protobuf-targets" ...) includes target "libprotoc" which requires target "absl_utility" that is not in any export set.
CMake Error: install(EXPORT "protobuf-targets" ...) includes target "libprotoc" which requires target "absl_variant" that is not in any export set.
CMake Error: install(EXPORT "utf8_range-targets" ...) includes target "utf8_validity" which requires target "absl_strings" that is not in any export set.
-- Generating done
CMake Generate step failed.  Build files cannot be regenerated correctly.
Любые мысли были бы очень оценены.

Подробнее здесь: https://stackoverflow.com/questions/766 ... ild-hermet
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»