Improve clangd support

clangd is a very useful tool, serving as a Language Server for C/C++,
helping non-IDE editors tremendously.
With these tweaks, it works flawlessly on my setup.

Add a .clangd config file to exclude the `-mno-direct-extern-access`
flag which works fine on gcc but not on clang.
Also tell CMake to export a thing called "compile commands", which is
essentially a JSON file detailing all the commands used in compilation,
so that clangd can correctly process headers and allow you to jump
between definitions, uses and whatnot.
Finally, adds `.cache/clangd` to the gitignore file.

Signed-off-by: tmpod <tom@tmpod.dev>
This commit is contained in:
tmpod 2024-08-06 18:10:04 +01:00
parent 56f5ed6a88
commit c6d8adc2fd
No known key found for this signature in database
GPG key ID: AB0B0A92F2455D82
3 changed files with 9 additions and 0 deletions

4
.clangd Normal file
View file

@ -0,0 +1,4 @@
CompileFlags:
Remove:
# clang has an issue with this flag, while gcc does not
- "-mno-direct-extern-access"

3
.gitignore vendored
View file

@ -188,3 +188,6 @@ screenshots/
android/src/google/play/listings/
keywords/
iphone/metadata/**/keywords.txt
# clangd cache
.cache/clangd/

View file

@ -11,6 +11,8 @@ set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# Fixes warning ld: warning: ignoring duplicate libraries on Mac and Windows.
if (POLICY CMP0156)
cmake_policy(SET CMP0156 NEW)