Skip to content
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

Merged
merged 1 commit into from
Jan 31, 2021

Conversation

krobelus
Copy link
Contributor

@krobelus krobelus commented Dec 31, 2020

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

make CC=clang GENERATE_COMPILATION_DATABASE=yes clean all-debug

Makefile Outdated Show resolved Hide resolved
Makefile Outdated
Comment on lines 411 to 437
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

Copy link
Collaborator

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.

Copy link
Contributor Author

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
@krobelus krobelus force-pushed the generate-compile_commands.json branch from 0243059 to c456645 Compare December 31, 2020 15:55
@koutcher koutcher merged commit 25f1086 into jonas:master Jan 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants