-
-
Notifications
You must be signed in to change notification settings - Fork 822
New issue
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
configvar_check 能否依赖另一个 configvar_check #5944
Comments
Title: Can configvar_check depend on another configvar_check? |
如果要互相依赖,只有这种方式,而且也没见多麻烦,下面你提的解决方式,也没见简单多少,好像更复杂了。 脚本域,你随意搞,觉得繁琐,自己走 function 或者 module 封装复用下就行了。 |
If you want to rely on each other, this is the only way, and it's not too troublesome. The solution you mentioned below is not much simpler, it seems to be more complicated. You can do whatever you want with the script domain. If it seems cumbersome, just use function or module to encapsulate and reuse it. |
@waruqi |
@waruqi |
尝试了一下,on_config 正好就在 option 的 check 之后,generate_configfiles 之前,直接在 on_config 里取 configvar 并设置新的 configvar 就能影响到 configfile 的生成,后面我自己封装一下和外部的 configvar_check_xxx 一致就能达到我想要的效果了 xmake.lua includes("@builtin/check")
add_rules("mode.debug", "mode.release")
configvar_check_cincludes("HAVE_SYS_SOCKET_H", "sys/socket.h")
configvar_check_cincludes("HAVE_WINSOCK2_H", "winsock2.h")
configvar_check_cincludes("HAVE_WS2TCPIP_H", "ws2tcpip.h")
target("xxx")
add_files("main.c")
add_configfiles("config.h.in")
on_config(function (target)
local variables = target:get("configvar") or {}
for _, opt in ipairs(target:orderopts()) do
for name, value in pairs(opt:get("configvar")) do
if variables[name] == nil then
variables[name] = table.unwrap(value)
variables["__extraconf_" .. name] = opt:extraconf("configvar." .. name, value)
end
end
end
print(variables)
local common_includes = {}
if variables["HAVE_SYS_SOCKET_H"] then
table.insert(common_includes, "sys/socket.h")
end
if variables["HAVE_WINSOCK2_H"] then
table.insert(common_includes, "winsock2.h")
end
if variables["HAVE_WS2TCPIP_H"] then
table.insert(common_includes, "ws2tcpip.h")
end
if target:has_cfuncs("freeaddrinfo", {includes = common_includes}) then
target:set("configvar", "HAVE_FREEADDRINFO", 1)
end
end) config.h.in ${define HAVE_SYS_SOCKET_H}
${define HAVE_WINSOCK2_H}
${define HAVE_FREEADDRINFO}
${define HAVE_WS2TCPIP_H} windows 下的效果 > checking for c includes(winsock2.h, ws2tcpip.h)
> checking for c funcs(freeaddrinfo)
> checking for c snippet(has_cfuncs)
generating config.h.in to build\config.h ..
checking for git ... ok
> replace HAVE_SYS_SOCKET_H -> /* #undef HAVE_SYS_SOCKET_H */
> replace HAVE_WINSOCK2_H -> #define HAVE_WINSOCK2_H 1
> replace HAVE_FREEADDRINFO -> #define HAVE_FREEADDRINFO 1
> replace HAVE_WS2TCPIP_H -> #define HAVE_WS2TCPIP_H 1 |
你在什么场景下需要该功能?
cmake 里有一些 check 可以直接获得到检查结果
在转换到 xmake 时,在 on_config 里需要不停的 target:check 和判断非常的麻烦
描述可能的解决方案
描述你认为的候选方案
上面是多次执行
_instance:_do_check()
的想法,不知道是否描述清楚了,如果有更好方案请指出其他信息
No response
The text was updated successfully, but these errors were encountered: