diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index 0c780d3f..a8246cf3 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -58,6 +58,7 @@ jobs: cmake -B build -G Ninja \ -DCMAKE_BUILD_TYPE=Debug \ -DBUILD_TZ_LIB=ON \ + -DSUBSTRAIT_CPP_FIND_PROTOBUF_CONFIG=OFF \ -DCMAKE_C_COMPILER_LAUNCHER=ccache \ -DCMAKE_CXX_COMPILER_LAUNCHER=ccache diff --git a/.gitmodules b/.gitmodules index 54889ed3..17e0ce99 100644 --- a/.gitmodules +++ b/.gitmodules @@ -7,9 +7,6 @@ [submodule "third_party/fmt"] path = third_party/fmt url = https://github.com/fmtlib/fmt -[submodule "third_party/abseil-cpp"] - path = third_party/abseil-cpp - url = https://github.com/abseil/abseil-cpp.git [submodule "third_party/datetime"] path = third_party/datetime url = https://github.com/HowardHinnant/date.git diff --git a/scripts/setup-ubuntu.sh b/scripts/setup-ubuntu.sh index a44281b8..af22e9f9 100755 --- a/scripts/setup-ubuntu.sh +++ b/scripts/setup-ubuntu.sh @@ -19,15 +19,10 @@ sudo --preserve-env apt install -y \ git \ wget \ clang-format-15 \ + libprotobuf-dev \ + protobuf-compiler \ uuid-dev \ default-jre \ libcurl4-openssl-dev -# Install the currently supported version of protobuf: -PB_REL="https://github.com/protocolbuffers/protobuf/releases" -PB_VER="28.2" -curl -LO $PB_REL/download/v$PB_VER/protoc-$PB_VER-linux-x86_64.zip -unzip protoc-$PB_VER-linux-x86_64.zip -d $HOME/.local -export PATH="$PATH:$HOME/.local/bin" - pip install cmake-format diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index b027aabe..37520af0 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -3,60 +3,20 @@ # Ensure `option()` in subdirectories honors normal variables set here. set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) +set(SUBSTRAIT_CPP_ABSL_DEFAULT_FETCH_TAG "20240116.2") set(SUBSTRAIT_CPP_PROTOBUF_DEFAULT_FETCH_TAG "v29.3") +set(SUBSTRAIT_CPP_GTEST_DEFAULT_FETCH_TAG "v1.14.0") +include(gtest.cmake) include(datetime.cmake) include(protobuf.cmake) -set(ABSL_ENABLE_INSTALL ON) if(NOT ${ABSL_INCLUDED_WITH_PROTOBUF}) - set(ABSL_PROPAGATE_CXX_STD ON) - add_subdirectory(abseil-cpp) + include(abseil-cpp.cmake) endif() add_subdirectory(fmt) -if(WIN32) - # For Windows: Prevent overriding the parent project's compiler/linker settings - set(gtest_force_shared_crt - ON - CACHE BOOL "" FORCE) -endif() - -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() -if(MSVC) - # ------------------------------------------------------------------------------ - # gtest MSVC fix - # ------------------------------------------------------------------------------ - # For some reason, googletest has include path issues when built with MSVC. - # Specifically, this seems like some incorrect assumptions about include paths - # inside the gmock project. - # We can fix this by injecting the include paths here. - function(fix_gtest_include TARGET) - target_include_directories( - ${TARGET} - PUBLIC $ - $ - $ - $ - $) - endfunction() - set(gtest_erroneous_targets gmock gmock_main) - foreach(target ${gtest_erroneous_targets}) - fix_gtest_include(${target}) - endforeach() -endif() - set(PROTOBUF_MATCHERS_BUILD_TESTING OFF) add_subdirectory(protobuf-matchers) diff --git a/third_party/abseil-cpp b/third_party/abseil-cpp deleted file mode 160000 index c2435f83..00000000 --- a/third_party/abseil-cpp +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c2435f8342c2d0ed8101cb43adfd605fdc52dca2 diff --git a/third_party/abseil-cpp.cmake b/third_party/abseil-cpp.cmake new file mode 100644 index 00000000..002bcd59 --- /dev/null +++ b/third_party/abseil-cpp.cmake @@ -0,0 +1,56 @@ +# SPDX-License-Identifier: Apache-2.0 + +set(ABSL_ENABLE_INSTALL ON) + +option(SUBSTRAIT_CPP_USE_SYSTEM_ABSL "Use system absl via find_package" ON) +option(SUBSTRAIT_CPP_FIND_ABSL_CONFIG + "Use CONFIG mode to find system absl via find_package" ON) +option(SUBSTRAIT_CPP_FETCH_ABSL "Download absl via FetchContent if not found" + ON) +set(SUBSTRAIT_CPP_ABSL_FETCH_TAG + ${SUBSTRAIT_CPP_ABSL_DEFAULT_FETCH_TAG} + CACHE STRING "Git tag or commit to use for absl FetchContent") + +# First use `find_package`. This allows downstream projects to inject their +# version with `FetchContent_Declare(... OVERRIDE_FIND_PACKAGE`. +if(SUBSTRAIT_CPP_USE_SYSTEM_ABSL) + if(SUBSTRAIT_CPP_FIND_ABSL_CONFIG) + find_package(absl CONFIG) + else() + find_package(absl) + endif() +endif() + +# Now fall back to using `FetchContent`. +if(NOT absl_FOUND AND SUBSTRAIT_CPP_FETCH_ABSL) + message(STATUS "Fetching absl-cpp version ${SUBSTRAIT_CPP_ABSL_FETCH_TAG}") + include(FetchContent) + fetchcontent_declare( + absl-cpp + GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git + GIT_TAG ${SUBSTRAIT_CPP_ABSL_FETCH_TAG} + SYSTEM OVERRIDE_FIND_PACKAGE CMAKE_ARGS + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}) + if(MSVC) + add_compile_options("/W0") + else() + add_compile_options("-w") + endif() + set(ABSL_PROPAGATE_CXX_STD ON) + fetchcontent_makeavailable(absl-cpp) + fetchcontent_getproperties(absl-cpp SOURCE_DIR absl_SOURCE_DIR) + if(TARGET status AND NOT TARGET absl::status) + add_library(absl::status ALIAS status) + endif() + if(TARGET statusor AND NOT TARGET absl::statusor) + add_library(absl::statusor ALIAS statusor) + endif() + if(TARGET strings AND NOT TARGET absl::strings) + add_library(absl::strings ALIAS strings) + endif() +endif() + +if(NOT TARGET absl::status) + message(FATAL_ERROR "absl-cpp is required but was not found or fetched.") +endif() diff --git a/third_party/gtest.cmake b/third_party/gtest.cmake index f43a0714..66c8c1b8 100644 --- a/third_party/gtest.cmake +++ b/third_party/gtest.cmake @@ -2,18 +2,54 @@ include_guard(GLOBAL) -include(FetchContent) -fetchcontent_declare( - GTest - GIT_REPOSITORY https://github.com/google/googletest.git - GIT_TAG v1.14.0 - OVERRIDE_FIND_PACKAGE) +option(SUBSTRAIT_CPP_USE_SYSTEM_GTEST "Use system GTest via find_package" ON) +option(SUBSTRAIT_CPP_FIND_GTEST_CONFIG + "Use CONFIG mode to find system GTest via find_package" ON) +option(SUBSTRAIT_CPP_FETCH_GTEST "Download GTest via FetchContent if not found" + ON) +set(SUBSTRAIT_CPP_GTEST_FETCH_TAG + ${SUBSTRAIT_CPP_GTEST_DEFAULT_FETCH_TAG} + CACHE STRING "Git tag or commit to use for GTest FetchContent") -# Disable warnings for dependency targets. -if(MSVC) - set(gtest_force_shared_crt ON) - add_compile_options("/W0") -else() - add_compile_options("-w") +# First use `find_package`. This allows downstream projects to inject their +# version with `FetchContent_Declare(... OVERRIDE_FIND_PACKAGE`. +if(SUBSTRAIT_CPP_USE_SYSTEM_GTEST) + if(SUBSTRAIT_CPP_FIND_GTEST_CONFIG) + find_package(GTest CONFIG) + else() + find_package(GTest) + endif() +endif() + +# Now fall back to using `FetchContent`. +if(NOT GTest_FOUND AND SUBSTRAIT_CPP_FETCH_GTEST) + message(STATUS "Fetching googletest version ${SUBSTRAIT_CPP_GTEST_FETCH_TAG}") + include(FetchContent) + fetchcontent_declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG ${SUBSTRAIT_CPP_GTEST_FETCH_TAG} + SYSTEM OVERRIDE_FIND_PACKAGE CMAKE_ARGS + -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} + -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}) + if(MSVC) + set(gtest_force_shared_crt + ON + CACHE BOOL "" FORCE) + add_compile_options("/W0") + else() + add_compile_options("-w") + endif() + fetchcontent_makeavailable(googletest) + fetchcontent_getproperties(googletest SOURCE_DIR GTest_SOURCE_DIR) + if(TARGET gmock AND NOT TARGET GTest::gmock) + add_library(GTest::gmock ALIAS gmock) + endif() + if(TARGET gmock_main AND NOT TARGET GTest::gmock_main) + add_library(GTest::gmock_main ALIAS gmock_main) + endif() +endif() + +if(NOT TARGET GTest::gmock) + message(FATAL_ERROR "GTest is required but was not found or fetched.") endif() -fetchcontent_makeavailable(GTest)