summaryrefslogtreecommitdiff
path: root/contrib/buildsystems/CMakeLists.txt
diff options
context:
space:
mode:
authorMatthew Rogers <mattr94@gmail.com>2021-06-06 12:02:53 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-06-11 06:23:17 (GMT)
commit409047a2b3fabb6a5f3fdbb28d93a5db3a7de28c (patch)
tree9f783b6ef75016bd0b331b9955222ca2a724acb5 /contrib/buildsystems/CMakeLists.txt
parentcd0a852981162fb77f9fac68f231e3d41a99c993 (diff)
downloadgit-409047a2b3fabb6a5f3fdbb28d93a5db3a7de28c.zip
git-409047a2b3fabb6a5f3fdbb28d93a5db3a7de28c.tar.gz
git-409047a2b3fabb6a5f3fdbb28d93a5db3a7de28c.tar.bz2
cmake: create compile_commands.json by default
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> Acked-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'contrib/buildsystems/CMakeLists.txt')
-rw-r--r--contrib/buildsystems/CMakeLists.txt4
1 files changed, 4 insertions, 0 deletions
diff --git a/contrib/buildsystems/CMakeLists.txt b/contrib/buildsystems/CMakeLists.txt
index 083a3bf..67b722f 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})