Skip to content

Commit 787f07c

Browse files
committed
fix: support multiple inclusion
Signed-off-by: Henry Schreiner <henryschreineriii@gmail.com>
1 parent 17d91fd commit 787f07c

File tree

8 files changed

+85
-1
lines changed

8 files changed

+85
-1
lines changed

src/f2py_cmake/cmake/UseF2Py.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ if(CMAKE_VERSION VERSION_LESS 3.17)
88
message(FATAL_ERROR "CMake 3.17+ required")
99
endif()
1010

11-
include_guard(GLOBAL)
11+
include_guard(DIRECTORY)
1212

1313
if(TARGET Python::NumPy)
1414
set(_Python Python)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cmake_minimum_required(VERSION 3.24)
2+
3+
project(test
4+
LANGUAGES Fortran C
5+
)
6+
7+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
8+
9+
add_subdirectory(src)
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
add_subdirectory(subrepo)
2+
3+
set (CMAKE_FIND_FRAMEWORK LAST)
4+
find_package(
5+
Python
6+
COMPONENTS Interpreter Development.Module NumPy
7+
REQUIRED)
8+
9+
include(UseF2Py)
10+
11+
message(STATUS "Building test f2py module")
12+
13+
f2py_object_library(test_object OBJECT)
14+
f2py_generate_module(test_ test_py.F90 OUTPUT_VARIABLE test_files)
15+
python_add_library(test_ MODULE "${test_files}" WITH_SOABI)
16+
target_link_libraries(test_ PRIVATE test_object)
17+
install(TARGETS test_ DESTINATION lib/Python)
18+
19+
message(STATUS "Done building test f2py module")
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cmake_minimum_required(VERSION 3.24)
2+
3+
project(test-subrepo
4+
LANGUAGES Fortran C
5+
)
6+
7+
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
8+
9+
add_subdirectory(src)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
set(CMAKE_FIND_FRAMEWORK LAST)
2+
3+
find_package(
4+
Python
5+
COMPONENTS Interpreter Development.Module NumPy
6+
REQUIRED)
7+
8+
include(UseF2Py)
9+
10+
message(STATUS "Building subrepo f2py module")
11+
12+
f2py_object_library(subrepo_object OBJECT)
13+
f2py_generate_module(subrepo_ subrepo_py.F90 OUTPUT_VARIABLE subrepo_files)
14+
python_add_library(subrepo_ MODULE "${subrepo_files}" WITH_SOABI)
15+
target_link_libraries(subrepo_ PRIVATE subrepo_object)
16+
install(TARGETS subrepo_ DESTINATION lib/Python)
17+
18+
message(STATUS "Done building subrepo f2py module")
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
subroutine bobo()
2+
print *, "bobo"
3+
end subroutine bobo
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
subroutine bobo()
2+
print *, "bobo"
3+
end subroutine bobo

tests/test_package.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
from __future__ import annotations
22

33
import importlib.metadata
4+
import shutil
5+
import subprocess
46
import zipfile
57
from pathlib import Path
68

9+
import pytest
710
from scikit_build_core.build import build_wheel
811

912
import f2py_cmake as m
13+
import f2py_cmake.vendor
1014

1115
DIR = Path(__file__).parent.resolve()
1216

@@ -15,6 +19,7 @@ def test_version():
1519
assert importlib.metadata.version("f2py_cmake") == m.__version__
1620

1721

22+
@pytest.skipif(shutil.which("cmake") is None, reason="CMake not found")
1823
def test_f77(monkeypatch, tmp_path):
1924
monkeypatch.chdir(DIR / "packages/f77")
2025
build_dir = tmp_path / "build"
@@ -30,3 +35,21 @@ def test_f77(monkeypatch, tmp_path):
3035
build_files = {x.name for x in build_dir.iterdir()}
3136
assert "fibbymodule.c" in build_files
3237
assert "fibby-f2pywrappers.f" in build_files
38+
39+
40+
41+
def test_f90(monkeypatch, tmp_path):
42+
src_dir = tmp_path / "source"
43+
build_dir = tmp_path / "build"
44+
shutil.copytree(DIR / "packages/f90dual", src_dir)
45+
monkeypatch.chdir(src_dir)
46+
47+
cmake_dir = src_dir / "cmake"
48+
cmake_dir.mkdir()
49+
f2py_cmake.vendor.vendorize(cmake_dir)
50+
51+
inner_cmake_dir = src_dir / "src/subrepo/cmake"
52+
inner_cmake_dir.mkdir()
53+
f2py_cmake.vendor.vendorize(inner_cmake_dir)
54+
55+
subprocess.run(["cmake", "-S", ".", "-B", str(build_dir)], check=True)

0 commit comments

Comments
 (0)