admin管理员组文章数量:1390501
I have a CMake that targets Arduino. This involves some command line options to the compiler that clangd is not familiar with.
This would give me an error at the top of any file:
Unknown argument: '-fno-tree-scev-cprop'clang(drv_unknown_argument)
I created a .clangd
file in the root of my repo, with the following content:
CompileFlags:
Remove: [-fno-tree-scev-cprop, -fno-split-wide-types, -mmcu=]
This removes the error from files in my repo, but for files included from outside the error is still generated. For example if I open Arduino.h
, I see the error still:
How can I remove these flags from ALL compile commands, regardless of file? Obviously, I could edit compile_commands.json
, but that doesn't seem like the right solution.
I have a CMake that targets Arduino. This involves some command line options to the compiler that clangd is not familiar with.
This would give me an error at the top of any file:
Unknown argument: '-fno-tree-scev-cprop'clang(drv_unknown_argument)
I created a .clangd
file in the root of my repo, with the following content:
CompileFlags:
Remove: [-fno-tree-scev-cprop, -fno-split-wide-types, -mmcu=]
This removes the error from files in my repo, but for files included from outside the error is still generated. For example if I open Arduino.h
, I see the error still:
How can I remove these flags from ALL compile commands, regardless of file? Obviously, I could edit compile_commands.json
, but that doesn't seem like the right solution.
2 Answers
Reset to default 0include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-std=c++0x" "-fno-tree-scev-cprop" NOTREE_SUPPORTED)
if(NOTREE_SUPPORTED)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-tree-scev-cprop")
endif()
You can use check_cxx_compiler_flag
in your cmake to see whether it's available, and then set the flag if it is...
Clangd config options are applied on a per-file basis to files opened in an editor, by searching for .clangd
files in the ancestor directories of the file being opened. In addition, the user config file is also used.
With that in mind, I can think of two methods. Let's suppose Arduino.h
is located at /a/b/c/Arduino.h
, and the entire subdirectory /a/b
contains header files used by this cross compiler.
Method 1
Create /a/b/.clangd
containing:
CompileFlags:
Remove: [-fno-tree-scev-cprop, -fno-split-wide-types, -mmcu=]
Method 2
Add to your user config file (e.g. ~/.config/clangd/config.yaml
) the following:
If:
PathMatch: /a/b/.*
CompileFlags:
Remove: [-fno-tree-scev-cprop, -fno-split-wide-types, -mmcu=]
Note that the way If
works is that these lines need to be separated from any other contents of the user config file by a ---
line (so that the If
only applies to this CompileFlags
section and not others).
本文标签: cHow to ignore unknown options in Clangd for files outside the project structureStack Overflow
版权声明:本文标题:c++ - How to ignore unknown options in Clangd for files outside the project structure? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744592786a2614595.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
jq
oneliner. :P – HolyBlackCat Commented Mar 16 at 16:49