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/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index b027aabe..8489a8a0 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -3,60 +3,16 @@ # 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) -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/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) diff --git a/third_party/protobuf.cmake b/third_party/protobuf.cmake index da88c837..1847bd01 100644 --- a/third_party/protobuf.cmake +++ b/third_party/protobuf.cmake @@ -60,9 +60,3 @@ endif() if(NOT TARGET protobuf::libprotobuf) message(FATAL_ERROR "Protobuf is required but was not found or fetched.") endif() - -if(NOT TARGET absl::status) - set(ABSL_INCLUDED_WITH_PROTOBUF OFF) -else() - set(ABSL_INCLUDED_WITH_PROTOBUF ON) -endif()