Skip to content

Commit

Permalink
Set up scikit-build-core for the fortran extension module
Browse files Browse the repository at this point in the history
  • Loading branch information
eguiraud committed Mar 24, 2024
1 parent f20a9c0 commit cccf4c0
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
43 changes: 43 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
cmake_minimum_required(VERSION 3.17.2...3.26)
project(${SKBUILD_PROJECT_NAME} LANGUAGES C Fortran)

find_package(
Python
COMPONENTS Interpreter Development.Module NumPy
REQUIRED)

# F2PY headers
execute_process(
COMMAND "${PYTHON_EXECUTABLE}" -c
"import numpy.f2py; print(numpy.f2py.get_include())"
OUTPUT_VARIABLE F2PY_INCLUDE_DIR
OUTPUT_STRIP_TRAILING_WHITESPACE)

add_library(fortranobject OBJECT "${F2PY_INCLUDE_DIR}/fortranobject.c")
target_link_libraries(fortranobject PUBLIC Python::NumPy)
target_include_directories(fortranobject PUBLIC "${F2PY_INCLUDE_DIR}")
set_property(TARGET fortranobject PROPERTY POSITION_INDEPENDENT_CODE ON)

add_custom_command(
OUTPUT _auroramodule.c example-f2pywrappers.f
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/aurora/main.f90"
"${CMAKE_CURRENT_SOURCE_DIR}/aurora/impden.f90"
"${CMAKE_CURRENT_SOURCE_DIR}/aurora/math.f90"
"${CMAKE_CURRENT_SOURCE_DIR}/aurora/grids.f90"
VERBATIM
COMMAND "${Python_EXECUTABLE}" -m numpy.f2py
"${CMAKE_CURRENT_SOURCE_DIR}/aurora/main.f90"
"${CMAKE_CURRENT_SOURCE_DIR}/aurora/impden.f90"
"${CMAKE_CURRENT_SOURCE_DIR}/aurora/math.f90"
"${CMAKE_CURRENT_SOURCE_DIR}/aurora/grids.f90"
-m _aurora --lower)

python_add_library(_aurora MODULE "${CMAKE_CURRENT_BINARY_DIR}/_auroramodule.c"
"${CMAKE_CURRENT_SOURCE_DIR}/aurora/main.f90"
"${CMAKE_CURRENT_SOURCE_DIR}/aurora/impden.f90"
"${CMAKE_CURRENT_SOURCE_DIR}/aurora/math.f90"
"${CMAKE_CURRENT_SOURCE_DIR}/aurora/grids.f90"
WITH_SOABI)
target_link_libraries(_aurora PRIVATE fortranobject)

install(TARGETS _aurora DESTINATION aurora/)
34 changes: 34 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[project]
name = "aurorafusion"
dynamic = ["version"]
description = "Aurora package for particle transport, radiation and neutrals in magnetically-confined plasmas"
authors = [
{ name = "F. Sciortino", email = "[email protected]" },
]
urls = { "Homepage" = "https://github.com/fsciortino/Aurora" }
keywords = ["particle and impurity transport, neutrals, radiation, magnetic confinement fusion"]
classifiers = [
"Programming Language :: Python :: 3",
]
dependencies = [
"matplotlib",
"numpy",
"omfit_classes",
"pandas",
"pexpect",
"requests",
"scipy",
]

[build-system]
requires = ["scikit-build-core", "numpy"]
build-backend = "scikit_build_core.build"

[tool.scikit-build]
ninja.minimum-version = "1.10"
cmake.minimum-version = "3.17.2"
wheel.packages = ["aurora"]

[tool.scikit-build.metadata.version]
provider = "scikit_build_core.metadata.regex"
input = "aurora/__init__.py"

0 comments on commit cccf4c0

Please sign in to comment.