We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
目前xmake只能用check_c[xx]snippet测试一段代码能否正常编译,但无法比较容易的获取一段代码的输出,只能写一个target在after_build里面获取变量;然而使用这种方法时,必须还要保证先编译运行测试代码,再配置其他target,并且还要调整install时的规则,相当麻烦
例如,在编译时打印size type:
> xmake checking sizeof int: 4 checking sizeof long: 4 checking sizeof long long: 8 ....
就没法很好的实现;测试dll存在性
#include <windows.h> HMODULE m = LoadLibrary("vulkan-1.dll"); FARPROC test = GetProcAddress(m, "vkCreateShader");
也没法很好解决(必须运行时才能发现找到的dll是否符合要求)
还有很多一系列场景都与运行一段代码有关
include("run_c[xx]snippets") local ok, result = run_c[xx]snippets([[snippet]], {cxflags = "..."})
include("check_c[xx]snippets") local ok, result = check_c[xx]snippets([[snippet]], {output = true, cxflags = "..."})
The text was updated successfully, but these errors were encountered:
初步支持了,可以先试下:#1562
添加 {tryrun = true} 和 {output = true} 两个选项给 add_csnippets/add_cxxnippets
{tryrun = true}
{output = true}
option("test") add_csnippets("HAS_INT_4", "return (sizeof(int) == 4)? 0 : -1;", {tryrun = true}) option("test") add_csnippets("INT_SIZE", 'printf("%d", sizeof(int)); return 0;', {output = true, number = true})
tryrun = true
output = true
注: 设置为捕获输出,当前 option 不能再设置其他 snippets
我们也可以通过 is_config 获取绑定到option的输出
if is_config("test", "8") tben -- xxx end
includes("check_csnippets.lua") target("test") set_kind("binary") add_files("*.c") add_configfiles("config.h.in") check_csnippets("HAS_INT_4", "return (sizeof(int) == 4)? 0 : -1;", {tryrun = true}) check_csnippets("INT_SIZE", 'printf("%d", sizeof(int)); return 0;', {output = true, number = true}) configvar_check_csnippets("HAS_LONG_8", "return (sizeof(long) == 8)? 0 : -1;", {tryrun = true}) configvar_check_csnippets("PTR_SIZE", 'printf("%d", sizeof(void*)); return 0;', {output = true, number = true})
设置为 output = true,自动追加 stdio.h 所以不用额外设置
tryrun 模式,最后必须有个 return 0; 或者 return -1; 来返回 main 的 exitcode 用于控制检测状态。
如果额外设置了 number = true,那么会作为数值定义而不是字符串,#define INT_SIZE 4
#define INT_SIZE 4
Sorry, something went wrong.
这里有例子 https://github.com/xmake-io/xmake/blob/master/tests/apis/check_xxx/xmake.lua
No branches or pull requests
你在什么场景下需要该功能?
目前xmake只能用check_c[xx]snippet测试一段代码能否正常编译,但无法比较容易的获取一段代码的输出,只能写一个target在after_build里面获取变量;然而使用这种方法时,必须还要保证先编译运行测试代码,再配置其他target,并且还要调整install时的规则,相当麻烦
例如,在编译时打印size type:
就没法很好的实现;测试dll存在性
也没法很好解决(必须运行时才能发现找到的dll是否符合要求)
还有很多一系列场景都与运行一段代码有关
描述可能的解决方案
描述你认为的候选方案
The text was updated successfully, but these errors were encountered: