[英]Where Do Xcode Default Flags Come From?
動機
Xcode 提供了操作任何需要的編譯器/鏈接器工具鏈的能力,但默認的 Xcode 配置假定 Mac SDK 並添加了許多默認標志,這些標志不會出現在項目本身的任何地方。
如果可以禁用/刪除這些標志,則可以使用 Xcode 的本機構建系統來控制外部編譯器/工具鏈,例如 xtensa-elf-gcc 和周圍工具,同時獲得 Xcode 代碼突出顯示和 clang 分析的好處。 與 Xcode 直接支持的外部 makefile 選項相比,這將是一個非常可取的選項,后者與 Xcode 的其余部分不能很好地集成。
動機 TL; DR
如果可以禁用 Xcode 的默認標志,則 Xcode 可以直接支持 ESP8266 的編譯代碼(使用 CC=xtensa-elf-gcc)。
xtensa-elf-gcc 不支持默認標志(假設為 Mac OS)並阻止其使用。
標志是這不起作用的唯一原因。
例子
最基本的編譯會生成一個帶有這些標志的 clang 命令:
-xc
-arch x86_64
-fmessage-length=0
-fdiagnostics-show-note-include-stack
-fmacro-backtrace-limit=0
-std=gnu99
-Wno-trigraphs
-fpascal 字符串
-O0
-fno-common
-Wno-missing-field-initializers
-Wno-missing-prototypes
-Werror=返回類型
-W文檔
-Wunreachable-code
-Werror=deprecated-objc-isa-usage
-Werror=objc-root-class
-Wno-missing-braces
- 括號
-Wswitch
-Wunused-function
-Wno-unused-label
-Wno-unused-parameter
-Wunused-變量
-Wunused-value
-Wempty-body
-Wconditional-未初始化
-Wno-unknown-pragmas
-Wno-shadow
-Wno-four-char-constants
-Wno-轉換
-Wconstant-轉換
-Wint 轉換
-Wbool-轉換
-Wenum-轉換
-Wshorten-64-to-32
-Wpointer-sign
-Wno-newline-eof
-DDEBUG=1
-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk
-fasm-blocks
-fstrict-別名
-Wdeprecated-declarations
-mmacosx-version-min=10.12
-G
-Wno-sign-conversion
-Winfinite-遞歸
-iquote [生成的文件.hmap]
-I[own-target-headers.hmap]
-I[all-target-headers.hmap]
-iquote [project-headers.hmap]
-I[構建/產品/調試/包含]
-I[Build/Intermediates/libESP8266.build/Debug/libESP8266.build/DerivedSources/x86_64]
-I[Build/Intermediates/libESP8266.build/Debug/libESP8266.build/DerivedSources]
-F[構建/產品/調試]
-MMD
-MT 依賴
-MF [Build/Intermediates/libESP8266.build/Debug/libESP8266.build/Objects-normal/x86_64/main.d]
--serialize-diagnostics [Build/Intermediates/libESP8266.build/Debug/libESP8266.build/Objects-normal/x86_64/main.dia]
-c /Users/asher/Projects/Arduino/libESP8266/main.c
-o [main.o]
顯然,其中一些或多或少是必要的(-c、-o、各種 -Is 等),但大多數應該是完全可選的。
問題
那么它們來自哪里呢? 我試過編輯基本模板,即使減少了所有與 Mac 相關的方面,結果還是一樣。 它們是否以編程方式添加到某處? 如果是這樣,它(大概)在 DevToolsCore 或 IDEFoundation 中?
有一個答案,但它不是一個方便的。
可以在以下位置找到 Xcode 構建實現:
/Applications/Xcode.app/Contents/PlugIns/Xcode3Core.ideplugin
核心定義似乎是從各種插件中的 .xcspec 文件組裝而來的,這些插件可以在以下位置找到:
/Applications/Xcode.app/Contents/PlugIns/Xcode3Core.ideplugin/Contents/SharedSupport/Developer/Library/Xcode/Plug-ins
特別是,對於 clang 和 ld,請查看:
/Applications/Xcode.app/Contents/PlugIns/Xcode3Core.ideplugin/Contents/SharedSupport/Developer/Library/Xcode/Plug-ins/Clang\ LLVM\ 1.0.xcplugin/Contents/Resources/Clang\ LLVM\ 1.0.xcspec
/Applications/Xcode.app/Contents/PlugIns/Xcode3Core.ideplugin/Contents/SharedSupport/Developer/Library/Xcode/Plug-ins/CoreBuildTasks.xcplugin/Contents/Resources/Ld.xcspec
根據您正在尋找的內容,您可能需要挖掘。 如果您正在尋找特定的構建設置,請在 Xcode 構建設置檢查器中找到它,然后搜索相應變量名稱的文本內容。
理論上 .xcspec 文件允許包標識符和繼承描述組合你想要的任何構建結果。 據我所知,這些細節沒有很好的記錄/根本沒有記錄。
由於 Apple 已將 Xcode 插件限制為僅限 Apple,因此可能無法在用戶級別以合理的方式擴展構建定義。 可以修改默認系統,但最終只能得到修改后的版本。
也許其他人已經想出或稍后會想出更多有關如何利用此設置的信息,在這種情況下,我將更新答案以反映我們的最佳知識。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.