blob: 1b64affa50cafa4081176eb6442d55b5390a9246 [file] [log] [blame]
Mike Kruskalcac97652022-08-12 16:41:00 -07001# Setup our dependency on Abseil.
2
Mike Kruskala9f1ea62023-01-24 21:49:33 -08003if(protobuf_BUILD_TESTS)
4 # Tell Abseil to build test-only helpers.
5 set(ABSL_BUILD_TEST_HELPERS ON)
6
7 # We depend on googletest too, so just tell Abseil to use the same one we've
8 # already setup.
9 set(ABSL_USE_EXTERNAL_GOOGLETEST ON)
10 set(ABSL_FIND_GOOGLETEST OFF)
11endif()
12
Christian Blichmann6affd512022-08-22 22:51:28 +020013if(TARGET absl::strings)
14 # If Abseil is included already, skip including it.
15 # (https://github.com/protocolbuffers/protobuf/issues/10435)
16elseif(protobuf_ABSL_PROVIDER STREQUAL "module")
Mike Kruskalcac97652022-08-12 16:41:00 -070017 if(NOT ABSL_ROOT_DIR)
18 set(ABSL_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/abseil-cpp)
19 endif()
20 if(EXISTS "${ABSL_ROOT_DIR}/CMakeLists.txt")
21 if(protobuf_INSTALL)
22 # When protobuf_INSTALL is enabled and Abseil will be built as a module,
23 # Abseil will be installed along with protobuf for convenience.
24 set(ABSL_ENABLE_INSTALL ON)
25 endif()
26 add_subdirectory(${ABSL_ROOT_DIR} third_party/abseil-cpp)
27 else()
28 message(WARNING "protobuf_ABSL_PROVIDER is \"module\" but ABSL_ROOT_DIR is wrong")
29 endif()
30 if(protobuf_INSTALL AND NOT _protobuf_INSTALL_SUPPORTED_FROM_MODULE)
31 message(WARNING "protobuf_INSTALL will be forced to FALSE because protobuf_ABSL_PROVIDER is \"module\" and CMake version (${CMAKE_VERSION}) is less than 3.13.")
32 set(protobuf_INSTALL FALSE)
33 endif()
34elseif(protobuf_ABSL_PROVIDER STREQUAL "package")
35 # Use "CONFIG" as there is no built-in cmake module for absl.
36 find_package(absl REQUIRED CONFIG)
37endif()
38set(_protobuf_FIND_ABSL "if(NOT TARGET absl::strings)\n find_package(absl CONFIG)\nendif()")
39
Mike Kruskal983fc2d2022-11-02 23:24:26 -070040if (BUILD_SHARED_LIBS AND MSVC)
41 # On MSVC Abseil is bundled into a single DLL.
Protobuf Team Botf5a22552024-02-05 16:44:49 -080042 # This condition is necessary as of abseil 20230125.3 when abseil is consumed
43 # via add_subdirectory, the abseil_dll target is named abseil_dll, while if
44 # abseil is consumed via find_package, the target is called absl::abseil_dll
45 # Once https://github.com/abseil/abseil-cpp/pull/1466 is merged and released
46 # in the minimum version of abseil required by protobuf, it is possible to
47 # always link absl::abseil_dll and absl::abseil_test_dll and remove the if
Silvio Traversaro87b3bc72023-06-05 15:01:50 -070048 if(protobuf_ABSL_PROVIDER STREQUAL "package")
49 set(protobuf_ABSL_USED_TARGETS absl::abseil_dll)
50 set(protobuf_ABSL_USED_TEST_TARGETS absl::abseil_test_dll)
51 else()
52 set(protobuf_ABSL_USED_TARGETS abseil_dll)
53 set(protobuf_ABSL_USED_TEST_TARGETS abseil_test_dll)
54 endif()
Mike Kruskal983fc2d2022-11-02 23:24:26 -070055else()
56 set(protobuf_ABSL_USED_TARGETS
Mike Kruskala9f1ea62023-01-24 21:49:33 -080057 absl::absl_check
58 absl::absl_log
Mike Kruskal983fc2d2022-11-02 23:24:26 -070059 absl::algorithm
60 absl::base
61 absl::bind_front
62 absl::bits
63 absl::btree
64 absl::cleanup
65 absl::cord
66 absl::core_headers
67 absl::debugging
Mike Kruskala9f1ea62023-01-24 21:49:33 -080068 absl::die_if_null
Mike Kruskal983fc2d2022-11-02 23:24:26 -070069 absl::dynamic_annotations
70 absl::flags
71 absl::flat_hash_map
72 absl::flat_hash_set
73 absl::function_ref
74 absl::hash
Protobuf Team Bot578e07e2023-11-27 11:26:16 -080075 absl::if_constexpr
Mike Kruskal983fc2d2022-11-02 23:24:26 -070076 absl::layout
Mike Kruskala9f1ea62023-01-24 21:49:33 -080077 absl::log_initialize
Protobuf Team Botf5a22552024-02-05 16:44:49 -080078 absl::log_globals
Mike Kruskala9f1ea62023-01-24 21:49:33 -080079 absl::log_severity
Mike Kruskal983fc2d2022-11-02 23:24:26 -070080 absl::memory
81 absl::node_hash_map
82 absl::node_hash_set
83 absl::optional
Mike Kruskalb6032d72024-03-12 12:37:29 -070084 absl::random_distributions
85 absl::random_random
Mike Kruskal983fc2d2022-11-02 23:24:26 -070086 absl::span
87 absl::status
88 absl::statusor
89 absl::strings
90 absl::synchronization
91 absl::time
Mike Kruskal1aef0a42023-01-03 15:51:30 -080092 absl::type_traits
Mike Kruskal983fc2d2022-11-02 23:24:26 -070093 absl::utility
94 absl::variant
95 )
Mike Kruskala9f1ea62023-01-24 21:49:33 -080096 set(protobuf_ABSL_USED_TEST_TARGETS
97 absl::scoped_mock_log
98 )
Mike Kruskal7930cd12023-01-20 21:38:59 -080099endif ()