@@ -50,70 +50,80 @@ if(APPLE)
5050 set (CMAKE_FIND_FRAMEWORK LAST)
5151endif ()
5252
53- # Fetch pybind to be able to use pybind11_add_module symbol.
54- set (PYBIND_VER v2.10.1)
55- include (FetchContent)
56- FetchContent_Declare(
57- pybind11
58- GIT_REPOSITORY https://github.com/pybind/pybind11
59- GIT_TAG ${PYBIND_VER}
60- )
61- if (NOT pybind11_POPULATED)
62- FetchContent_Populate(pybind11)
63- add_subdirectory (${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR} )
64- include_directories (${pybind11_INCLUDE_DIR} )
65- endif ()
66-
67- # Needed to disable Abseil tests.
68- set (BUILD_TESTING OFF )
69-
70- # Include abseil-cpp.
71- set (ABSEIL_VER 20210324.2)
72- include (ExternalProject)
73- set (ABSEIL_CMAKE_ARGS
74- "-DCMAKE_INSTALL_PREFIX=${CMAKE_SOURCE_DIR} /abseil-cpp"
75- "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} "
76- "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} "
77- "-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} "
78- "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} "
79- "-DCMAKE_POSITION_INDEPENDENT_CODE=${CMAKE_POSITION_INDEPENDENT_CODE} "
80- "-DLIBRARY_OUTPUT_PATH=${CMAKE_SOURCE_DIR} /abseil-cpp/lib" )
81- if (DEFINED CMAKE_OSX_ARCHITECTURES)
82- set (ABSEIL_CMAKE_ARGS
83- ${ABSEIL_CMAKE_ARGS}
84- "-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES} " )
53+ set (PYBIND_VER 2.10.1)
54+ find_package (pybind11 ${PYBIND_VER} CONFIG)
55+
56+ if (NOT pybind11_FOUND)
57+ # Fetch pybind to be able to use pybind11_add_module symbol.
58+ include (FetchContent)
59+ FetchContent_Declare(
60+ pybind11
61+ GIT_REPOSITORY https://github.com/pybind/pybind11
62+ GIT_TAG v${PYBIND_VER}
63+ )
64+ if (NOT pybind11_POPULATED)
65+ FetchContent_Populate(pybind11)
66+ add_subdirectory (${pybind11_SOURCE_DIR} ${pybind11_BINARY_DIR} )
67+ include_directories (${pybind11_INCLUDE_DIR} )
68+ endif ()
8569endif ()
86- ExternalProject_Add(abseil-cpp
87- GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git
88- GIT_TAG ${ABSEIL_VER}
89- PREFIX ${CMAKE_SOURCE_DIR} /abseil-cpp
90- CMAKE_ARGS ${ABSEIL_CMAKE_ARGS}
91- )
92- ExternalProject_Get_Property(abseil-cpp install_dir)
93- set (abseil_install_dir ${install_dir} )
94- include_directories (${abseil_install_dir} /include )
95-
9670
9771# Define pybind11 tree module.
9872pybind11_add_module(_tree tree .h tree .cc)
99- add_dependencies (_tree abseil-cpp)
10073
101- if (WIN32 OR MSVC )
102- set (ABSEIL_LIB_PREF "absl" )
103- set (LIB_SUFF "lib" )
74+ find_package (absl)
75+
76+ if (NOT absl_FOUND)
77+ # Needed to disable Abseil tests.
78+ set (BUILD_TESTING OFF )
79+
80+ # Include abseil-cpp.
81+ set (ABSEIL_VER 20210324.2)
82+ include (ExternalProject)
83+ set (ABSEIL_CMAKE_ARGS
84+ "-DCMAKE_INSTALL_PREFIX=${CMAKE_SOURCE_DIR} /abseil-cpp"
85+ "-DCMAKE_CXX_STANDARD=${CMAKE_CXX_STANDARD} "
86+ "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} "
87+ "-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} "
88+ "-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} "
89+ "-DCMAKE_POSITION_INDEPENDENT_CODE=${CMAKE_POSITION_INDEPENDENT_CODE} "
90+ "-DLIBRARY_OUTPUT_PATH=${CMAKE_SOURCE_DIR} /abseil-cpp/lib" )
91+ if (DEFINED CMAKE_OSX_ARCHITECTURES)
92+ set (ABSEIL_CMAKE_ARGS
93+ ${ABSEIL_CMAKE_ARGS}
94+ "-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES} " )
95+ endif ()
96+ ExternalProject_Add(abseil-cpp
97+ GIT_REPOSITORY https://github.com/abseil/abseil-cpp.git
98+ GIT_TAG ${ABSEIL_VER}
99+ PREFIX ${CMAKE_SOURCE_DIR} /abseil-cpp
100+ CMAKE_ARGS ${ABSEIL_CMAKE_ARGS}
101+ )
102+ ExternalProject_Get_Property(abseil-cpp install_dir)
103+ set (abseil_install_dir ${install_dir} )
104+ include_directories (${abseil_install_dir} /include )
105+
106+ add_dependencies (_tree abseil-cpp)
107+
108+ if (WIN32 OR MSVC )
109+ set (ABSEIL_LIB_PREF "absl" )
110+ set (LIB_SUFF "lib" )
111+ else ()
112+ set (ABSEIL_LIB_PREF "libabsl" )
113+ set (LIB_SUFF "a" )
114+ endif ()
115+
116+ # Link abseil static libs.
117+ # We don't use find_library here to force cmake to build abseil before linking.
118+ set (ABSEIL_LIBS int128 raw_hash_set raw_logging_internal strings throw_delegate)
119+ foreach (ABSEIL_LIB IN LISTS ABSEIL_LIBS)
120+ target_link_libraries (_tree PRIVATE
121+ "${abseil_install_dir} /lib/${ABSEIL_LIB_PREF} _${ABSEIL_LIB} .${LIB_SUFF} " )
122+ endforeach ()
104123else ()
105- set (ABSEIL_LIB_PREF "libabsl" )
106- set (LIB_SUFF "a" )
124+ target_link_libraries (_tree PRIVATE absl::int128 absl::raw_hash_set absl::raw_logging_internal absl::strings absl::throw_delegate)
107125endif ()
108126
109- # Link abseil static libs.
110- # We don't use find_library here to force cmake to build abseil before linking.
111- set (ABSEIL_LIBS int128 raw_hash_set raw_logging_internal strings throw_delegate)
112- foreach (ABSEIL_LIB IN LISTS ABSEIL_LIBS)
113- target_link_libraries (_tree PRIVATE
114- "${abseil_install_dir} /lib/${ABSEIL_LIB_PREF} _${ABSEIL_LIB} .${LIB_SUFF} " )
115- endforeach ()
116-
117127# Make the module private to tree package.
118128set_target_properties (_tree PROPERTIES OUTPUT_NAME tree /_tree)
119129
0 commit comments