Skip to content

Commit

Permalink
fix: configure compilation database for clangd when using cmake presets
Browse files Browse the repository at this point in the history
  • Loading branch information
abdes committed Dec 7, 2021
1 parent e7b9c07 commit 7493c24
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
8 changes: 8 additions & 0 deletions .clangd.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# We need to configure the location of the compilation database in this file
# and not in vscode `.settings` until we have a way to get the cmake build
# directory or preset name as a subsititution variable.
#
# See https://github.com/clangd/vscode-clangd/issues/48

CompileFlags:
CompilationDatabase: "@CMAKE_BINARY_DIR@"
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ out/
.sphinx
.cache

# In this specific project we ignore .clangd as it is dynamycally generated by cmake during the
# configuration stage.
.clangd

# Generated files inside source tree
doc/conf.py

Expand Down
6 changes: 2 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,7 @@
// pch optimized location (memory or disk, selecting memory will increase memory overhead, but will improve performance)
"--pch-storage=memory",
// After adding this item, placeholders will be provided for the parameters when completing the function. After typing, press Tab to switch to the next placeholder or even the end of the function
"--function-arg-placeholders",
// compelie_ Directory location of the commands.json file (relative to the workspace, the file generated by CMake is in the build folder by default, so it is set to build)
"--compile-commands-dir=build"
"--function-arg-placeholders"
],
// Automatically detect Cland updates
"clangd.checkUpdates": true,
Expand All @@ -205,6 +203,7 @@
"cmake.preferredGenerators": [
"Ninja"
],
"cmake.allowCommentsInPresetsFile": true,
// Automatically extract submissions from the default remote library of the current Git repository
"git.autofetch": true,
// Confirm before synchronizing Git repository
Expand Down Expand Up @@ -288,5 +287,4 @@
"cmakeFormat.args": [
"--config-file=${workspaceFolder}/.cmake-format.yaml"
],
"cmake.allowCommentsInPresetsFile": true,
}
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,14 @@ endif()
# Generate version-header
configure_file(templates/version.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/asap/asap-version.h)

# Generate a clangd configuration file that points to the compilation database in the cmake build
# directory. We need to do this as the build directory is different for every preset and can be
# different as well when the user decides to build somewhere else.
# Currently we cannot configure this properly in vscode settings.
# See https://github.com/clangd/vscode-clangd/issues/48
configure_file(.clangd.in ${CMAKE_SOURCE_DIR}/.clangd @ONLY)


# --------------------------------------------------------------------------------------------------
# Test targets
# --------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit 7493c24

Please sign in to comment.