From ae4040a7eb9345b8f534e3b304e97ac8e21cfdc1 Mon Sep 17 00:00:00 2001 From: Sven Fischer Date: Tue, 5 Dec 2023 11:58:01 +0100 Subject: [PATCH] Make compile-commands generation conditional To not "pollute" projects with the compile-commands.json link if they include libssh as a subproject (e.g. with add_subdirectory()), check if libssh is the root project and only create the link in this case. Signed-off-by: Sven Fischer Reviewed-by: Sahana Prasad Reviewed-by: Jakub Jelen --- CMakeLists.txt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 44e08edb..5885770d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -225,10 +225,13 @@ endif (CMAKE_BUILD_TYPE STREQUAL "Coverage") add_custom_target(dist COMMAND ${CMAKE_MAKE_PROGRAM} package_source DEPENDS ${_SYMBOL_TARGET} VERBATIM) -# Link compile database for clangd -execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink - "${CMAKE_BINARY_DIR}/compile_commands.json" - "${CMAKE_SOURCE_DIR}/compile_commands.json") +get_directory_property(hasParent PARENT_DIRECTORY) +if(NOT(hasParent)) + # Link compile database for clangd if we are the master project + execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink + "${CMAKE_BINARY_DIR}/compile_commands.json" + "${CMAKE_SOURCE_DIR}/compile_commands.json") +endif() message(STATUS "********************************************") message(STATUS "********** ${PROJECT_NAME} build options : **********")