diff --git a/tests/packages/cmake-subproject/cmakesubproject.pyx b/tests/packages/cmake-subproject/cmakesubproject.pyx new file mode 100644 index 000000000..05ed8c3df --- /dev/null +++ b/tests/packages/cmake-subproject/cmakesubproject.pyx @@ -0,0 +1,13 @@ +# SPDX-FileCopyrightText: 2024 The meson-python developers +# +# SPDX-License-Identifier: MIT + +cdef extern from "cmaketest.hpp": + cdef cppclass Test: + Test(int) except + + int add(int) + + +def sum(int a, int b): + t = new Test(a) + return t.add(b) diff --git a/tests/packages/cmake-subproject/meson.build b/tests/packages/cmake-subproject/meson.build new file mode 100644 index 000000000..b7f96221a --- /dev/null +++ b/tests/packages/cmake-subproject/meson.build @@ -0,0 +1,21 @@ +# SPDX-FileCopyrightText: 2024 The meson-python developers +# +# SPDX-License-Identifier: MIT + +project('cmake-subproject', ['c', 'cpp', 'cython'], version: '1') + +if meson.version().version_compare('>= 1.3.0') + dep = dependency('cmaketest') +else + dep = import('cmake').subproject('cmaketest').dependency('cmaketest') +endif + +py = import('python').find_installation() + +py.extension_module( + 'cmakesubproject', + 'cmakesubproject.pyx', + dependencies: dep, + override_options: ['cython_language=cpp'], + install: true, +) diff --git a/tests/packages/cmake-subproject/pyproject.toml b/tests/packages/cmake-subproject/pyproject.toml new file mode 100644 index 000000000..0e67ab758 --- /dev/null +++ b/tests/packages/cmake-subproject/pyproject.toml @@ -0,0 +1,7 @@ +# SPDX-FileCopyrightText: 2021 The meson-python developers +# +# SPDX-License-Identifier: MIT + +[build-system] +build-backend = 'mesonpy' +requires = ['meson-python'] diff --git a/tests/packages/cmake-subproject/subprojects/cmaketest.wrap b/tests/packages/cmake-subproject/subprojects/cmaketest.wrap new file mode 100644 index 000000000..378ad2ed5 --- /dev/null +++ b/tests/packages/cmake-subproject/subprojects/cmaketest.wrap @@ -0,0 +1,9 @@ +# SPDX-FileCopyrightText: 2024 The meson-python developers +# +# SPDX-License-Identifier: MIT + +[wrap-file] +method = cmake + +[provide] +cmaketest = cmaketest_dep diff --git a/tests/packages/cmake-subproject/subprojects/cmaketest/CMakeLists.txt b/tests/packages/cmake-subproject/subprojects/cmaketest/CMakeLists.txt new file mode 100644 index 000000000..6bdef1b4e --- /dev/null +++ b/tests/packages/cmake-subproject/subprojects/cmaketest/CMakeLists.txt @@ -0,0 +1,17 @@ +# SPDX-FileCopyrightText: 2024 The meson-python developers +# +# SPDX-License-Identifier: MIT + +cmake_minimum_required(VERSION 3.5) + +project(cmaketest) +set(CMAKE_CXX_STANDARD 14) + +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +add_library(cmaketest SHARED cmaketest.cpp) + +include(GenerateExportHeader) +generate_export_header(cmaketest) + +install(TARGETS cmaketest) diff --git a/tests/packages/cmake-subproject/subprojects/cmaketest/cmaketest.cpp b/tests/packages/cmake-subproject/subprojects/cmaketest/cmaketest.cpp new file mode 100644 index 000000000..71bdc988f --- /dev/null +++ b/tests/packages/cmake-subproject/subprojects/cmaketest/cmaketest.cpp @@ -0,0 +1,13 @@ +// SPDX-FileCopyrightText: 2024 The meson-python developers +// +// SPDX-License-Identifier: MIT + +#include "cmaketest.hpp" + +Test::Test(int x) { + this->x = x; +} + +int Test::add(int y) const { + return x + y; +} diff --git a/tests/packages/cmake-subproject/subprojects/cmaketest/cmaketest.hpp b/tests/packages/cmake-subproject/subprojects/cmaketest/cmaketest.hpp new file mode 100644 index 000000000..e0aee2c68 --- /dev/null +++ b/tests/packages/cmake-subproject/subprojects/cmaketest/cmaketest.hpp @@ -0,0 +1,14 @@ +// SPDX-FileCopyrightText: 2024 The meson-python developers +// +// SPDX-License-Identifier: MIT + +#pragma once +#include "cmaketest_export.h" + +class CMAKETEST_EXPORT Test { +private: + int x; +public: + Test(int x); + int add(int y) const; +}; diff --git a/tests/test_wheel.py b/tests/test_wheel.py index 659ecbf5e..8d74b8543 100644 --- a/tests/test_wheel.py +++ b/tests/test_wheel.py @@ -362,3 +362,15 @@ def test_custom_target_install_dir(package_custom_target_dir, tmp_path): 'package/generated/one.py', 'package/generated/two.py', } + + +@pytest.mark.skipif(sys.platform not in {'linux', 'darwin'}, reason='Not supported on this platform') +def test_cmake_subproject(wheel_cmake_subproject): + artifact = wheel.wheelfile.WheelFile(wheel_cmake_subproject) + assert wheel_contents(artifact) == { + 'cmake_subproject-1.dist-info/METADATA', + 'cmake_subproject-1.dist-info/RECORD', + 'cmake_subproject-1.dist-info/WHEEL', + f'.cmake_subproject.mesonpy.libs/libcmaketest{LIB_SUFFIX}', + f'cmakesubproject{EXT_SUFFIX}', + }