Browse Source

Use a system-installed abseil when available (#2791)

Currently, CMake is configured to download and build abseil from source
whenever `BUILD_GEOCODER` is set to `ON`. Let's allow users to use a
pre-existing installation of abseil by checking for one first before
attempting to download and build another one.

If CMake finds a pre-existing installation of abseil, it will use that
instead.

We need to allow the user to override `CMAKE_CXX_STANDARD` because they
may have built abseil with a newer standard than C++11. Attempting to
build libphonenumber with C++11 will fail if abseil was built with a
newer C++ standard.

Closes #2772.
pull/2794/head
Carlo Cabrera 3 years ago
committed by GitHub
parent
commit
035901b78d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 22 deletions
  1. +3
    -1
      cpp/CMakeLists.txt
  2. +23
    -21
      tools/cpp/CMakeLists.txt

+ 3
- 1
cpp/CMakeLists.txt View File

@ -18,7 +18,7 @@ cmake_minimum_required (VERSION 3.11)
# Pick the C++ standard to compile with.
# Abseil currently supports C++11, C++14, and C++17.
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 11 CACHE STRING "C++ standard used to compile this project")
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project (libphonenumber)
@ -203,6 +203,8 @@ add_custom_command (
)
if (${BUILD_GEOCODER} STREQUAL "ON")
find_package(absl)
# Geocoding data cpp file generation
set (TOOLS_DIR "${CMAKE_CURRENT_BINARY_DIR}/tools")
add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../tools/cpp" "${TOOLS_DIR}")


+ 23
- 21
tools/cpp/CMakeLists.txt View File

@ -28,27 +28,29 @@ project (generate_geocoding_data)
include (gtest.cmake)
include (FetchContent)
# Downloading the abseil sources.
FetchContent_Declare(
abseil-cpp
GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git
GIT_TAG origin/master
)
# Building the abseil binaries
FetchContent_GetProperties(abseil-cpp)
if (NOT abseil-cpp_POPULATED)
FetchContent_Populate(abseil-cpp)
endif ()
if (NOT abseil-cpp_POPULATED)
message (FATAL_ERROR "Could not build abseil-cpp binaries.")
endif ()
# Safeguarding against any potential link errors as mentioned in
# https://github.com/abseil/abseil-cpp/issues/225
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
add_subdirectory(${abseil-cpp_SOURCE_DIR} ${abseil-cpp_BINARY_DIR})
if(NOT absl_FOUND)
# Downloading the abseil sources.
FetchContent_Declare(
abseil-cpp
GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git
GIT_TAG origin/master
)
# Building the abseil binaries
FetchContent_GetProperties(abseil-cpp)
if (NOT abseil-cpp_POPULATED)
FetchContent_Populate(abseil-cpp)
endif ()
if (NOT abseil-cpp_POPULATED)
message (FATAL_ERROR "Could not build abseil-cpp binaries.")
endif ()
# Safeguarding against any potential link errors as mentioned in
# https://github.com/abseil/abseil-cpp/issues/225
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
add_subdirectory(${abseil-cpp_SOURCE_DIR} ${abseil-cpp_BINARY_DIR})
endif()
find_or_build_gtest ()
set (


Loading…
Cancel
Save