1diff --git a/tree/CMakeLists.txt b/tree/CMakeLists.txt
2index 8f9946c..b9d6e9b 100644
3--- a/tree/CMakeLists.txt
4+++ b/tree/CMakeLists.txt
5@@ -50,70 +50,80 @@ if(APPLE)
6 set (CMAKE_FIND_FRAMEWORK LAST)
7 endif()
8
9-# Fetch pybind to be able to use pybind11_add_module symbol.
10-set(PYBIND_VER v2.6.2)
11-include(FetchContent)
12-FetchContent_Declare(
13- pybind11
14- GIT_REPOSITORY https://github.com/pybind/pybind11
15- GIT_TAG ${PYBIND_VER}
16-)
17-if(NOT pybind11_POPULATED)
18- FetchContent_Populate(pybind11)
19- add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR})
20- include_directories(${pybind11_INCLUDE_DIR})
21-endif()
22-
23-# Needed to disable Abseil tests.
24-set (BUILD_TESTING OFF)
25-
26-# Include abseil-cpp.
27-set(ABSEIL_VER 20210324.2)
28-include(ExternalProject)
29-set(ABSEIL_CMAKE_ARGS
30- "-DCMAKE_INSTALL_PREFIX=${CMAKE_SOURCE_DIR}/abseil-cpp"
31- "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
32- "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
33- "-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}"
34- "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
35- "-DCMAKE_POSITION_INDEPENDENT_CODE=${CMAKE_POSITION_INDEPENDENT_CODE}"
36- "-DLIBRARY_OUTPUT_PATH=${CMAKE_SOURCE_DIR}/abseil-cpp/lib")
37-if(DEFINED CMAKE_OSX_ARCHITECTURES)
38- set(ABSEIL_CMAKE_ARGS
39- ${ABSEIL_CMAKE_ARGS}
40- "-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}")
41+find_package(pybind11 CONFIG)
42+
43+if (NOT pybind11_FOUND)
44+ # Fetch pybind to be able to use pybind11_add_module symbol.
45+ set(PYBIND_VER v2.6.2)
46+ include(FetchContent)
47+ FetchContent_Declare(
48+ pybind11
49+ GIT_REPOSITORY https://github.com/pybind/pybind11
50+ GIT_TAG ${PYBIND_VER}
51+ )
52+ if(NOT pybind11_POPULATED)
53+ FetchContent_Populate(pybind11)
54+ add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR})
55+ include_directories(${pybind11_INCLUDE_DIR})
56+ endif()
57 endif()
58-ExternalProject_Add(abseil-cpp
59- GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git
60- GIT_TAG ${ABSEIL_VER}
61- PREFIX ${CMAKE_SOURCE_DIR}/abseil-cpp
62- CMAKE_ARGS ${ABSEIL_CMAKE_ARGS}
63-)
64-ExternalProject_Get_Property(abseil-cpp install_dir)
65-set(abseil_install_dir ${install_dir})
66-include_directories (${abseil_install_dir}/include)
67-
68
69 # Define pybind11 tree module.
70 pybind11_add_module(_tree tree.h tree.cc)
71-add_dependencies(_tree abseil-cpp)
72
73-if (WIN32 OR MSVC)
74- set(ABSEIL_LIB_PREF "absl")
75- set(LIB_SUFF "lib")
76+find_package(absl)
77+
78+if (NOT absl_FOUND)
79+ # Needed to disable Abseil tests.
80+ set (BUILD_TESTING OFF)
81+
82+ # Include abseil-cpp.
83+ set(ABSEIL_VER 20210324.2)
84+ include(ExternalProject)
85+ set(ABSEIL_CMAKE_ARGS
86+ "-DCMAKE_INSTALL_PREFIX=${CMAKE_SOURCE_DIR}/abseil-cpp"
87+ "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
88+ "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
89+ "-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}"
90+ "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
91+ "-DCMAKE_POSITION_INDEPENDENT_CODE=${CMAKE_POSITION_INDEPENDENT_CODE}"
92+ "-DLIBRARY_OUTPUT_PATH=${CMAKE_SOURCE_DIR}/abseil-cpp/lib")
93+ if(DEFINED CMAKE_OSX_ARCHITECTURES)
94+ set(ABSEIL_CMAKE_ARGS
95+ ${ABSEIL_CMAKE_ARGS}
96+ "-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}")
97+ endif()
98+ ExternalProject_Add(abseil-cpp
99+ GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git
100+ GIT_TAG ${ABSEIL_VER}
101+ PREFIX ${CMAKE_SOURCE_DIR}/abseil-cpp
102+ CMAKE_ARGS ${ABSEIL_CMAKE_ARGS}
103+ )
104+ ExternalProject_Get_Property(abseil-cpp install_dir)
105+ set(abseil_install_dir ${install_dir})
106+ include_directories (${abseil_install_dir}/include)
107+
108+ add_dependencies(_tree abseil-cpp)
109+
110+ if (WIN32 OR MSVC)
111+ set(ABSEIL_LIB_PREF "absl")
112+ set(LIB_SUFF "lib")
113+ else()
114+ set(ABSEIL_LIB_PREF "libabsl")
115+ set(LIB_SUFF "a")
116+ endif()
117+
118+ # Link abseil static libs.
119+ # We don't use find_library here to force cmake to build abseil before linking.
120+ set(ABSEIL_LIBS int128 raw_hash_set raw_logging_internal strings throw_delegate)
121+ foreach(ABSEIL_LIB IN LISTS ABSEIL_LIBS)
122+ target_link_libraries(_tree PRIVATE
123+ "${abseil_install_dir}/lib/${ABSEIL_LIB_PREF}_${ABSEIL_LIB}.${LIB_SUFF}")
124+ endforeach()
125 else()
126- set(ABSEIL_LIB_PREF "libabsl")
127- set(LIB_SUFF "a")
128+ target_link_libraries(_tree PRIVATE absl::int128 absl::raw_hash_set absl::raw_logging_internal absl::strings absl::throw_delegate)
129 endif()
130
131-# Link abseil static libs.
132-# We don't use find_library here to force cmake to build abseil before linking.
133-set(ABSEIL_LIBS int128 raw_hash_set raw_logging_internal strings throw_delegate)
134-foreach(ABSEIL_LIB IN LISTS ABSEIL_LIBS)
135- target_link_libraries(_tree PRIVATE
136- "${abseil_install_dir}/lib/${ABSEIL_LIB_PREF}_${ABSEIL_LIB}.${LIB_SUFF}")
137-endforeach()
138-
139 # Make the module private to tree package.
140 set_target_properties(_tree PROPERTIES OUTPUT_NAME tree/_tree)
141