Skip to content

Commit

Permalink
PYBIND11_FINDPYTHON=ON (ECP-WarpX#5390)
Browse files Browse the repository at this point in the history
  • Loading branch information
ax3l authored and dpgrote committed Oct 23, 2024
1 parent 25cee2d commit 217ada9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions cmake/dependencies/pybind11.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 8 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 217ada9

Please sign in to comment.