Skip to content

Commit

Permalink
PYBIND11_FINDPYTHON=ON (#738)
Browse files Browse the repository at this point in the history
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 <axel.huebl@plasma.ninja>
  • Loading branch information
ax3l authored Oct 11, 2024
1 parent 23b2808 commit 9355a57
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ impactx_make_third_party_includes_system(WarpX::ablastr_3d ablastr_3d)

# Python
if(ImpactX_PYTHON)
find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)
find_package(Python 3.8 COMPONENTS Interpreter Development.Module REQUIRED)

# default installation directories: Python
impactx_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: ${ImpactX_pybind11_repo} (${ImpactX_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(ImpactX_pybind11_internal OR ImpactX_pybind11_src)
set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)

Expand Down
9 changes: 8 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,18 @@ def build_extension(self, ext):
if not extdir.endswith(os.path.sep):
extdir += os.path.sep

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, "impactx"),
"-DCMAKE_VERBOSE_MAKEFILE=ON",
"-DCMAKE_PYTHON_OUTPUT_DIRECTORY=" + extdir,
"-DPython_EXECUTABLE=" + sys.executable,
## variants
"-DImpactX_COMPUTE=" + ImpactX_COMPUTE,
"-DImpactX_FFT:BOOL=" + ImpactX_FFT,
Expand Down

0 comments on commit 9355a57

Please sign in to comment.