diff options
| author | ruki <[email protected]> | 2025-01-09 10:19:14 +0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-01-09 10:19:14 +0800 |
| commit | 8e24b5a44dcffbee1444d715909a64014e11e866 (patch) | |
| tree | a2f0aaf7b582dae30d4db636efd199ccb158e0d8 /tests | |
| parent | 1cf6a7f479837b471a5f91410359d86983828e6a (diff) | |
| parent | 6317ffd0fe312360eb5f6e079320c01c95870ad0 (diff) | |
Merge pull request #6001 from xmake-io/namespace
Support for namespace
Diffstat (limited to 'tests')
76 files changed, 759 insertions, 0 deletions
diff --git a/tests/apis/namespace/basic/.gitignore b/tests/apis/namespace/basic/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/apis/namespace/basic/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/apis/namespace/basic/src/bar.cpp b/tests/apis/namespace/basic/src/bar.cpp new file mode 100644 index 000000000..2c00cc6b6 --- /dev/null +++ b/tests/apis/namespace/basic/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/basic/src/bar.h b/tests/apis/namespace/basic/src/bar.h new file mode 100644 index 000000000..47d8a7251 --- /dev/null +++ b/tests/apis/namespace/basic/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/basic/src/foo.cpp b/tests/apis/namespace/basic/src/foo.cpp new file mode 100644 index 000000000..1a1fb3425 --- /dev/null +++ b/tests/apis/namespace/basic/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/basic/src/foo.h b/tests/apis/namespace/basic/src/foo.h new file mode 100644 index 000000000..d2506bca9 --- /dev/null +++ b/tests/apis/namespace/basic/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/basic/src/main.cpp b/tests/apis/namespace/basic/src/main.cpp new file mode 100644 index 000000000..4cf7b5e62 --- /dev/null +++ b/tests/apis/namespace/basic/src/main.cpp @@ -0,0 +1,9 @@ +#include "foo.h" +#include "bar.h" +#include <iostream> + +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/basic/test.lua b/tests/apis/namespace/basic/test.lua new file mode 100644 index 000000000..83c0a9546 --- /dev/null +++ b/tests/apis/namespace/basic/test.lua @@ -0,0 +1,3 @@ +function main() + os.exec("xmake -vD") +end diff --git a/tests/apis/namespace/basic/xmake.lua b/tests/apis/namespace/basic/xmake.lua new file mode 100644 index 000000000..fd52ab013 --- /dev/null +++ b/tests/apis/namespace/basic/xmake.lua @@ -0,0 +1,19 @@ +add_rules("mode.debug", "mode.release") + +namespace("ns1", function () + target("foo") + set_kind("static") + add_files("src/foo.cpp") +end) + +namespace("ns2") + target("bar") + set_kind("static") + add_files("src/bar.cpp") +namespace_end() + +target("test") + set_kind("binary") + add_deps("ns1::foo", "ns2::bar") + add_files("src/main.cpp") + diff --git a/tests/apis/namespace/includes/.gitignore b/tests/apis/namespace/includes/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/apis/namespace/includes/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/apis/namespace/includes/src/bar.cpp b/tests/apis/namespace/includes/src/bar.cpp new file mode 100644 index 000000000..2c00cc6b6 --- /dev/null +++ b/tests/apis/namespace/includes/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/includes/src/bar.h b/tests/apis/namespace/includes/src/bar.h new file mode 100644 index 000000000..47d8a7251 --- /dev/null +++ b/tests/apis/namespace/includes/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/includes/src/foo.cpp b/tests/apis/namespace/includes/src/foo.cpp new file mode 100644 index 000000000..1a1fb3425 --- /dev/null +++ b/tests/apis/namespace/includes/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/includes/src/foo.h b/tests/apis/namespace/includes/src/foo.h new file mode 100644 index 000000000..d2506bca9 --- /dev/null +++ b/tests/apis/namespace/includes/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/includes/src/main.cpp b/tests/apis/namespace/includes/src/main.cpp new file mode 100644 index 000000000..4cf7b5e62 --- /dev/null +++ b/tests/apis/namespace/includes/src/main.cpp @@ -0,0 +1,9 @@ +#include "foo.h" +#include "bar.h" +#include <iostream> + +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/includes/src/xmake.lua b/tests/apis/namespace/includes/src/xmake.lua new file mode 100644 index 000000000..1d93e5a9a --- /dev/null +++ b/tests/apis/namespace/includes/src/xmake.lua @@ -0,0 +1,8 @@ +namespace("ns2", function () + add_defines("NS2_ROOT") + target("bar") + set_kind("static") + add_files("bar.cpp") + add_defines("BAR") +end) + diff --git a/tests/apis/namespace/includes/test.lua b/tests/apis/namespace/includes/test.lua new file mode 100644 index 000000000..83c0a9546 --- /dev/null +++ b/tests/apis/namespace/includes/test.lua @@ -0,0 +1,3 @@ +function main() + os.exec("xmake -vD") +end diff --git a/tests/apis/namespace/includes/xmake.lua b/tests/apis/namespace/includes/xmake.lua new file mode 100644 index 000000000..323627734 --- /dev/null +++ b/tests/apis/namespace/includes/xmake.lua @@ -0,0 +1,20 @@ +add_rules("mode.debug", "mode.release") + +add_defines("ROOT") + +namespace("ns1", function () + add_defines("NS1_ROOT") + target("foo") + set_kind("static") + add_files("src/foo.cpp") + add_defines("FOO") + + includes("src") +end) + +target("test") + set_kind("binary") + add_deps("ns1::foo", "ns1::ns2::bar") + add_files("src/main.cpp") + add_defines("TEST") + diff --git a/tests/apis/namespace/inner/.gitignore b/tests/apis/namespace/inner/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/apis/namespace/inner/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/apis/namespace/inner/src/bar.cpp b/tests/apis/namespace/inner/src/bar.cpp new file mode 100644 index 000000000..2c00cc6b6 --- /dev/null +++ b/tests/apis/namespace/inner/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/inner/src/bar.h b/tests/apis/namespace/inner/src/bar.h new file mode 100644 index 000000000..47d8a7251 --- /dev/null +++ b/tests/apis/namespace/inner/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/inner/src/foo.cpp b/tests/apis/namespace/inner/src/foo.cpp new file mode 100644 index 000000000..1a1fb3425 --- /dev/null +++ b/tests/apis/namespace/inner/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/inner/src/foo.h b/tests/apis/namespace/inner/src/foo.h new file mode 100644 index 000000000..d2506bca9 --- /dev/null +++ b/tests/apis/namespace/inner/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/inner/src/main.cpp b/tests/apis/namespace/inner/src/main.cpp new file mode 100644 index 000000000..4cf7b5e62 --- /dev/null +++ b/tests/apis/namespace/inner/src/main.cpp @@ -0,0 +1,9 @@ +#include "foo.h" +#include "bar.h" +#include <iostream> + +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/inner/test.lua b/tests/apis/namespace/inner/test.lua new file mode 100644 index 000000000..83c0a9546 --- /dev/null +++ b/tests/apis/namespace/inner/test.lua @@ -0,0 +1,3 @@ +function main() + os.exec("xmake -vD") +end diff --git a/tests/apis/namespace/inner/xmake.lua b/tests/apis/namespace/inner/xmake.lua new file mode 100644 index 000000000..c18203f29 --- /dev/null +++ b/tests/apis/namespace/inner/xmake.lua @@ -0,0 +1,19 @@ +add_rules("mode.debug", "mode.release") + +namespace("ns1", function () + target("foo") + set_kind("static") + add_files("src/foo.cpp") + + namespace("ns2", function() + target("bar") + set_kind("static") + add_files("src/bar.cpp") + end) + + target("test") + set_kind("binary") + add_deps("foo", "ns2::bar") + add_files("src/main.cpp") +end) + diff --git a/tests/apis/namespace/nested/.gitignore b/tests/apis/namespace/nested/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/apis/namespace/nested/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/apis/namespace/nested/src/bar.cpp b/tests/apis/namespace/nested/src/bar.cpp new file mode 100644 index 000000000..2c00cc6b6 --- /dev/null +++ b/tests/apis/namespace/nested/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/nested/src/bar.h b/tests/apis/namespace/nested/src/bar.h new file mode 100644 index 000000000..47d8a7251 --- /dev/null +++ b/tests/apis/namespace/nested/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/nested/src/foo.cpp b/tests/apis/namespace/nested/src/foo.cpp new file mode 100644 index 000000000..1a1fb3425 --- /dev/null +++ b/tests/apis/namespace/nested/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/nested/src/foo.h b/tests/apis/namespace/nested/src/foo.h new file mode 100644 index 000000000..d2506bca9 --- /dev/null +++ b/tests/apis/namespace/nested/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/nested/src/main.cpp b/tests/apis/namespace/nested/src/main.cpp new file mode 100644 index 000000000..4cf7b5e62 --- /dev/null +++ b/tests/apis/namespace/nested/src/main.cpp @@ -0,0 +1,9 @@ +#include "foo.h" +#include "bar.h" +#include <iostream> + +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/nested/test.lua b/tests/apis/namespace/nested/test.lua new file mode 100644 index 000000000..83c0a9546 --- /dev/null +++ b/tests/apis/namespace/nested/test.lua @@ -0,0 +1,3 @@ +function main() + os.exec("xmake -vD") +end diff --git a/tests/apis/namespace/nested/xmake.lua b/tests/apis/namespace/nested/xmake.lua new file mode 100644 index 000000000..93d7132f3 --- /dev/null +++ b/tests/apis/namespace/nested/xmake.lua @@ -0,0 +1,19 @@ +add_rules("mode.debug", "mode.release") + +namespace("ns1", function () + target("foo") + set_kind("static") + add_files("src/foo.cpp") + + namespace("ns2") + target("bar") + set_kind("static") + add_files("src/bar.cpp") + namespace_end() +end) + +target("test") + set_kind("binary") + add_deps("ns1::foo", "ns1::ns2::bar") + add_files("src/main.cpp") + diff --git a/tests/apis/namespace/option/.gitignore b/tests/apis/namespace/option/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/apis/namespace/option/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/apis/namespace/option/src/bar.cpp b/tests/apis/namespace/option/src/bar.cpp new file mode 100644 index 000000000..2c00cc6b6 --- /dev/null +++ b/tests/apis/namespace/option/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/option/src/bar.h b/tests/apis/namespace/option/src/bar.h new file mode 100644 index 000000000..47d8a7251 --- /dev/null +++ b/tests/apis/namespace/option/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/option/src/foo.cpp b/tests/apis/namespace/option/src/foo.cpp new file mode 100644 index 000000000..1a1fb3425 --- /dev/null +++ b/tests/apis/namespace/option/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/option/src/foo.h b/tests/apis/namespace/option/src/foo.h new file mode 100644 index 000000000..d2506bca9 --- /dev/null +++ b/tests/apis/namespace/option/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/option/src/main.cpp b/tests/apis/namespace/option/src/main.cpp new file mode 100644 index 000000000..4cf7b5e62 --- /dev/null +++ b/tests/apis/namespace/option/src/main.cpp @@ -0,0 +1,9 @@ +#include "foo.h" +#include "bar.h" +#include <iostream> + +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/option/test.lua b/tests/apis/namespace/option/test.lua new file mode 100644 index 000000000..83c0a9546 --- /dev/null +++ b/tests/apis/namespace/option/test.lua @@ -0,0 +1,3 @@ +function main() + os.exec("xmake -vD") +end diff --git a/tests/apis/namespace/option/xmake.lua b/tests/apis/namespace/option/xmake.lua new file mode 100644 index 000000000..b39b764f1 --- /dev/null +++ b/tests/apis/namespace/option/xmake.lua @@ -0,0 +1,44 @@ +add_rules("mode.debug", "mode.release") + +option("opt0", {default = true, defines = "OPT0", description = "option0"}) + +namespace("ns1", function () + option("opt1", {default = true, defines = "NS1_OPT1", description = "option1"}) + + target("foo") + set_kind("static") + add_files("src/foo.cpp") + add_options("opt1") + if has_config("opt1") then + add_defines("HAS_NS1_OPT1") + end + + namespace("ns2", function() + option("opt2", {default = true, defines = "NS2_OPT2", description = "option2"}) + target("bar") + set_kind("static") + add_files("src/bar.cpp") + add_options("opt2") + if has_config("opt2") then + add_defines("HAS_NS2_OPT2") + end + end) + + target("test") + set_kind("binary") + add_deps("foo", "ns2::bar") + add_files("src/main.cpp") + add_options("opt0", "opt1", "ns2::opt2") + on_load(function (target) + if has_config("opt0") then + target:add("defines", "HAS_OPT0") + end + if has_config("opt1") then + target:add("defines", "HAS_NS1_OPT1") + end + if has_config("ns2::opt2") then + target:add("defines", "HAS_NS2_OPT2") + end + end) +end) + 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 <iostream> + +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..bff75b066 --- /dev/null +++ b/tests/apis/namespace/package/test.lua @@ -0,0 +1,3 @@ +function main() + os.exec("xmake -vD -y") +end diff --git a/tests/apis/namespace/package/xmake.lua b/tests/apis/namespace/package/xmake.lua new file mode 100644 index 000000000..c88038071 --- /dev/null +++ b/tests/apis/namespace/package/xmake.lua @@ -0,0 +1,64 @@ + +add_requires("package0", {system = false}) + +package("package0") + on_load(function (package) + package:add("defines", "PACKAGE0") + end) + on_install(function (package) end) + +namespace("ns1", function () + + add_requires("package1", {system = false}) + + package("package1") + on_load(function (package) + package:add("defines", "NS1_PACKAGE1") + end) + on_install(function (package) end) + + target("foo") + set_kind("static") + add_files("src/foo.cpp") + add_packages("package1") + if has_package("package1") then + add_defines("HAS_PACKAGE1") + end + + namespace("ns2", function() + + add_requires("package2", {system = false}) + + package("package2") + on_load(function (package) + package:add("defines", "NS2_PACKAGE2") + end) + on_install(function (package) end) + + target("bar") + set_kind("static") + add_files("src/bar.cpp") + add_packages("package2") + if has_package("package2") then + add_defines("HAS_PACKAGE2") + end + end) + + target("test") + set_kind("binary") + add_deps("foo", "ns2::bar") + add_files("src/main.cpp") + add_packages("package0", "package1", "ns2::package2") + on_load(function (target) + if has_package("package0") then + target:add("defines", "HAS_PACKAGE0") + end + if has_package("package1") then + target:add("defines", "HAS_PACKAGE1") + end + if has_package("ns2::package2") then + target:add("defines", "HAS_PACKAGE2") + end + end) +end) + diff --git a/tests/apis/namespace/root/.gitignore b/tests/apis/namespace/root/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/apis/namespace/root/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/apis/namespace/root/src/bar.cpp b/tests/apis/namespace/root/src/bar.cpp new file mode 100644 index 000000000..2c00cc6b6 --- /dev/null +++ b/tests/apis/namespace/root/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/root/src/bar.h b/tests/apis/namespace/root/src/bar.h new file mode 100644 index 000000000..47d8a7251 --- /dev/null +++ b/tests/apis/namespace/root/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/root/src/foo.cpp b/tests/apis/namespace/root/src/foo.cpp new file mode 100644 index 000000000..1a1fb3425 --- /dev/null +++ b/tests/apis/namespace/root/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/root/src/foo.h b/tests/apis/namespace/root/src/foo.h new file mode 100644 index 000000000..d2506bca9 --- /dev/null +++ b/tests/apis/namespace/root/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/root/src/main.cpp b/tests/apis/namespace/root/src/main.cpp new file mode 100644 index 000000000..4cf7b5e62 --- /dev/null +++ b/tests/apis/namespace/root/src/main.cpp @@ -0,0 +1,9 @@ +#include "foo.h" +#include "bar.h" +#include <iostream> + +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/root/test.lua b/tests/apis/namespace/root/test.lua new file mode 100644 index 000000000..83c0a9546 --- /dev/null +++ b/tests/apis/namespace/root/test.lua @@ -0,0 +1,3 @@ +function main() + os.exec("xmake -vD") +end diff --git a/tests/apis/namespace/root/xmake.lua b/tests/apis/namespace/root/xmake.lua new file mode 100644 index 000000000..725fbc6f7 --- /dev/null +++ b/tests/apis/namespace/root/xmake.lua @@ -0,0 +1,26 @@ +add_rules("mode.debug", "mode.release") + +add_defines("ROOT") + +namespace("ns1", function () + add_defines("NS1_ROOT") + target("foo") + set_kind("static") + add_files("src/foo.cpp") + add_defines("FOO") + + namespace("ns2", function () + add_defines("NS2_ROOT") + target("bar") + set_kind("static") + add_files("src/bar.cpp") + add_defines("BAR") + end) +end) + +target("test") + set_kind("binary") + add_deps("ns1::foo", "ns1::ns2::bar") + add_files("src/main.cpp") + add_defines("TEST") + diff --git a/tests/apis/namespace/rule/.gitignore b/tests/apis/namespace/rule/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/apis/namespace/rule/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/apis/namespace/rule/src/bar.cpp b/tests/apis/namespace/rule/src/bar.cpp new file mode 100644 index 000000000..2c00cc6b6 --- /dev/null +++ b/tests/apis/namespace/rule/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/rule/src/bar.h b/tests/apis/namespace/rule/src/bar.h new file mode 100644 index 000000000..47d8a7251 --- /dev/null +++ b/tests/apis/namespace/rule/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/rule/src/foo.cpp b/tests/apis/namespace/rule/src/foo.cpp new file mode 100644 index 000000000..1a1fb3425 --- /dev/null +++ b/tests/apis/namespace/rule/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/rule/src/foo.h b/tests/apis/namespace/rule/src/foo.h new file mode 100644 index 000000000..d2506bca9 --- /dev/null +++ b/tests/apis/namespace/rule/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/rule/src/main.cpp b/tests/apis/namespace/rule/src/main.cpp new file mode 100644 index 000000000..4cf7b5e62 --- /dev/null +++ b/tests/apis/namespace/rule/src/main.cpp @@ -0,0 +1,9 @@ +#include "foo.h" +#include "bar.h" +#include <iostream> + +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/rule/test.lua b/tests/apis/namespace/rule/test.lua new file mode 100644 index 000000000..83c0a9546 --- /dev/null +++ b/tests/apis/namespace/rule/test.lua @@ -0,0 +1,3 @@ +function main() + os.exec("xmake -vD") +end diff --git a/tests/apis/namespace/rule/xmake.lua b/tests/apis/namespace/rule/xmake.lua new file mode 100644 index 000000000..96b80271d --- /dev/null +++ b/tests/apis/namespace/rule/xmake.lua @@ -0,0 +1,37 @@ +add_rules("mode.debug", "mode.release") + +rule("rule0") + on_load(function (target) + target:add("defines", "RULE0") + end) + +namespace("ns1", function () + rule("rule1") + on_load(function (target) + target:add("defines", "NS1_RULE1") + end) + + target("foo") + set_kind("static") + add_files("src/foo.cpp") + add_rules("rule1") + + namespace("ns2", function() + rule("rule2") + on_load(function (target) + target:add("defines", "NS2_RULE2") + end) + + target("bar") + set_kind("static") + add_files("src/bar.cpp") + add_rules("rule2") + end) + + target("test") + set_kind("binary") + add_deps("foo", "ns2::bar") + add_files("src/main.cpp") + add_rules("rule0", "rule1", "ns2::rule2") +end) + diff --git a/tests/apis/namespace/task/.gitignore b/tests/apis/namespace/task/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/apis/namespace/task/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/apis/namespace/task/test.lua b/tests/apis/namespace/task/test.lua new file mode 100644 index 000000000..46fa44af3 --- /dev/null +++ b/tests/apis/namespace/task/test.lua @@ -0,0 +1,5 @@ +function main() + os.exec("xmake task0") + os.exec("xmake ns1::task1") + os.exec("xmake ns1::ns2::task2") +end diff --git a/tests/apis/namespace/task/xmake.lua b/tests/apis/namespace/task/xmake.lua new file mode 100644 index 000000000..1f9d13e4a --- /dev/null +++ b/tests/apis/namespace/task/xmake.lua @@ -0,0 +1,22 @@ +task("task0") + set_menu {options = {}} + on_run(function () + print("task0") + end) + +namespace("ns1", function () + task("task1") + set_menu {options = {}} + on_run(function () + print("NS1_TASK1") + end) + + namespace("ns2", function() + task("task2") + set_menu {options = {}} + on_run(function () + print("NS2_TASK2") + end) + end) +end) + diff --git a/tests/apis/namespace/toolchain/.gitignore b/tests/apis/namespace/toolchain/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/apis/namespace/toolchain/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/apis/namespace/toolchain/src/bar.cpp b/tests/apis/namespace/toolchain/src/bar.cpp new file mode 100644 index 000000000..2c00cc6b6 --- /dev/null +++ b/tests/apis/namespace/toolchain/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/toolchain/src/bar.h b/tests/apis/namespace/toolchain/src/bar.h new file mode 100644 index 000000000..47d8a7251 --- /dev/null +++ b/tests/apis/namespace/toolchain/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/toolchain/src/foo.cpp b/tests/apis/namespace/toolchain/src/foo.cpp new file mode 100644 index 000000000..1a1fb3425 --- /dev/null +++ b/tests/apis/namespace/toolchain/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/toolchain/src/foo.h b/tests/apis/namespace/toolchain/src/foo.h new file mode 100644 index 000000000..d2506bca9 --- /dev/null +++ b/tests/apis/namespace/toolchain/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/toolchain/src/main.cpp b/tests/apis/namespace/toolchain/src/main.cpp new file mode 100644 index 000000000..4cf7b5e62 --- /dev/null +++ b/tests/apis/namespace/toolchain/src/main.cpp @@ -0,0 +1,9 @@ +#include "foo.h" +#include "bar.h" +#include <iostream> + +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/toolchain/test.lua b/tests/apis/namespace/toolchain/test.lua new file mode 100644 index 000000000..83c0a9546 --- /dev/null +++ b/tests/apis/namespace/toolchain/test.lua @@ -0,0 +1,3 @@ +function main() + os.exec("xmake -vD") +end diff --git a/tests/apis/namespace/toolchain/xmake.lua b/tests/apis/namespace/toolchain/xmake.lua new file mode 100644 index 000000000..588541296 --- /dev/null +++ b/tests/apis/namespace/toolchain/xmake.lua @@ -0,0 +1,36 @@ + +toolchain("toolchain0") + on_load(function (toolchain) + toolchain:add("defines", "TOOLCHAIN0") + end) + +namespace("ns1", function () + toolchain("toolchain1") + on_load(function (toolchain) + toolchain:add("defines", "NS1_TOOLCHAIN1") + end) + + target("foo") + set_kind("static") + add_files("src/foo.cpp") + set_toolchains("toolchain1") + + namespace("ns2", function() + toolchain("toolchain2") + on_load(function (toolchain) + toolchain:add("defines", "NS2_TOOLCHAIN2") + end) + + target("bar") + set_kind("static") + add_files("src/bar.cpp") + set_toolchains("toolchain2") + end) + + target("test") + set_kind("binary") + add_deps("foo", "ns2::bar") + add_files("src/main.cpp") + set_toolchains("toolchain0", "toolchain1", "ns2::toolchain2") +end) + |
