Page 1 of 1
Using clangd for a custom Makefile project
Posted: Thu Oct 20, 2022 12:50 pm
by reinier85
Good morning guys,
I was hoping you guys could point me in the right direction, since I have not yet fully connected all the dots.
Problem statement: I have to maintain an ancient, mainly C project which in the past was simply developed using vi and Makefiles, which compiled with gcc (actually g++, because there are some C++ files). Now I am busy constructing this project using CodeLite and one of my main desires is to have a working language server using clangd to easily navigate and explore the code base. I am currently struggling to configure clangd to find all the project headers.
What I have done so far:
- create a few Codelite projects to organise the main application suite and the libraries
- there are already old school Makefiles for the entire project, so in Codelite I am using a custom build (Project settings -> Customize -> Custom Build)
- I read the LSP plugin documentation: https://docs.codelite.org/plugins/lsp/
- I started to read the clangd documentation (I am new to this as well): https://clangd.llvm.org/config
- I played around with the clangd server settings (Plugins -> Language Server -> Settings -> clangd), but did not make much progress
- I tried automatically creating the compile_commands.json file (Settings -> Code Completion -> Generate compile_commands.json file), did not seem to work
- I tried to manually create the compile_commands.json and compile_flags.txt, but I am not too sure where to place them
Questions:
- what is in general the best practice for configuring clangd with Codelite?
- in my particular case (gcc + custom Makefiles), how should I create compile_commands.json and compile_flags.txt? I saw a tool called bear that helps with this
- do I need both of these files?
- how do I configure it on a project basis?
- do I need to do configure clangd outside of CodeLite, e.g. as suggested here: https://clangd.llvm.org/config
Sorry for all the questions, but I hope you guys can help me out!
Thanks in advance!
Re: Using clangd for a custom Makefile project
Posted: Thu Oct 20, 2022 6:20 pm
by Jarod42
You need only one of compile_commands.json and compile_flags.txt
If I remember correctly compile_flags.txt take precedence when found in same directory.
That file should be placed in source directory or any of its parent (the first one found is used).
Codelite generate them normally near project/workspace (I don't used custom Makefiles, so don't know the behavior for that),
so not necessary to the correct place depending of your directories structure.
clang tooling use also files (.clangd, .clang-format, ...) for per directory (and so potentially per project) options.
,
Re: Using clangd for a custom Makefile project
Posted: Sat Oct 22, 2022 6:16 pm
by eranif
The easiest way is to create a file named (like Jarod42 mentioned) compile_flags.txt
place this file at the root level of your workspace and it should have a content similar to this:
Code: Select all
-I/include/path
-I/another/include/path
-DMACRO=1
-std=c++11
-I/more/include
The easiest way to build this file is to run your makefile once and copy the macros/include paths etc from the output you get in stdout
Re: Using clangd for a custom Makefile project
Posted: Tue Jan 03, 2023 1:31 pm
by oneno
Using gcc and a custom Makefile that compiles in terminal.
What settings are required for codelite workspace to use that custom Makefile?
Not clear on the previous response.
Makefile and output for make are on pastebin.
Have a workspace and project created in codelite.
After compiling, the Makefile is overwritten and no errors reported.
But, the compile does not produce the executable.
Re: Using clangd for a custom Makefile project
Posted: Wed Jan 04, 2023 2:59 am
by oneno
It appears there is a bug in the codelite configuration.
To resolve the issue, all codelite configuration files were deleted via file manager (Thunar on linux) via Ctrl+h and deleting the hidden .codelite folder.
After;
- launched codelite IDE
- dragged the project folder in codelite just above where it says "DRAG AND DROP A FOLDER HERE" and choosing C++. That created the workspace and project.
- buiilt the project and compiled the executable which ran as required.
But noticed the Makefile was overwritten. Before and after of the Makefile are on pastebin
So have codelite compile the source as required. But Makefile is being overwritten ?