xmake-io / xmake

🔥 A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
10.05k stars 787 forks source link

支持强制包含 #4101

Closed jingkaimori closed 1 year ago

jingkaimori commented 1 year ago

你在什么场景下需要该功能?

墨干项目通过强制包含来引入配置文件,gcc 和 msvc 都支持强制包含选项,而且vscode的C++插件提供了强制包含的配置项。

xmake 需要引入新的配置项,并且改进 msvc 插件,从而生成对应的强制包含信息

描述可能的解决方案

target("test")
    set_forceinclude({"src/config.h", "src/config_after.h"})

描述你认为的候选方案

目前的解决方案:

if is_plat("windows") then
    add_cxxflags("-FI " .. path.absolute("$(buildir)\\L1\\config.h"))
else
    add_cxxflags("-include $(buildir)/L1/config.h")
end

其他信息

No response

Issues-translate-bot commented 1 year ago

Bot detected the issue body's language is not English, translate it automatically.


Title: supports mandatory inclusion

waruqi commented 1 year ago

加了 add_cincludes/add_cxxincludes,但不能指定路径,你只能配合 add_includedirs 来定位。。

add_cincludes("config.h")
add_includedirs("$(buildir)/L1")
xmake update -s github:xmake-io/xmake#includes

edit: 还有点问题,需要再改改

Issues-translate-bot commented 1 year ago

Bot detected the issue body's language is not English, translate it automatically.


Added add_cincludes/add_cxxincludes, but you cannot specify the path, you can only locate it with add_includedirs. .

add_cincludes("config.h")
add_includedirs("src")
waruqi commented 1 year ago

改了下,再试试

add_forceincludes("config.h")
add_includedirs("$(buildir)/L1")

默认 add_forceincludes 匹配 c/c++/objc。如果仅仅只想匹配 c++ 可以

add_forceincludes("config.h", {sourcekinds = "cxx"})

如果想同时匹配多个源文件类型,可以

add_forceincludes("config.h", {sourcekinds = {"cxx", "mxx"}})
Issues-translate-bot commented 1 year ago

Bot detected the issue body's language is not English, translate it automatically.


Change it and try again

add_force includes("config.h")
add_includedirs("$(buildir)/L1")

By default add_forceincludes matches c/c++/objc. If you only want to match c++ you can

add_force includes("config.h", {sourcekinds = "cxx"})

If you want to match multiple source file types at the same time, you can

add_force includes("config.h", {sourcekinds = {"cxx", "mxx"}})
jingkaimori commented 1 year ago

现在能跑通了,add_forceincludes添加的各个文件出现在命令行的顺序能控制吗?

Issues-translate-bot commented 1 year ago

Bot detected the issue body's language is not English, translate it automatically.


Now it works. Can the order in which the files added by add_forceincludes appear on the command line be controlled?

waruqi commented 1 year ago

现在能跑通了,add_forceincludes添加的各个文件出现在命令行的顺序能控制吗?

按添加的先后顺序,就跟 add_defines add_links 什么的类似。

Issues-translate-bot commented 1 year ago

Bot detected the issue body's language is not English, translate it automatically.


It works now. Can the order of the files added by add_forceincludes appear on the command line be controlled?

According to the order of addition, it is similar to add_defines add_links or something.