1# Setup our dependency on Abseil. 2 3if(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 13if(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") 17 if(NOT ABSL_ROOT_DIR) 18 if (NOT EXISTS "${protobuf_SOURCE_DIR}/../../out/abseil-cpp/CMakeLists.txt") 19 execute_process(COMMAND ${protobuf_SOURCE_DIR}/../abseil-cpp/install_no_lock.sh ${protobuf_SOURCE_DIR}/../../out/ ${protobuf_SOURCE_DIR}/../abseil-cpp 20 WORKING_DIRECTORY ${protobuf_SOURCE_DIR}/../abseil-cpp 21 RESULT_VARIABLE result) 22 endif() 23 set(ABSL_ROOT_DIR ${protobuf_SOURCE_DIR}/../../out/abseil-cpp) 24 set(EXPORT_ABSL_ROOT_DIR "out/abseil-cpp" CACHE PATH "absl_root_dir") 25 endif() 26 if(EXISTS "${ABSL_ROOT_DIR}/CMakeLists.txt") 27 if(protobuf_INSTALL) 28 # When protobuf_INSTALL is enabled and Abseil will be built as a module, 29 # Abseil will be installed along with protobuf for convenience. 30 set(ABSL_ENABLE_INSTALL ON) 31 endif() 32 add_subdirectory(${ABSL_ROOT_DIR} third_party/abseil-cpp) 33 else() 34 message(WARNING "protobuf_ABSL_PROVIDER is \"module\" but ABSL_ROOT_DIR is wrong") 35 endif() 36 if(protobuf_INSTALL AND NOT _protobuf_INSTALL_SUPPORTED_FROM_MODULE) 37 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.") 38 set(protobuf_INSTALL FALSE) 39 endif() 40elseif(protobuf_ABSL_PROVIDER STREQUAL "package") 41 # Use "CONFIG" as there is no built-in cmake module for absl. 42 find_package(absl REQUIRED CONFIG) 43endif() 44set(_protobuf_FIND_ABSL "if(NOT TARGET absl::strings)\n find_package(absl CONFIG)\nendif()") 45 46if (BUILD_SHARED_LIBS AND MSVC) 47 # On MSVC Abseil is bundled into a single DLL. 48 # This condition is necessary as of abseil 20230125.3 when abseil is consumed 49 # via add_subdirectory, the abseil_dll target is named abseil_dll, while if 50 # abseil is consumed via find_package, the target is called absl::abseil_dll 51 # Once https://github.com/abseil/abseil-cpp/pull/1466 is merged and released 52 # in the minimum version of abseil required by protobuf, it is possible to 53 # always link absl::abseil_dll and absl::abseil_test_dll and remove the if 54 if(protobuf_ABSL_PROVIDER STREQUAL "package") 55 set(protobuf_ABSL_USED_TARGETS absl::abseil_dll) 56 set(protobuf_ABSL_USED_TEST_TARGETS absl::abseil_test_dll) 57 else() 58 set(protobuf_ABSL_USED_TARGETS abseil_dll) 59 set(protobuf_ABSL_USED_TEST_TARGETS abseil_test_dll) 60 endif() 61else() 62 set(protobuf_ABSL_USED_TARGETS 63 absl::absl_check 64 absl::absl_log 65 absl::algorithm 66 absl::base 67 absl::bind_front 68 absl::bits 69 absl::btree 70 absl::cleanup 71 absl::cord 72 absl::core_headers 73 absl::debugging 74 absl::die_if_null 75 absl::dynamic_annotations 76 absl::flags 77 absl::flat_hash_map 78 absl::flat_hash_set 79 absl::function_ref 80 absl::hash 81 absl::if_constexpr 82 absl::layout 83 absl::log_initialize 84 absl::log_globals 85 absl::log_severity 86 absl::memory 87 absl::node_hash_map 88 absl::node_hash_set 89 absl::optional 90 absl::random_distributions 91 absl::random_random 92 absl::span 93 absl::status 94 absl::statusor 95 absl::strings 96 absl::synchronization 97 absl::time 98 absl::type_traits 99 absl::utility 100 absl::variant 101 ) 102 set(protobuf_ABSL_USED_TEST_TARGETS 103 absl::scoped_mock_log 104 ) 105endif () 106