xmake-io / xmake

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

有没有办法实现对指定的文件增加编译选项 #5436

Closed 19317362 closed 1 month ago

19317362 commented 1 month ago

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

使用protobuf时,set_warnings("all", "error") 以后,生成的.pb.cc MSVC编译不过

store.pb.cc(108): error C2220: the following warning is treated as an error
store.pb.cc(108): warning C4125: decimal digit terminates octal escape sequence
store.pb.cc(110): warning C4125: decimal digit terminates octal escape sequence
store.pb.cc(517): warning C4127: conditional expression is constant

描述可能的解决方案

之前在使用cmake时,可以对 pb.cc 文件增加 "/wd4244 /wd4127 /wd4100 /wd4251 /wd4125" 编译选项来解决这个问题。

if (CMAKE_C_COMPILER_ID STREQUAL "MSVC")
set_source_files_properties(store.pb.cc store.pb.cc PROPERTIES COMPILE_FLAGS "/wd4244 /wd4127 /wd4100 /wd4251 /wd4125" )
    # add_definitions("/wd4244 /wd4127")
endif()

使用xmake的话,有没有类似的替代方案

描述你认为的候选方案

No response

其他信息

No response

Issues-translate-bot commented 1 month ago

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


Title: Is there any way to add compilation options to the specified file?

star-hengxing commented 1 month ago
add_files("test/*.c", "test2/test2.c", {defines = "TEST2", languages = "c99", includedirs = ".", cflags = "-O0"})
-- 强制禁用 cxflags,cflags 等编译选项的自动检测
add_files("src/*.c", {force = {cxflags = "-DTEST", mflags = "-framework xxx"}})
Issues-translate-bot commented 1 month ago

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


add_files("test/*.c", "test2/test2.c", {defines = "TEST2", languages ​​= "c99", includedirs = ".", cflags = "-O0"})
-- Forcefully disable automatic detection of compilation options such as cxflags, cflags and so on
add_files("src/*.c", {force = {cxflags = "-DTEST", mflags = "-framework xxx"}})