1 diff --git a/tree/CMakeLists.txt b/tree/CMakeLists.txt
2 index 4fd1b1a..f0d072b 100644
3 --- a/tree/CMakeLists.txt
4 +++ b/tree/CMakeLists.txt
5 @@ -50,70 +50,79 @@ if(APPLE)
6 set (CMAKE_FIND_FRAMEWORK LAST)
9 -# Fetch pybind to be able to use pybind11_add_module symbol.
10 -set(PYBIND_VER v2.10.1)
11 -include(FetchContent)
12 -FetchContent_Declare(
14 - GIT_REPOSITORY https://github.com/pybind/pybind11
15 - GIT_TAG ${PYBIND_VER}
17 -if(NOT pybind11_POPULATED)
18 - FetchContent_Populate(pybind11)
19 - add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR})
20 - include_directories(${pybind11_INCLUDE_DIR})
23 -# Needed to disable Abseil tests.
24 -set (BUILD_TESTING OFF)
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)
43 +if (NOT pybind11_FOUND)
44 + # Fetch pybind to be able to use pybind11_add_module symbol.
45 + set(PYBIND_VER v2.10.1)
46 + include(FetchContent)
47 + FetchContent_Declare(
49 + GIT_REPOSITORY https://github.com/pybind/pybind11
50 + GIT_TAG ${PYBIND_VER}
52 + if(NOT pybind11_POPULATED)
53 + FetchContent_Populate(pybind11)
54 + add_subdirectory(${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR})
55 + include_directories(${pybind11_INCLUDE_DIR})
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}
64 -ExternalProject_Get_Property(abseil-cpp install_dir)
65 -set(abseil_install_dir ${install_dir})
66 -include_directories (${abseil_install_dir}/include)
69 # Define pybind11 tree module.
70 pybind11_add_module(_tree tree.h tree.cc)
71 -add_dependencies(_tree abseil-cpp)
76 + # Needed to disable Abseil tests.
77 + set (BUILD_TESTING OFF)
79 + # Include abseil-cpp.
80 + set(ABSEIL_VER 20210324.2)
81 + include(ExternalProject)
82 + set(ABSEIL_CMAKE_ARGS
83 + "-DCMAKE_INSTALL_PREFIX=${CMAKE_SOURCE_DIR}/abseil-cpp"
84 + "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD}"
85 + "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}"
86 + "-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}"
87 + "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}"
88 + "-DCMAKE_POSITION_INDEPENDENT_CODE=${CMAKE_POSITION_INDEPENDENT_CODE}"
89 + "-DLIBRARY_OUTPUT_PATH=${CMAKE_SOURCE_DIR}/abseil-cpp/lib")
90 + if(DEFINED CMAKE_OSX_ARCHITECTURES)
91 + set(ABSEIL_CMAKE_ARGS
92 + ${ABSEIL_CMAKE_ARGS}
93 + "-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES}")
95 + ExternalProject_Add(abseil-cpp
96 + GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git
97 + GIT_TAG ${ABSEIL_VER}
98 + PREFIX ${CMAKE_SOURCE_DIR}/abseil-cpp
99 + CMAKE_ARGS ${ABSEIL_CMAKE_ARGS}
101 + ExternalProject_Get_Property(abseil-cpp install_dir)
102 + set(abseil_install_dir ${install_dir})
103 + include_directories (${abseil_install_dir}/include)
105 + add_dependencies(_tree abseil-cpp)
108 + set(ABSEIL_LIB_PREF "absl")
109 + set(LIB_SUFF "lib")
111 + set(ABSEIL_LIB_PREF "libabsl")
116 - set(ABSEIL_LIB_PREF "absl")
117 - set(LIB_SUFF "lib")
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}")
126 - set(ABSEIL_LIB_PREF "libabsl")
128 + target_link_libraries(_tree PRIVATE absl::int128 absl::raw_hash_set absl::raw_logging_internal absl::strings absl::throw_delegate)
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}")
139 # Make the module private to tree package.
140 set_target_properties(_tree PROPERTIES OUTPUT_NAME tree/_tree)