From e5ea7bc6347ce4c4a62468138753cedea663bfa9 Mon Sep 17 00:00:00 2001 From: ruki Date: Tue, 7 Jan 2025 22:45:32 +0800 Subject: add package for namespace --- tests/apis/namespace/package/.gitignore | 8 ++++++ tests/apis/namespace/package/src/bar.cpp | 5 ++++ tests/apis/namespace/package/src/bar.h | 9 +++++++ tests/apis/namespace/package/src/foo.cpp | 5 ++++ tests/apis/namespace/package/src/foo.h | 9 +++++++ tests/apis/namespace/package/src/main.cpp | 9 +++++++ tests/apis/namespace/package/test.lua | 3 +++ tests/apis/namespace/package/xmake.lua | 44 +++++++++++++++++++++++++++++++ 8 files changed, 92 insertions(+) create mode 100644 tests/apis/namespace/package/.gitignore create mode 100644 tests/apis/namespace/package/src/bar.cpp create mode 100644 tests/apis/namespace/package/src/bar.h create mode 100644 tests/apis/namespace/package/src/foo.cpp create mode 100644 tests/apis/namespace/package/src/foo.h create mode 100644 tests/apis/namespace/package/src/main.cpp create mode 100644 tests/apis/namespace/package/test.lua create mode 100644 tests/apis/namespace/package/xmake.lua (limited to 'tests') diff --git a/tests/apis/namespace/package/.gitignore b/tests/apis/namespace/package/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/apis/namespace/package/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/apis/namespace/package/src/bar.cpp b/tests/apis/namespace/package/src/bar.cpp new file mode 100644 index 000000000..2c00cc6b6 --- /dev/null +++ b/tests/apis/namespace/package/src/bar.cpp @@ -0,0 +1,5 @@ +#include "bar.h" + +int sub(int a, int b) { + return a - b; +} diff --git a/tests/apis/namespace/package/src/bar.h b/tests/apis/namespace/package/src/bar.h new file mode 100644 index 000000000..47d8a7251 --- /dev/null +++ b/tests/apis/namespace/package/src/bar.h @@ -0,0 +1,9 @@ +#ifdef __cplusplus +extern "C" { +#endif + +int sub(int a, int b); + +#ifdef __cplusplus +} +#endif diff --git a/tests/apis/namespace/package/src/foo.cpp b/tests/apis/namespace/package/src/foo.cpp new file mode 100644 index 000000000..1a1fb3425 --- /dev/null +++ b/tests/apis/namespace/package/src/foo.cpp @@ -0,0 +1,5 @@ +#include "foo.h" + +int add(int a, int b) { + return a + b; +} diff --git a/tests/apis/namespace/package/src/foo.h b/tests/apis/namespace/package/src/foo.h new file mode 100644 index 000000000..d2506bca9 --- /dev/null +++ b/tests/apis/namespace/package/src/foo.h @@ -0,0 +1,9 @@ +#ifdef __cplusplus +extern "C" { +#endif + +int add(int a, int b); + +#ifdef __cplusplus +} +#endif diff --git a/tests/apis/namespace/package/src/main.cpp b/tests/apis/namespace/package/src/main.cpp new file mode 100644 index 000000000..4cf7b5e62 --- /dev/null +++ b/tests/apis/namespace/package/src/main.cpp @@ -0,0 +1,9 @@ +#include "foo.h" +#include "bar.h" +#include + +int main(int argc, char** argv) { + std::cout << "add(1, 2) = " << add(1, 2) << std::endl; + std::cout << "sub(2, 1) = " << sub(2, 1) << std::endl; + return 0; +} diff --git a/tests/apis/namespace/package/test.lua b/tests/apis/namespace/package/test.lua new file mode 100644 index 000000000..83c0a9546 --- /dev/null +++ b/tests/apis/namespace/package/test.lua @@ -0,0 +1,3 @@ +function main() + os.exec("xmake -vD") +end diff --git a/tests/apis/namespace/package/xmake.lua b/tests/apis/namespace/package/xmake.lua new file mode 100644 index 000000000..b2bc61d73 --- /dev/null +++ b/tests/apis/namespace/package/xmake.lua @@ -0,0 +1,44 @@ + +add_requires("package0") + +package("package0") + on_fetch(function (package) + return {defines = "PACKAGE0"} + end) + +namespace("ns1", function () + + add_requires("package1") + + package("package1") + on_fetch(function (package) + return {defines = "NS1_PACKAGE1"} + end) + + target("foo") + set_kind("static") + add_files("src/foo.cpp") + add_packages("package1") + + namespace("ns2", function() + + add_requires("package2") + + package("package2") + on_fetch(function (package) + return {defines = "NS2_PACKAGE2"} + end) + + target("bar") + set_kind("static") + add_files("src/bar.cpp") + add_packages("package2") + end) + + target("test") + set_kind("binary") + add_deps("foo", "ns2::bar") + add_files("src/main.cpp") + add_packages("package0", "package1", "ns2::package2") +end) + -- cgit v1.3.1