Skip to content

Commit bf44871

Browse files
build(deps): refactor CMake files for finding abseil-cpp
This PR refactors the CMake logic that finds or fetches the abseil-cpp dependency. It follows the same pattern applied by substrait-io#138 for the protobuf library. Signed-off-by: Ingo Müller <ingomueller@google.com>
1 parent aae781d commit bf44871

4 files changed

Lines changed: 58 additions & 7 deletions

File tree

.gitmodules

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
[submodule "third_party/fmt"]
88
path = third_party/fmt
99
url = https://github.com/fmtlib/fmt
10-
[submodule "third_party/abseil-cpp"]
11-
path = third_party/abseil-cpp
12-
url = https://github.com/abseil/abseil-cpp.git
1310
[submodule "third_party/datetime"]
1411
path = third_party/datetime
1512
url = https://github.com/HowardHinnant/date.git

third_party/CMakeLists.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33
# Ensure `option()` in subdirectories honors normal variables set here.
44
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
55

6+
set(SUBSTRAIT_CPP_ABSL_DEFAULT_FETCH_TAG "20240116.2")
67
set(SUBSTRAIT_CPP_PROTOBUF_DEFAULT_FETCH_TAG "v29.3")
78
set(SUBSTRAIT_CPP_GTEST_DEFAULT_FETCH_TAG "v1.14.0")
89

910
include(gtest.cmake)
1011
include(datetime.cmake)
1112
include(protobuf.cmake)
1213

13-
set(ABSL_ENABLE_INSTALL ON)
1414
if(NOT ${ABSL_INCLUDED_WITH_PROTOBUF})
15-
set(ABSL_PROPAGATE_CXX_STD ON)
16-
add_subdirectory(abseil-cpp)
15+
include(abseil-cpp.cmake)
1716
endif()
1817

1918
add_subdirectory(fmt)

third_party/abseil-cpp

Lines changed: 0 additions & 1 deletion
This file was deleted.

third_party/abseil-cpp.cmake

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
set(ABSL_ENABLE_INSTALL ON)
4+
5+
option(SUBSTRAIT_CPP_USE_SYSTEM_ABSL "Use system absl via find_package" ON)
6+
option(SUBSTRAIT_CPP_FIND_ABSL_CONFIG
7+
"Use CONFIG mode to find system absl via find_package" ON)
8+
option(SUBSTRAIT_CPP_FETCH_ABSL "Download absl via FetchContent if not found"
9+
ON)
10+
set(SUBSTRAIT_CPP_ABSL_FETCH_TAG
11+
${SUBSTRAIT_CPP_ABSL_DEFAULT_FETCH_TAG}
12+
CACHE STRING "Git tag or commit to use for absl FetchContent")
13+
14+
# First use `find_package`. This allows downstream projects to inject their
15+
# version with `FetchContent_Declare(... OVERRIDE_FIND_PACKAGE`.
16+
if(SUBSTRAIT_CPP_USE_SYSTEM_ABSL)
17+
if(SUBSTRAIT_CPP_FIND_ABSL_CONFIG)
18+
find_package(absl CONFIG)
19+
else()
20+
find_package(absl)
21+
endif()
22+
endif()
23+
24+
# Now fall back to using `FetchContent`.
25+
if(NOT absl_FOUND AND SUBSTRAIT_CPP_FETCH_ABSL)
26+
message(STATUS "Fetching absl-cpp version ${SUBSTRAIT_CPP_ABSL_FETCH_TAG}")
27+
include(FetchContent)
28+
fetchcontent_declare(
29+
absl-cpp
30+
GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git
31+
GIT_TAG ${SUBSTRAIT_CPP_ABSL_FETCH_TAG}
32+
SYSTEM OVERRIDE_FIND_PACKAGE CMAKE_ARGS
33+
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}
34+
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER})
35+
if(MSVC)
36+
add_compile_options("/W0")
37+
else()
38+
add_compile_options("-w")
39+
endif()
40+
set(ABSL_PROPAGATE_CXX_STD ON)
41+
fetchcontent_makeavailable(absl-cpp)
42+
fetchcontent_getproperties(absl-cpp SOURCE_DIR absl_SOURCE_DIR)
43+
if(TARGET status AND NOT TARGET absl::status)
44+
add_library(absl::status ALIAS status)
45+
endif()
46+
if(TARGET statusor AND NOT TARGET absl::statusor)
47+
add_library(absl::statusor ALIAS statusor)
48+
endif()
49+
if(TARGET strings AND NOT TARGET absl::strings)
50+
add_library(absl::strings ALIAS strings)
51+
endif()
52+
endif()
53+
54+
if(NOT TARGET absl::status)
55+
message(FATAL_ERROR "absl-cpp is required but was not found or fetched.")
56+
endif()

0 commit comments

Comments
 (0)