-
-
Notifications
You must be signed in to change notification settings - Fork 814
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
112 additions
and
2 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Xmake cache | ||
.xmake/ | ||
build/ | ||
|
||
# MacOS Cache | ||
.DS_Store | ||
|
||
|
8 changes: 8 additions & 0 deletions
8
tests/projects/other/autogen_shared_module/modules/autogen/foo/.gitignore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Xmake cache | ||
.xmake/ | ||
build/ | ||
|
||
# MacOS Cache | ||
.DS_Store | ||
|
||
|
42 changes: 42 additions & 0 deletions
42
tests/projects/other/autogen_shared_module/modules/autogen/foo/src/main.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include <xmi.h> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <vector> | ||
|
||
using namespace std; | ||
|
||
static int generate(lua_State* lua) { | ||
const char* inputfile = lua_tostring(lua, 1); | ||
const char* outputfile = lua_tostring(lua, 2); | ||
|
||
ifstream src_file(inputfile, ios::in | ios::binary); | ||
if (!src_file) { | ||
return 1; | ||
} | ||
vector<char> buffer(istreambuf_iterator<char>(src_file), {}); | ||
src_file.close(); | ||
|
||
ofstream dst_file(outputfile, 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; | ||
} | ||
|
||
int luaopen(foo, lua_State* lua) { | ||
static const luaL_Reg funcs[] = { | ||
{"generate", generate}, | ||
{NULL, NULL} | ||
}; | ||
lua_newtable(lua); | ||
luaL_setfuncs(lua, funcs, 0); | ||
return 1; | ||
} | ||
|
6 changes: 6 additions & 0 deletions
6
tests/projects/other/autogen_shared_module/modules/autogen/foo/xmake.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
add_rules("mode.debug", "mode.release") | ||
|
||
target("foo") | ||
add_rules("module.shared") | ||
add_files("src/*.cpp") | ||
set_languages("c++11") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
hello world! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
function main(t) | ||
t:build() | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.foo", {always_build = true}) | ||
|
||
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)) | ||
foo.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") | ||
|