Skip to content

Commit

Permalink
Switched from meson to scikit-build-core for simpler Fortran builds
Browse files Browse the repository at this point in the history
  • Loading branch information
lindonroberts committed May 30, 2024
1 parent 2699dc6 commit 9b1f620
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 902 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)
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)

file(GLOB F90_SOURCE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/trustregion/*.f90")

add_custom_command(
OUTPUT _trsmodule.c _trs-f2pywrappers.f
DEPENDS ${F90_SOURCE_FILES}
VERBATIM
COMMAND "${Python_EXECUTABLE}" -m numpy.f2py
"${CMAKE_CURRENT_SOURCE_DIR}/trustregion/trsapp.f90"
"${CMAKE_CURRENT_SOURCE_DIR}/trustregion/trsbox.f90"
"${CMAKE_CURRENT_SOURCE_DIR}/trustregion/trslin.f90" -m _trs --lower)

python_add_library(_trs MODULE "${CMAKE_CURRENT_BINARY_DIR}/_trsmodule.c"
"${F90_SOURCE_FILES}" WITH_SOABI)
target_link_libraries(_trs PRIVATE fortranobject)

install(TARGETS _trs DESTINATION trustregion/)

# Taken from PRIMA:
# The following are not added to the component because scikit-build-core automatically
# detects files in python/<package_name> and adds them to the wheel. These commands
# are here in case one is building via cmake directly and not via scikit-build-core
file(GLOB SUPPORTING_PY_FILES "${CMAKE_CURRENT_SOURCE_DIR}/trustregion/*.py")
install (FILES ${SUPPORTING_PY_FILES} DESTINATION trustregion)
16 changes: 0 additions & 16 deletions meson.build

This file was deleted.

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[build-system]
requires = ["meson-python", "wheel", "numpy"]
build-backend = "mesonpy"
requires = ["scikit-build-core", "numpy"]
build-backend = "scikit_build_core.build"

[project]
name = "trustregion"
dynamic = ["version"]
version = "1.2.1"
dependencies = [
"numpy"
]
Expand Down
Empty file removed trustregion/_trs-f2pywrappers.f
Empty file.
Loading

0 comments on commit 9b1f620

Please sign in to comment.