diff --git a/CMakeLists.txt b/CMakeLists.txt index f8a4383..d2f4b68 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,30 @@ if(POLICY CMP0091) cmake_policy(SET CMP0091 NEW) endif() +# Enable JSON compilation database generation +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) + +# Symbolic link to the compile_commands.json in root directory for tools or copy for Windows +if(CMAKE_EXPORT_COMPILE_COMMANDS) + if(WIN32) + # On Windows, instead of creating a symlink, copy the file + add_custom_target( + create_compile_commands_copy ALL + COMMAND ${CMAKE_COMMAND} -E copy + ${CMAKE_BINARY_DIR}/compile_commands.json + ${CMAKE_SOURCE_DIR}/compile_commands.json + ) + else() + # On non-Windows systems, create the symbolic link + add_custom_target( + create_compile_commands_symlink ALL + COMMAND ${CMAKE_COMMAND} -E create_symlink + ${CMAKE_BINARY_DIR}/compile_commands.json + ${CMAKE_SOURCE_DIR}/compile_commands.json + ) + endif() +endif() + # Platform detection if(WIN32 OR "${CMAKE_SYSTEM}" MATCHES "Windows") set(WINDOWS TRUE)