Skip to content

Commit

Permalink
adds clangd to makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
BlakeFreer committed Apr 4, 2024
1 parent c21e34d commit cac3109
Show file tree
Hide file tree
Showing 989 changed files with 39 additions and 799,475 deletions.
2 changes: 0 additions & 2 deletions .clangd

This file was deleted.

4 changes: 3 additions & 1 deletion firmware/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
**/build/
**/build/
/.clangd
/.cache
12 changes: 9 additions & 3 deletions firmware/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,23 @@ PROJECT =
BUILD = build
BUILD_DIR = $(BUILD)/$(PROJECT)/$(PLATFORM)
CUBEMX_DIR := projects/$(PROJECT)/platforms/$(PLATFORM)/cubemx
GENERATOR = -G"Unix Makefiles"

COMPILE_COMMANDS_DEST = $(BUILD)/compile_commands.json

build: FORCE
cmake -B $(BUILD_DIR) -S. -G"Unix Makefiles" -DPROJECT=$(PROJECT) -DPLATFORM=$(PLATFORM) -D CMAKE_EXPORT_COMPILE_COMMANDS=1
cmake --build $(BUILD_DIR)
cmake -B $(BUILD_DIR) -S. $(GENERATOR) -DPROJECT=$(PROJECT) -DPLATFORM=$(PLATFORM) $(COMPILE_COMMANDS_FLAGS)

@echo Copying compile_commands.json to $(BUILD) for clangd.
cp $(BUILD_DIR)/compile_commands.json $(COMPILE_COMMANDS_DEST)
@# Ensure the .clangd file exists
touch .clangd

cmake --build $(BUILD_DIR)

clean: FORCE
rm -rf $(BUILD_DIR)
rm $(COMPILE_COMMANDS_DEST)
rm -f $(COMPILE_COMMANDS_DEST)

deepclean: clean
ifeq ($(findstring stm32,$(PLATFORM)),stm32)
Expand Down
30 changes: 27 additions & 3 deletions firmware/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,32 @@ The following dependecies must be installed __and added to your PATH variable.__
* Select the 6.8.1 version in the __Get Software__ section.
* Verify by running `stm32cubemx`. The application should open.

* clangd - [link](https://clangd.llvm.org/installation)
* clangd 16.0.2 - [link](https://github.com/clangd/clangd/releases/tag/16.0.2)
* Download and extract `clang-<platform>-16.0.2.zip`
* This is our "official" C/C++ language server.
* You should also install the __clangd__ extension for your IDE.
* If you have the Microsoft __C/C++__ extension installed, disable it for the `racecar` workspace.
* Verify with ``clangd --version``.

## __clangd__ Setup

1. Install the __clangd__ vscode extension.

* If you have the Microsoft __C/C++__ extension installed, disable it for the `racecar` workspace.

2. Go to the __clangd__ extension settings and provide the full path to `clangd.exe`. This execuable is in the `bin/` subdirectory of the extracted folder.

3. Create an empty file named `.clangd` in the `firmware/` directory.
* This file indicates the "root" directory of the project, so it will look for a `compile_commands.json` file in `firmware/build/`. This json file is created by CMake in the project build directory (ex `build/DemoProject/stm32f767`) and copied to `build/` by the Makefile.
* You may optionally configure __clangd__ with this file. See <https://clangd.llvm.org/config>
* On windows, I had to use the following configuration to help __clangd__ find system header files.

```yaml
If:
PathMatch: .*/windows/.*

CompileFlags:
Add: --target=x86_64-w64-mingw64
```
### Using __clangd__
Whenever you build a project with the Makefile, __clangd__ will see the new `build/compile_commands.json` and immediately update the IDE's include paths. This means that, when switching which project or platform you are developing for, simply build the project and your development environment will be automatically prepared.
Loading

0 comments on commit cac3109

Please sign in to comment.