Skip to content

Commit

Permalink
Call find_package() conditionally.
Browse files Browse the repository at this point in the history
If a top-level project has called `add_directory(abseil-cpp)` already (possibly
indirectly), let that take precedence over any copy of Abseil that might have
been installed on the system. And likewise for ICU, GoogleTest and Benchmark.

Fixes #427.

Change-Id: I1902f6fc04df49d029357734116e08ee4a565836
Reviewed-on: https://code-review.googlesource.com/c/re2/+/61350
Reviewed-by: Paul Wankadia <[email protected]>
Reviewed-by: Alex Chernyakhovsky <[email protected]>
  • Loading branch information
junyer committed May 24, 2023
1 parent 1e44e72 commit 63aeffa
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,18 @@ set(ABSL_DEPS
absl_synchronization
)

find_package(absl REQUIRED)
# If a top-level project has called add_directory(abseil-cpp) already (possibly
# indirectly), let that take precedence over any copy of Abseil that might have
# been installed on the system. And likewise for ICU, GoogleTest and Benchmark.
if(NOT TARGET absl::base)
find_package(absl REQUIRED)
endif()
list(APPEND REQUIRES ${ABSL_DEPS})

if(RE2_USE_ICU)
find_package(ICU REQUIRED COMPONENTS uc)
if(NOT TARGET ICU::uc)
find_package(ICU REQUIRED COMPONENTS uc)
endif()
add_definitions(-DRE2_USE_ICU)
list(APPEND REQUIRES icu-uc)
endif()
Expand Down Expand Up @@ -159,8 +166,12 @@ if(RE2_USE_ICU)
endif()

if(RE2_BUILD_TESTING)
find_package(GTest REQUIRED)
find_package(benchmark REQUIRED)
if(NOT TARGET GTest::gtest)
find_package(GTest REQUIRED)
endif()
if(NOT TARGET benchmark::benchmark)
find_package(benchmark REQUIRED)
endif()

set(TESTING_SOURCES
re2/testing/backtrack.cc
Expand Down

0 comments on commit 63aeffa

Please sign in to comment.