Hi all,
I'm experiencing some issue when trying to use protobuf within CMake with
fetch content when building/generating.
I got this error:
/root/example/car-pub/build/_deps/protobuf-src/src/google/protobuf/stubs/common.h:44:10:
fatal error: absl/strings/string_view.h: No such file or directory
44 | #include "absl/strings/string_view.h"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Here my CMakeLists.txt
cmake_minimum_required(VERSION 3.20)
include(FetchContent)
set(CMAKE_BUILD_TYPE Debug)
project(
car-pub
LANGUAGES C CXX)
# set(PROTOC protoc)
set(CMAKE_CXX_STANDARD 17)
FetchContent_Declare(
argparse
GIT_REPOSITORY https://github.com/p-ranav/argparse.git
)
FetchContent_MakeAvailable(argparse)
FetchContent_Declare(
Protobuf
GIT_REPOSITORY https://github.com/protocolbuffers/protobuf
GIT_TAG v22.0
)
FetchContent_MakeAvailable(Protobuf)
FetchContent_GetProperties(Protobuf SOURCE_DIR Protobuf_SOURCE_DIR)
FetchContent_GetProperties(Protobuf INCLUDE_DIRS Protobuf_INCLUDE_DIRS)
include(${Protobuf_SOURCE_DIR}/cmake/protobuf-generate.cmake)
include_directories(
${Protobuf_SOURCE_DIR}/src
${Protobuf_SOURCE_DIR}/third_party/abseil-cpp/absl
${Protobuf_SOURCE_DIR}/third_party/googletest/googletest/include
${Protobuf_SOURCE_DIR}/third_party/googletest/googlemock/include
${Protobuf_SOURCE_DIR}/third_party/jsoncpp/include
)
add_library(vss
OBJECT
${CMAKE_SOURCE_DIR}/proto/vss_rel_4.0-develop.proto
)
target_link_libraries(vss PRIVATE Protobuf)
target_include_directories(
vss PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/proto>
$<INSTALL_INTERFACE:include>
${INCLUDE_DIRECTORIES}
)
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/proto)
protobuf_generate(
TARGET vss
LANGUAGE cpp
IMPORT_DIRS ${CMAKE_SOURCE_DIR}/proto
PROTOC_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/proto
)
add_executable(publisher "src/pub.cpp")
target_link_libraries(publisher PRIVATE argparse vss)
Any suggestion?
--
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/protobuf/42ca934f-32fa-4773-b589-9504d04588e1n%40googlegroups.com.