summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/apis/add_files_replace/src/config.h2
-rw-r--r--tests/apis/add_files_replace/src/main.c7
-rw-r--r--xmake/rules/utils/replace/xmake.lua5
3 files changed, 10 insertions, 4 deletions
diff --git a/tests/apis/add_files_replace/src/config.h b/tests/apis/add_files_replace/src/config.h
new file mode 100644
index 000000000..96d83f651
--- /dev/null
+++ b/tests/apis/add_files_replace/src/config.h
@@ -0,0 +1,2 @@
+#pragma once
+#define VERSION "1.0"
diff --git a/tests/apis/add_files_replace/src/main.c b/tests/apis/add_files_replace/src/main.c
index 8b6ee15b8..d2ac8f8ae 100644
--- a/tests/apis/add_files_replace/src/main.c
+++ b/tests/apis/add_files_replace/src/main.c
@@ -1,10 +1,9 @@
#include <stdio.h>
+#include "config.h"
-#ifndef REPLACED_VALUE
-#define REPLACED_VALUE "original"
-#endif
+#define HELLO "original"
int main(int argc, char** argv) {
- printf("hello %s!\n", REPLACED_VALUE);
+ printf("hello %s, %s!\n", HELLO, VERSION);
return 0;
}
diff --git a/xmake/rules/utils/replace/xmake.lua b/xmake/rules/utils/replace/xmake.lua
index 47340cb1a..da04a0720 100644
--- a/xmake/rules/utils/replace/xmake.lua
+++ b/xmake/rules/utils/replace/xmake.lua
@@ -45,6 +45,11 @@ rule("utils.replace")
-- get the replaced file path
local replacefile = target:autogenfile(sourcefile)
+ -- add the original source directory as includedir for the replaced file,
+ -- so that relative #include paths still work
+ local sourcedir = path.directory(path.absolute(sourcefile))
+ target:fileconfig_add(replacefile, {includedirs = sourcedir})
+
-- replace the sourcefile in the build sourcebatch,
-- so that the compiler uses the replaced file instead of the original
for _, sourcebatch in pairs(target:sourcebatches()) do