Cannot build in CMake with FetchContent

1,241 views
Skip to first unread message

Gabriele Baldoni

unread,
Apr 25, 2023, 6:48:52 AM4/25/23
to Protocol Buffers
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?

Adam Cozzette

unread,
Apr 25, 2023, 11:36:55 AM4/25/23
to Gabriele Baldoni, Protocol Buffers
I think the include directory ${Protobuf_SOURCE_DIR}/third_party/abseil-cpp/absl should be just  ${Protobuf_SOURCE_DIR}/third_party/abseil-cpp.

--
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 protobuf+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/protobuf/42ca934f-32fa-4773-b589-9504d04588e1n%40googlegroups.com.

Gabriele Baldoni

unread,
Apr 25, 2023, 11:56:04 AM4/25/23
to Protocol Buffers
Right, what a stupid error, thanks for spotting this.
Reply all
Reply to author
Forward
0 new messages