Skip to content
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

支持强制包含 #4101

Closed
1 of 2 tasks
jingkaimori opened this issue Aug 21, 2023 · 9 comments
Closed
1 of 2 tasks

支持强制包含 #4101

jingkaimori opened this issue Aug 21, 2023 · 9 comments

Comments

@jingkaimori
Copy link
Contributor

jingkaimori commented Aug 21, 2023

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

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

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

描述可能的解决方案

  • 定义域下为 target 添加set_forceinclude接口:
  • vscode 插件根据上述接口修改c_cpp_properties.json文件
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
Copy link

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


Title: supports mandatory inclusion

waruqi added a commit that referenced this issue Aug 21, 2023
waruqi added a commit that referenced this issue Aug 21, 2023
@waruqi
Copy link
Member

waruqi commented Aug 21, 2023

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

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

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

@waruqi waruqi added this to the v2.8.2 milestone Aug 21, 2023
@Issues-translate-bot
Copy link

Issues-translate-bot commented Aug 21, 2023

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
Copy link
Member

waruqi commented Aug 21, 2023

改了下,再试试

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
Copy link

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
Copy link
Contributor Author

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

@Issues-translate-bot
Copy link

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
Copy link
Member

waruqi commented Aug 21, 2023

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

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

@Issues-translate-bot
Copy link

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.

waruqi added a commit that referenced this issue Aug 21, 2023
@waruqi waruqi closed this as completed Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants