Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for namespace #6001

Open
wants to merge 15 commits into
base: dev
Choose a base branch
from
8 changes: 8 additions & 0 deletions tests/apis/namespace/basic/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Xmake cache
.xmake/
build/

# MacOS Cache
.DS_Store


5 changes: 5 additions & 0 deletions tests/apis/namespace/basic/src/bar.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "bar.h"

int sub(int a, int b) {
return a - b;
}
9 changes: 9 additions & 0 deletions tests/apis/namespace/basic/src/bar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifdef __cplusplus
extern "C" {
#endif

int sub(int a, int b);

#ifdef __cplusplus
}
#endif
5 changes: 5 additions & 0 deletions tests/apis/namespace/basic/src/foo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "foo.h"

int add(int a, int b) {
return a + b;
}
9 changes: 9 additions & 0 deletions tests/apis/namespace/basic/src/foo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifdef __cplusplus
extern "C" {
#endif

int add(int a, int b);

#ifdef __cplusplus
}
#endif
9 changes: 9 additions & 0 deletions tests/apis/namespace/basic/src/main.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
3 changes: 3 additions & 0 deletions tests/apis/namespace/basic/test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function main()
os.exec("xmake -vD")
end
19 changes: 19 additions & 0 deletions tests/apis/namespace/basic/xmake.lua
Original file line number Diff line number Diff line change
@@ -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")

8 changes: 8 additions & 0 deletions tests/apis/namespace/includes/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Xmake cache
.xmake/
build/

# MacOS Cache
.DS_Store


5 changes: 5 additions & 0 deletions tests/apis/namespace/includes/src/bar.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "bar.h"

int sub(int a, int b) {
return a - b;
}
9 changes: 9 additions & 0 deletions tests/apis/namespace/includes/src/bar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifdef __cplusplus
extern "C" {
#endif

int sub(int a, int b);

#ifdef __cplusplus
}
#endif
5 changes: 5 additions & 0 deletions tests/apis/namespace/includes/src/foo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "foo.h"

int add(int a, int b) {
return a + b;
}
9 changes: 9 additions & 0 deletions tests/apis/namespace/includes/src/foo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifdef __cplusplus
extern "C" {
#endif

int add(int a, int b);

#ifdef __cplusplus
}
#endif
9 changes: 9 additions & 0 deletions tests/apis/namespace/includes/src/main.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
8 changes: 8 additions & 0 deletions tests/apis/namespace/includes/src/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace("ns2", function ()
add_defines("NS2_ROOT")
target("bar")
set_kind("static")
add_files("bar.cpp")
add_defines("BAR")
end)

3 changes: 3 additions & 0 deletions tests/apis/namespace/includes/test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function main()
os.exec("xmake -vD")
end
20 changes: 20 additions & 0 deletions tests/apis/namespace/includes/xmake.lua
Original file line number Diff line number Diff line change
@@ -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")

8 changes: 8 additions & 0 deletions tests/apis/namespace/inner/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Xmake cache
.xmake/
build/

# MacOS Cache
.DS_Store


5 changes: 5 additions & 0 deletions tests/apis/namespace/inner/src/bar.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "bar.h"

int sub(int a, int b) {
return a - b;
}
9 changes: 9 additions & 0 deletions tests/apis/namespace/inner/src/bar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifdef __cplusplus
extern "C" {
#endif

int sub(int a, int b);

#ifdef __cplusplus
}
#endif
5 changes: 5 additions & 0 deletions tests/apis/namespace/inner/src/foo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "foo.h"

int add(int a, int b) {
return a + b;
}
9 changes: 9 additions & 0 deletions tests/apis/namespace/inner/src/foo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifdef __cplusplus
extern "C" {
#endif

int add(int a, int b);

#ifdef __cplusplus
}
#endif
9 changes: 9 additions & 0 deletions tests/apis/namespace/inner/src/main.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
3 changes: 3 additions & 0 deletions tests/apis/namespace/inner/test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function main()
os.exec("xmake -vD")
end
19 changes: 19 additions & 0 deletions tests/apis/namespace/inner/xmake.lua
Original file line number Diff line number Diff line change
@@ -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)

8 changes: 8 additions & 0 deletions tests/apis/namespace/nested/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Xmake cache
.xmake/
build/

# MacOS Cache
.DS_Store


5 changes: 5 additions & 0 deletions tests/apis/namespace/nested/src/bar.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "bar.h"

int sub(int a, int b) {
return a - b;
}
9 changes: 9 additions & 0 deletions tests/apis/namespace/nested/src/bar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifdef __cplusplus
extern "C" {
#endif

int sub(int a, int b);

#ifdef __cplusplus
}
#endif
5 changes: 5 additions & 0 deletions tests/apis/namespace/nested/src/foo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "foo.h"

int add(int a, int b) {
return a + b;
}
9 changes: 9 additions & 0 deletions tests/apis/namespace/nested/src/foo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifdef __cplusplus
extern "C" {
#endif

int add(int a, int b);

#ifdef __cplusplus
}
#endif
9 changes: 9 additions & 0 deletions tests/apis/namespace/nested/src/main.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
3 changes: 3 additions & 0 deletions tests/apis/namespace/nested/test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function main()
os.exec("xmake -vD")
end
19 changes: 19 additions & 0 deletions tests/apis/namespace/nested/xmake.lua
Original file line number Diff line number Diff line change
@@ -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")

8 changes: 8 additions & 0 deletions tests/apis/namespace/root/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Xmake cache
.xmake/
build/

# MacOS Cache
.DS_Store


5 changes: 5 additions & 0 deletions tests/apis/namespace/root/src/bar.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "bar.h"

int sub(int a, int b) {
return a - b;
}
9 changes: 9 additions & 0 deletions tests/apis/namespace/root/src/bar.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifdef __cplusplus
extern "C" {
#endif

int sub(int a, int b);

#ifdef __cplusplus
}
#endif
5 changes: 5 additions & 0 deletions tests/apis/namespace/root/src/foo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include "foo.h"

int add(int a, int b) {
return a + b;
}
9 changes: 9 additions & 0 deletions tests/apis/namespace/root/src/foo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#ifdef __cplusplus
extern "C" {
#endif

int add(int a, int b);

#ifdef __cplusplus
}
#endif
9 changes: 9 additions & 0 deletions tests/apis/namespace/root/src/main.cpp
Original file line number Diff line number Diff line change
@@ -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;
}
3 changes: 3 additions & 0 deletions tests/apis/namespace/root/test.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function main()
os.exec("xmake -vD")
end
26 changes: 26 additions & 0 deletions tests/apis/namespace/root/xmake.lua
Original file line number Diff line number Diff line change
@@ -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")

Loading