git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 2/3] cmake: create compile_commands.json by default

From
MGMatthew Rogers via GitGitGadget <gitgitgadget@gmail.com>
Date
Jun 6, 2021, 12:02 UTC
Message-ID
<a3b5eef5418861ee5c008aef0cdab3448b8fc5d9.1622980974.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.970.v2.git.1622980974.gitgitgadget@gmail.com>
From: Matthew Rogers <mattr94@gmail.com>

Some users have expressed interest in a more "batteries included" way of building via CMake[1], and a big part of that is providing easier access to tooling external tools.

A straightforward way to accomplish this is to make it as simple as possible is to enable the generation of the compile_commands.json file, which is supported by many tools such as: clang-tidy, clang-format, sourcetrail, etc.

This does come with a small run-time overhead during the configuration step (~6 seconds on my machine):

    Time to configure with CMAKE_EXPORT_COMPILE_COMMANDS=TRUE
    real    1m9.840s
    user    0m0.031s
    sys     0m0.031s
    Time to configure with CMAKE_EXPORT_COMPILE_COMMANDS=FALSE
    real    1m3.195s
    user    0m0.015s
    sys     0m0.015s

This seems like a small enough price to pay to make the project more accessible to newer users. Additionally there are other large projects like llvm [2] which has had this enabled by default for >6 years at the time of this writing, and no real negative consequences that I can find with my search-skills.

NOTE: That the compile_commands.json is currently produced only when
using the Ninja and Makefile generators.  See The CMake documentation[3]
for more info.

1: https://lore.kernel.org/git/CAOjrSZusMSvs7AS-ZDsV8aQUgsF2ZA754vSDjgFKMRgi_oZAWw@mail.gmail.com/ 2: https://github.com/llvm/llvm-project/commit/2c5712051b31b316a9fc972f692579bd8efa6e67 3: https://cmake.org/cmake/help/latest/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html

Signed-off-by: Matthew Rogers <mattr94@gmail.com>
---
 contrib/buildsystems/CMakeLists.txt | 4 ++++
 1 file changed, 4 insertions(+)
diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt
index be6d9659c387..399a3cd6c071 100644
--- a/contrib/buildsystems/CMakeLists.txt
+++ b/contrib/buildsystems/CMakeLists.txt
@@ -57,6 +57,10 @@ if(NOT WIN32)
 	set(USE_VCPKG OFF CACHE BOOL FORCE)
 endif()
 
+if(NOT DEFINED CMAKE_EXPORT_COMPILE_COMMANDS)
+	set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
+endif()
+
 if(USE_VCPKG)
 	set(VCPKG_DIR "${CMAKE_SOURCE_DIR}/compat/vcbuild/vcpkg")
 	if(NOT EXISTS ${VCPKG_DIR})
-- 
gitgitgadget
Previous: Matthew Rogers via GitGitGadgetNext: Matthew Rogers via GitGitGadget
Message 24 of 31 in “Make CMake work out of the box”
  1. 0/3 Make CMake work out of the boxMatthew Rogers via GitGitGadget, Jun 4, 2021
  2. 1/3 cmake: add knob to disable vcpkgMatthew Rogers via GitGitGadget, Jun 4, 2021
  3. Eric SunshineJun 4, 2021
  4. Matt RogersJun 4, 2021
  5. Sibi SiddharthanJun 4, 2021
  6. Matt RogersJun 5, 2021
  7. Sibi SiddharthanJun 6, 2021
  8. 3/3 cmake: add warning for ignored MSGFMT_EXEMatthew Rogers via GitGitGadget, Jun 4, 2021
  9. Eric SunshineJun 4, 2021
  10. 2/3 cmake: create compile_commands.json by defaultMatthew Rogers via GitGitGadget, Jun 4, 2021
  11. Eric SunshineJun 4, 2021
  12. Sibi SiddharthanJun 4, 2021
  13. Matt RogersJun 5, 2021
  14. Sibi SiddharthanJun 6, 2021
  15. Bagas SanjayaJun 5, 2021
  16. Matt RogersJun 5, 2021
  17. Johannes SchindelinJun 10, 2021
  18. Philip OakleyJun 18, 2021
  19. Johannes SchindelinJun 18, 2021
  20. Philip OakleyJun 18, 2021
  21. Johannes SchindelinJun 22, 2021
  22. 0/3 Make CMake work out of the boxMatthew Rogers via GitGitGadget, Jun 6, 2021
  23. 1/3 cmake: add knob to disable vcpkgMatthew Rogers via GitGitGadget, Jun 6, 2021
  24. 2/3 cmake: create compile_commands.json by defaultMatthew Rogers via GitGitGadget, Jun 6, 2021
  25. 3/3 cmake: add warning for ignored MSGFMT_EXEMatthew Rogers via GitGitGadget, Jun 6, 2021
  26. Junio C HamanoJun 7, 2021
  27. Johannes SchindelinJun 10, 2021
  28. Philip OakleyJun 18, 2021
  29. Philip OakleyJun 18, 2021
  30. Johannes SchindelinJun 10, 2021
  31. Junio C HamanoJun 11, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.