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

cmake: Export compile_commands.json for all generated code #23618

Closed
sslupsky opened this issue Mar 19, 2020 · 2 comments
Closed

cmake: Export compile_commands.json for all generated code #23618

sslupsky opened this issue Mar 19, 2020 · 2 comments
Assignees

Comments

@sslupsky
Copy link
Contributor

Presently, if you include the following setting in a CMakeLists.txt file in the project root, the targets listed in the compile_commands.json file generated by CMake are limited to the targets specified in the CMakeLists.txt file.

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

I would prefer that the compile_commands.json file also include all the compiled code for Zephyr (the drivers, kernel, subsys, etc). There reason is that I can configure MS VSCode to read the compile_commands.json file and configure its intellisense feature to highlight coding errors.

I tried editing the CMakeLists.txt files in the following Zephyr tree subfolders:
arch/arm
boards
drivers
kernel
soc
subsys

This improved things quite a bit and many of the Zephyr targets now appear in the compile_commands.json file. However, there are a few that still do not appear. For instance, sam0_rtc_timer.c is not included as a target. Neither is wdt_sam0.c. I know these are being compiled because my application uses them and I have debugged them. There are likely a few other files that are not included as well, I have not yet performed an exhaustive analysis.

Is there another way to inform CMake so that a complete set of targets will be included in compile_commands.json?

@mbolivar-nordic
Copy link
Contributor

Is there another way to inform CMake so that a complete set of targets will be included in compile_commands.json?

There are several examples in the west documentation that I believe do what you are asking about:

https://docs.zephyrproject.org/latest/guides/west/build-flash-debug.html#permanent-cmake-arguments

@sslupsky
Copy link
Contributor Author

sslupsky commented Mar 22, 2020

Thank you @mbolivar

I was able to get export setting to stick by adding

-DCMAKE_EXPORT_COMPILE_COMMANDS=1

to the west command line.

There is still a VSCode CMake-Tools issue where resolving the location of a header file can result in multiple paths. I have noticed this happens when there are headers with no target. That is, there is a <kernel.h> but there is no target "kernel.c". CMake-Tools attempts to look up "kernel.c" when I try to locate <kernel.h> Since "kernel.c" is not a target in compile_commands.json, the c/cpp extension defaults to another search process and comes up with multiple paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants