diff options
| -rw-r--r-- | tests/projects/other/autogen_code/.gitignore | 8 | ||||
| -rw-r--r-- | tests/projects/other/autogen_code/test.lua | 3 | ||||
| -rw-r--r-- | tests/projects/other/autogen_code/xmake.lua | 20 | ||||
| -rw-r--r-- | xmake/core/project/target.lua | 10 |
4 files changed, 41 insertions, 0 deletions
diff --git a/tests/projects/other/autogen_code/.gitignore b/tests/projects/other/autogen_code/.gitignore new file mode 100644 index 000000000..152105761 --- /dev/null +++ b/tests/projects/other/autogen_code/.gitignore @@ -0,0 +1,8 @@ +# Xmake cache +.xmake/ +build/ + +# MacOS Cache +.DS_Store + + diff --git a/tests/projects/other/autogen_code/test.lua b/tests/projects/other/autogen_code/test.lua new file mode 100644 index 000000000..b57362078 --- /dev/null +++ b/tests/projects/other/autogen_code/test.lua @@ -0,0 +1,3 @@ +function main(t) + t:build() +end diff --git a/tests/projects/other/autogen_code/xmake.lua b/tests/projects/other/autogen_code/xmake.lua new file mode 100644 index 000000000..fb40d8e9c --- /dev/null +++ b/tests/projects/other/autogen_code/xmake.lua @@ -0,0 +1,20 @@ +add_rules("mode.debug", "mode.release") + +target("autogen_code") + set_kind("binary") + add_files("$(buildir)/autogen.cpp", {always_added = true}) + before_build(function (target) + io.writefile("$(buildir)/autogen.cpp", [[ +#include <iostream> + +using namespace std; + +int main(int argc, char** argv) +{ + cout << "hello world!" << endl; + return 0; +} + ]]) + end) + + diff --git a/xmake/core/project/target.lua b/xmake/core/project/target.lua index 30d1ad7b1..06fab0934 100644 --- a/xmake/core/project/target.lua +++ b/xmake/core/project/target.lua @@ -1232,6 +1232,16 @@ function _instance:sourcefiles() results = os.dirs(file) end end + + -- Even if the current source file does not exist yet, we always add it. + -- This is usually used for some rules that automatically generate code files, + -- because they ensure that the code files have been generated before compilation. + -- + -- e.g. add_files("src/test.c", {always_added = true}) + -- + if #results == 0 and self:extraconf("files", file, "always_added") then + results = {file} + end end targetcache:set2("sourcefiles", file, results) end |
