Skip to content

Commit

Permalink
[CMake] Prefer third_party/pybind11 by default (pytorch#58951)
Browse files Browse the repository at this point in the history
Summary:
To make build behaviour aligned with other third_party/ libraries,
introduce `USE_SYSTEM_PYBIND11 (https://github.com/pytorch/pytorch/commit/d55b25a633b7e2e6122becf6dbdf0528df6e8b13)` build option, which set to OFF by
default, which means PyTorch will be build with bundled pybind11 even if
other version is already installed locally.

Fixes pytorch#58750

Pull Request resolved: pytorch#58951

Reviewed By: driazati

Differential Revision: D28690411

Pulled By: malfet

fbshipit-source-id: e56b5a8f2a23ee1834b2a6d3807f287149decf8c
  • Loading branch information
malfet authored and facebook-github-bot committed May 25, 2021
1 parent 45aa54d commit 7179e7e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ option(USE_SYSTEM_CPUINFO "Use system-provided cpuinfo." OFF)
option(USE_SYSTEM_SLEEF "Use system-provided sleef." OFF)
option(USE_SYSTEM_GLOO "Use system-provided gloo." OFF)
option(USE_SYSTEM_FP16 "Use system-provided fp16." OFF)
option(USE_SYSTEM_PYBIND11 "Use system-provided PyBind11." OFF)
option(USE_SYSTEM_PTHREADPOOL "Use system-provided pthreadpool." OFF)
option(USE_SYSTEM_PSIMD "Use system-provided psimd." OFF)
option(USE_SYSTEM_FXDIV "Use system-provided fxdiv." OFF)
Expand All @@ -371,6 +372,7 @@ if(USE_SYSTEM_LIBS)
set(USE_SYSTEM_BENCHMARK ON)
set(USE_SYSTEM_ONNX ON)
set(USE_SYSTEM_XNNPACK ON)
set(USE_SYSTEM_PYBIND11 ON)
endif()

# Used when building Caffe2 through setup.py
Expand Down
12 changes: 4 additions & 8 deletions cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -999,24 +999,20 @@ if(BUILD_PYTHON)
endif()

# ---[ pybind11
if(NOT pybind11_PREFER_third_party)
if(USE_SYSTEM_BIND11)
find_package(pybind11 CONFIG)
if(NOT pybind11_FOUND)
find_package(pybind11)
endif()
endif()

if(pybind11_FOUND)
message(STATUS "System pybind11 found")
if(NOT pybind11_FOUND)
message(FATAL "Cannot find system pybind11")
endif()
else()
message(STATUS "Using third_party/pybind11.")
set(pybind11_INCLUDE_DIRS ${CMAKE_CURRENT_LIST_DIR}/../third_party/pybind11/include)
install(DIRECTORY ${pybind11_INCLUDE_DIRS}
DESTINATION ${CMAKE_INSTALL_PREFIX}
FILES_MATCHING PATTERN "*.h")
set(pybind11_PREFER_third_party ON CACHE BOOL
"Use the third_party/pybind11 submodule, instead of looking for system
installation of pybind11")
endif()
message(STATUS "pybind11 include dirs: " "${pybind11_INCLUDE_DIRS}")
include_directories(SYSTEM ${pybind11_INCLUDE_DIRS})
Expand Down

0 comments on commit 7179e7e

Please sign in to comment.