From 49cb790b9f738fe15cecf88af5378896ce788566 Mon Sep 17 00:00:00 2001 From: Jonathan Gopel Date: Tue, 27 Oct 2020 21:30:59 -0600 Subject: [PATCH] :new: [CMake] Enable generation of compile_commands.json Problem: - `compile_commands.json` is not being generated, which hurts editor integration with tooling. Solution: - Generate the `compile_commands.json` file with CMake, if the CMake version is sufficient. --- CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index f21cf456..4fa0694e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,6 +5,11 @@ if(${CMAKE_VERSION} VERSION_LESS 3.12) cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) endif() +# Enable generation of compile_commands.json if the CMake version is high enough +if(${CMAKE_VERSION} VERSION_GREATER_EQUAL 3.5) + set(CMAKE_EXPORT_COMPILE_COMMANDS ON) +endif() + # Determine if fmt is built as a subproject (using add_subdirectory) # or if it is the master project. set(MASTER_PROJECT OFF)