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).
jq
oneliner. :P – HolyBlackCat Commented Mar 16 at 16:49