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

Generate compile_commands.json for clangd #381

Open
wants to merge 6 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ cmake-build-*/
.kdev?/
*.kdev?

# clangd LSP files
compile_commands.json
**.cache/clangd

# File-based project format:
*.iws

Expand Down
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
cmake_minimum_required(VERSION 3.20.0)
project(ImpactX VERSION 23.06)

# generate compile_commands.json
if(CMAKE_SOURCE_DIR STREQUAL PROJECT_SOURCE_DIR)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# and place it in the source directory https://stackoverflow.com/a/60910583
add_custom_target(
copy-compile-commands ALL
${CMAKE_COMMAND} -E copy_if_different
${CMAKE_BINARY_DIR}/compile_commands.json ${PROJECT_SOURCE_DIR})
Copy link
Member

@ax3l ax3l Jun 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has to be guarded for all build generators that are not GNUmake or Ninja:
https://cmake.org/cmake/help/latest/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html

Note

This option is implemented only by Makefile Generators and Ninja Generators. It is ignored on other generators.

This option currently does not work well in combination with the UNITY_BUILD target property or the CMAKE_UNITY_BUILD variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a guard to only generate compile_commands.json for Unix Makefiles and Ninja generators.

endif()

include(${ImpactX_SOURCE_DIR}/cmake/ImpactXFunctions.cmake)

# In-source tree builds are messy and can screw up the build system.
Expand Down