Skip to content

Commit

Permalink
feature: provide protobuf as a fallback dependency (#96)
Browse files Browse the repository at this point in the history
If the protobuf library does not exist on the system, the library is
fetched and installed from github. This provides greater compatibility
for various operating systems.
  • Loading branch information
EpsilonPrime committed Feb 22, 2024
1 parent ed37bf8 commit e26585f
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 15 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
[submodule "third_party/yaml-cpp"]
path = third_party/yaml-cpp
url = https://github.com/jbeder/yaml-cpp.git
[submodule "third_party/googletest"]
path = third_party/googletest
url = https://github.com/google/googletest.git
[submodule "third_party/substrait"]
path = third_party/substrait
url = https://github.com/substrait-io/substrait.git
Expand Down
16 changes: 12 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: Apache-2.0

cmake_minimum_required(VERSION 3.20)
cmake_minimum_required(VERSION 3.24)

# set the project name
project(substrait-cpp)
Expand Down Expand Up @@ -39,11 +39,19 @@ include_directories(src)
# available otherwise we fallback to the older protobuf method.
find_package(Protobuf QUIET CONFIG)
if(${Protobuf_FOUND})
message(STATUS "Modern protobuf library located.")
set(ABSL_INCLUDED_WITH_PROTOBUF ON)
else()
find_package(Protobuf REQUIRED)
include_directories(${Protobuf_INCLUDE_DIRS})
set(ABSL_INCLUDED_WITH_PROTOBUF OFF)
find_package(Protobuf QUIET)
if(${Protobuf_FOUND})
message(STATUS "Legacy protobuf library located.")
include_directories(${Protobuf_INCLUDE_DIRS})
set(ABSL_INCLUDED_WITH_PROTOBUF OFF)
else()
message(STATUS "Fetching external protobuf library.")
include(third_party/protobuf.cmake)
set(ABSL_INCLUDED_WITH_PROTOBUF ON)
endif()
endif()

add_subdirectory(third_party)
Expand Down
6 changes: 3 additions & 3 deletions export/planloader/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# SPDX-License-Identifier: Apache-2.0

if(NOT BUILD_SUBDIR_NAME EQUAL "release")
if(CMAKE_BUILD_TYPE MATCHES Debug)
message(
SEND_ERROR,
"The planloader library does not work in Debug mode due to its dependencies."
WARNING
"The planloader library does not work well in Debug mode due to bundled heap checking."
)
endif()

Expand Down
6 changes: 4 additions & 2 deletions src/substrait/proto/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ foreach(PROTO_FILE IN LISTS PROTOBUF_FILELIST)
set(PROTO_SRC ${PROTO_OUTPUT_PARENT_DIR}/proto/${RELATIVE_PROTO_PATH}.pb.cc)
add_custom_command(
OUTPUT ${PROTO_SRC} ${PROTO_HDR}
COMMAND protobuf::protoc "--proto_path=${GENERATED_PROTO_TOPLEVEL_DIR}"
"--cpp_out=${PROTO_OUTPUT_MIDLEVEL_DIR}" ${GENERATED_PROTO_FILE}
COMMAND
protobuf::protoc
"--proto_path=${GENERATED_PROTO_TOPLEVEL_DIR}:${protobuf_SOURCE_DIR}/src"
"--cpp_out=${PROTO_OUTPUT_MIDLEVEL_DIR}" ${GENERATED_PROTO_FILE}
DEPENDS ${GENERATED_PROTOBUF_LIST} protobuf::protoc
COMMENT "Generated C++ protobuf module for ${PROTO_FILE}"
VERBATIM)
Expand Down
16 changes: 15 additions & 1 deletion third_party/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,23 @@ endif()
include(datetime.cmake)

add_subdirectory(fmt)
add_subdirectory(googletest)

find_package(GTest QUIET)
if(NOT ${GTEST_FOUND})
message(STATUS "Retrieving external GoogleTest library.")
include(FetchContent)
fetchcontent_declare(
GTest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.14.0
OVERRIDE_FIND_PACKAGE)
fetchcontent_makeavailable(GTest)
endif()

set(PREVIOUS_BUILD_TESTING ${BUILD_TESTING})
set(BUILD_TESTING OFF)
add_subdirectory(protobuf-matchers)
set(BUILD_TESTING ${PREVIOUS_BUILD_TESTING})

set(YAML_CPP_BUILD_TESTS
OFF
Expand Down
1 change: 0 additions & 1 deletion third_party/googletest
Submodule googletest deleted from d92511
19 changes: 19 additions & 0 deletions third_party/protobuf.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# SPDX-License-Identifier: Apache-2.0

include_guard(GLOBAL)

set(ABSL_PROPAGATE_CXX_STD ON)

include(FetchContent)
FetchContent_Declare(GTest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG v1.14.0
OVERRIDE_FIND_PACKAGE
)
FetchContent_Declare(Protobuf
GIT_REPOSITORY https://github.com/protocolbuffers/protobuf.git
GIT_TAG v23.4
OVERRIDE_FIND_PACKAGE
)
set(protobuf_BUILD_TESTS OFF CACHE INTERNAL "")
FetchContent_MakeAvailable(Protobuf GTest)

0 comments on commit e26585f

Please sign in to comment.