From 268fa51cdc3b5b248443cce97e69254dd069f93c Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Fri, 11 Oct 2024 09:44:52 -0700 Subject: [PATCH] `PYBIND11_FINDPYTHON=ON` Reuse our `find_package(Python ...)` call and use new CMake logic in pybind11. https://pybind11.readthedocs.io/en/stable/compiling.html#modules-with-cmake https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-version-selection Signed-off-by: Axel Huebl --- CMakeLists.txt | 2 +- cmake/dependencies/pybind11.cmake | 5 +++++ setup.py | 8 ++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 980b23183fd..c08c72489cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -254,7 +254,7 @@ endif() # Python if(WarpX_PYTHON) - find_package(Python COMPONENTS Interpreter Development.Module REQUIRED) + find_package(Python 3.8 COMPONENTS Interpreter Development.Module REQUIRED) # default installation directories: Python warpx_set_default_install_dirs_python() diff --git a/cmake/dependencies/pybind11.cmake b/cmake/dependencies/pybind11.cmake index 94d38e69112..50b00013f7a 100644 --- a/cmake/dependencies/pybind11.cmake +++ b/cmake/dependencies/pybind11.cmake @@ -10,6 +10,11 @@ function(find_pybind11) message(STATUS "pybind11 repository: ${WarpX_pybind11_repo} (${WarpX_pybind11_branch})") include(FetchContent) endif() + + # rely on our find_package(Python ...) call + # https://pybind11.readthedocs.io/en/stable/compiling.html#modules-with-cmake + set(PYBIND11_FINDPYTHON ON) + if(WarpX_pybind11_internal OR WarpX_pybind11_src) set(CMAKE_POLICY_DEFAULT_CMP0077 NEW) diff --git a/setup.py b/setup.py index 9683c8ab675..f2bc72ff386 100644 --- a/setup.py +++ b/setup.py @@ -84,7 +84,15 @@ def build_extension(self, ext): r_dim = re.search(r"warpx_(1|2|rz|3)(?:d*)", ext.name) dims = r_dim.group(1).upper() + pyv = sys.version_info cmake_args = [ + # Python: use the calling interpreter in CMake + # https://cmake.org/cmake/help/latest/module/FindPython.html#hints + # https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-version-selection + f"-DPython_ROOT_DIR={sys.prefix}", + f"-DPython_FIND_VERSION={pyv.major}.{pyv.minor}.{pyv.micro}", + "-DPython_FIND_VERSION_EXACT=TRUE", + "-DPython_FIND_STRATEGY=LOCATION", "-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=" + os.path.join(extdir, "pywarpx"), "-DCMAKE_RUNTIME_OUTPUT_DIRECTORY=" + extdir, "-DWarpX_DIMS=" + dims,