From 7179e7ea7bb18e7df80a1c99c02bf54f215da160 Mon Sep 17 00:00:00 2001 From: Nikita Shulga Date: Tue, 25 May 2021 15:08:56 -0700 Subject: [PATCH] [CMake] Prefer third_party/pybind11 by default (#58951) 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 https://github.com/pytorch/pytorch/issues/58750 Pull Request resolved: https://github.com/pytorch/pytorch/pull/58951 Reviewed By: driazati Differential Revision: D28690411 Pulled By: malfet fbshipit-source-id: e56b5a8f2a23ee1834b2a6d3807f287149decf8c --- CMakeLists.txt | 2 ++ cmake/Dependencies.cmake | 12 ++++-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5f308a75f07..4818b5012b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) @@ -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 diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake index c7fe9b7d4bd..6d9c3ac3ab9 100644 --- a/cmake/Dependencies.cmake +++ b/cmake/Dependencies.cmake @@ -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})