diff options
Diffstat (limited to 'tests/projects')
18 files changed, 207 insertions, 0 deletions
diff --git a/tests/projects/other/autogen_module/.gitignore b/tests/projects/other/autogen_module/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/projects/other/autogen_module/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/projects/other/autogen_module/modules/autogen/.gitignore b/tests/projects/other/autogen_module/modules/autogen/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/projects/other/autogen_module/modules/autogen/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/projects/other/autogen_module/modules/autogen/src/main.cpp b/tests/projects/other/autogen_module/modules/autogen/src/main.cpp new file mode 100644 index 000000000..c5150cdbd --- /dev/null +++ b/tests/projects/other/autogen_module/modules/autogen/src/main.cpp @@ -0,0 +1,29 @@ +#include <iostream> +#include <fstream> +#include <vector> + +using namespace std; + +int main(int argc, char** argv) { + ifstream src_file(argv[1], ios::in | ios::binary); + if (!src_file) { + return 1; + } + vector<char> buffer(istreambuf_iterator<char>(src_file), {}); + src_file.close(); + + ofstream dst_file(argv[2], ios::out); + if (!dst_file) { + return 1; + } + + dst_file << "unsigned char g_codegen_data[] = {"; + for (auto byte : buffer) { + dst_file << "0x" << hex << (int)(unsigned char)byte << ","; + } + dst_file << "0};" << endl; + dst_file.close(); + return 0; +} + + diff --git a/tests/projects/other/autogen_module/modules/autogen/xmake.lua b/tests/projects/other/autogen_module/modules/autogen/xmake.lua new file mode 100644 index 000000000..677da3e2d --- /dev/null +++ b/tests/projects/other/autogen_module/modules/autogen/xmake.lua @@ -0,0 +1,6 @@ +add_rules("mode.debug", "mode.release") + +target("generate") + add_rules("module.binary") + add_files("src/*.cpp") + set_languages("c++11") diff --git a/tests/projects/other/autogen_module/src/data.in b/tests/projects/other/autogen_module/src/data.in new file mode 100644 index 000000000..a04238969 --- /dev/null +++ b/tests/projects/other/autogen_module/src/data.in @@ -0,0 +1 @@ +hello world! diff --git a/tests/projects/other/autogen_module/src/main.cpp b/tests/projects/other/autogen_module/src/main.cpp new file mode 100644 index 000000000..3241308f7 --- /dev/null +++ b/tests/projects/other/autogen_module/src/main.cpp @@ -0,0 +1,10 @@ +#include <iostream> + +using namespace std; + +extern unsigned char g_codegen_data[]; + +int main(int argc, char** argv) { + cout << (const char*)g_codegen_data << endl; + return 0; +} diff --git a/tests/projects/other/autogen_module/test.lua b/tests/projects/other/autogen_module/test.lua new file mode 100644 index 000000000..b57362078 --- /dev/null +++ b/tests/projects/other/autogen_module/test.lua @@ -0,0 +1,3 @@ +function main(t) + t:build() +end diff --git a/tests/projects/other/autogen_module/xmake.lua b/tests/projects/other/autogen_module/xmake.lua new file mode 100644 index 000000000..c5b194d2e --- /dev/null +++ b/tests/projects/other/autogen_module/xmake.lua @@ -0,0 +1,32 @@ +add_rules("mode.debug", "mode.release") + +add_moduledirs("modules") + +rule("autogen") + set_extensions(".in") + before_build_file(function (target, sourcefile, opt) + import("utils.progress") + import("core.project.depend") + import("core.tool.compiler") + import("autogen") + + local sourcefile_cx = path.join(target:autogendir(), "rules", "autogen", path.basename(sourcefile) .. ".cpp") + local objectfile = target:objectfile(sourcefile_cx) + table.insert(target:objectfiles(), objectfile) + + depend.on_changed(function () + progress.show(opt.progress, "${color.build.object}compiling.autogen %s", sourcefile) + os.mkdir(path.directory(sourcefile_cx)) + autogen.generate(sourcefile, sourcefile_cx) + compiler.compile(sourcefile_cx, objectfile, {target = target}) + end, {dependfile = target:dependfile(objectfile), + files = sourcefile, + changed = target:is_rebuilt()}) + end) + +target("test") + set_kind("binary") + add_rules("autogen") + add_files("src/main.cpp") + add_files("src/*.in") + diff --git a/tests/projects/other/native_module/.gitignore b/tests/projects/other/native_module/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/projects/other/native_module/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/projects/other/native_module/modules/binary/bar/.gitignore b/tests/projects/other/native_module/modules/binary/bar/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/projects/other/native_module/modules/binary/bar/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/projects/other/native_module/modules/binary/bar/src/add.cpp b/tests/projects/other/native_module/modules/binary/bar/src/add.cpp new file mode 100644 index 000000000..e19d07e12 --- /dev/null +++ b/tests/projects/other/native_module/modules/binary/bar/src/add.cpp @@ -0,0 +1,9 @@ +#include <stdio.h> +#include <stdlib.h> + +int main(int argc, char** argv) { + int a = atoi(argv[1]); + int b = atoi(argv[2]); + printf("%d", a + b); + return 0; +} diff --git a/tests/projects/other/native_module/modules/binary/bar/src/sub.cpp b/tests/projects/other/native_module/modules/binary/bar/src/sub.cpp new file mode 100644 index 000000000..980289d1a --- /dev/null +++ b/tests/projects/other/native_module/modules/binary/bar/src/sub.cpp @@ -0,0 +1,10 @@ +#include <stdio.h> +#include <stdlib.h> + +int main(int argc, char** argv) { + int a = atoi(argv[1]); + int b = atoi(argv[2]); + printf("%d", a - b); + return 0; +} + diff --git a/tests/projects/other/native_module/modules/binary/bar/xmake.lua b/tests/projects/other/native_module/modules/binary/bar/xmake.lua new file mode 100644 index 000000000..add3c6e97 --- /dev/null +++ b/tests/projects/other/native_module/modules/binary/bar/xmake.lua @@ -0,0 +1,10 @@ +add_rules("mode.debug", "mode.release") + +target("add") + add_rules("module.binary") + add_files("src/add.cpp") + +target("sub") + add_rules("module.binary") + add_files("src/sub.cpp") + diff --git a/tests/projects/other/native_module/modules/shared/foo/src/foo.c b/tests/projects/other/native_module/modules/shared/foo/src/foo.c new file mode 100644 index 000000000..3024f9380 --- /dev/null +++ b/tests/projects/other/native_module/modules/shared/foo/src/foo.c @@ -0,0 +1,29 @@ +#include <stdlib.h> +#include <lua.h> +#include <lauxlib.h> + +static int add(lua_State* lua) { + int a = lua_tointeger(lua, 1); + int b = lua_tointeger(lua, 2); + lua_pushinteger(lua, a + b); + return 1; +} + +static int sub(lua_State* lua) { + int a = lua_tointeger(lua, 1); + int b = lua_tointeger(lua, 2); + lua_pushinteger(lua, a - b); + return 1; +} + +static const luaL_Reg g_funcs[] = { + {"add", add}, + {"sub", sub}, + {NULL, NULL} +}; + +int luaopen_foo(lua_State* lua) { + lua_newtable(lua); + luaL_setfuncs(lua, g_funcs, 0); + return 1; +} diff --git a/tests/projects/other/native_module/modules/shared/foo/xmake.lua b/tests/projects/other/native_module/modules/shared/foo/xmake.lua new file mode 100644 index 000000000..ad4590ffa --- /dev/null +++ b/tests/projects/other/native_module/modules/shared/foo/xmake.lua @@ -0,0 +1,9 @@ +add_rules("mode.debug", "mode.release") + +add_requires("lua 5.4") + +target("foo") + add_rules("module.shared") + add_files("src/foo.c") + add_packages("lua") + diff --git a/tests/projects/other/native_module/src/main.cpp b/tests/projects/other/native_module/src/main.cpp new file mode 100644 index 000000000..7c775d288 --- /dev/null +++ b/tests/projects/other/native_module/src/main.cpp @@ -0,0 +1,6 @@ +#include <iostream> + +int main(int argc, char** argv) { + std::cout << "hello world!" << std::endl; + return 0; +} diff --git a/tests/projects/other/native_module/test.lua b/tests/projects/other/native_module/test.lua new file mode 100644 index 000000000..0c2735866 --- /dev/null +++ b/tests/projects/other/native_module/test.lua @@ -0,0 +1,5 @@ +function main(t) + if not xmake.luajit() then + t:build() + end +end diff --git a/tests/projects/other/native_module/xmake.lua b/tests/projects/other/native_module/xmake.lua new file mode 100644 index 000000000..396921051 --- /dev/null +++ b/tests/projects/other/native_module/xmake.lua @@ -0,0 +1,16 @@ +add_rules("mode.debug", "mode.release") + +add_moduledirs("modules") + +target("test") + set_kind("binary") + add_files("src/*.cpp") + on_config(function (target) + import("shared.foo") + import("binary.bar") + print("shared: 1 + 1 = %d", foo.add(1, 1)) + print("shared: 1 - 1 = %d", foo.sub(1, 1)) + print("binary: 1 + 1 = %s", bar.add(1, 1)) + print("binary: 1 - 1 = %s", bar.sub(1, 1)) + end) + |
