Skip to content

Commit

Permalink
PYBIND11_FINDPYTHON=ON
Browse files Browse the repository at this point in the history
  • Loading branch information
ax3l committed Oct 11, 2024
1 parent 8742a79 commit af3e4a3
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 @@ -102,7 +102,7 @@ math(EXPR list_last "${list_len} - 1")
list(GET AMReX_SPACEDIM ${list_last} AMReX_SPACEDIM_LAST)

# Python
find_package(Python COMPONENTS Interpreter Development.Module REQUIRED)
find_package(Python 3.8.0 COMPONENTS Interpreter Development.Module REQUIRED)

# default installation directories: Python
pyamrex_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 @@ -12,6 +12,11 @@ function(find_pybind11)
message(STATUS "pybind11 repository: ${pyAMReX_pybind11_repo} (${pyAMReX_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(TARGET pybind11::module)
# nothing to do, target already exists in the superbuild
elseif(pyAMReX_pybind11_internal OR pyAMReX_pybind11_src)
Expand Down
9 changes: 8 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,18 @@ def build_extension(self, ext):
r_dim = re.search(r"amrex_(1|2|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, "amrex"),
"-DCMAKE_VERBOSE_MAKEFILE=ON",
"-DCMAKE_PYTHON_OUTPUT_DIRECTORY=" + extdir,
"-DPython_EXECUTABLE=" + sys.executable,
"-DAMReX_SPACEDIM=" + dims,
## variants
"-DAMReX_OMP=" + AMReX_OMP,
Expand Down

0 comments on commit af3e4a3

Please sign in to comment.