-
Notifications
You must be signed in to change notification settings - Fork 622
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow to generate a compilation database #1064
Allow to generate a compilation database #1064
Conversation
Makefile
Outdated
GENERATE_COMPILATION_DATABASE ?= no | ||
|
||
ifeq ($(GENERATE_COMPILATION_DATABASE),yes) | ||
compdb_check = $(shell $(CC) $(ALL_CFLAGS) \ | ||
-c -MJ /dev/null \ | ||
-x c /dev/null -o /dev/null 2>&1; \ | ||
echo $$?) | ||
ifneq ($(compdb_check),0) | ||
override GENERATE_COMPILATION_DATABASE = no | ||
$(warning GENERATE_COMPILATION_DATABASE is set to "yes", but your compiler does not \ | ||
support generating compilation database entries) | ||
endif | ||
else | ||
ifneq ($(GENERATE_COMPILATION_DATABASE),no) | ||
$(error please set GENERATE_COMPILATION_DATABASE to "yes" or "no" \ | ||
(not "$(GENERATE_COMPILATION_DATABASE)")) | ||
endif | ||
endif | ||
|
||
compdb_dir = compile_commands | ||
ifeq ($(GENERATE_COMPILATION_DATABASE),yes) | ||
compdb_file = $(compdb_dir)/$(subst /,-,[email protected]) | ||
compdb_args = -MJ $(compdb_file) | ||
else | ||
compdb_args = | ||
endif | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this part at line 88 to make $(missing_compdb_dir)
work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, thanks! I'm not sure why because I don't see where the order would matter but that's okay 🤷
Taken from Git's Makefile. Keep in mind that not all compilers support the -MJ option. Clang does, so this command should give you a fresh compile_commands.json make CC=clang GENERATE_COMPILATION_DATABASE=yes clean all-debug
0243059
to
c456645
Compare
This is useful for some Clang-based tools, in particular language servers like clangd or ccls.
I mostly took this mostly from Git's Makefile. The awkward if-statement
is because the "missing_compdb_dir" trick that Git uses didn't work for
some reason.
Keep in mind that not all compilers support the -MJ option. Clang does, so this
command should give you a fresh compile_commands.json