Sonarlint CMake compile_commands.json in workspace

Hi @Shawn_Marie_Catana and thanks for sharing the question,

If I understand correctly, your question is more about writing a CMakeLists.txt file to build your project. Once you have that, generating the compilation database is as easy as setting CMAKE_EXPORT_COMPILE_COMMANDS.

Please note that you don’t need to write a CMakeLists.txt file just to generate a compilation database file for your project. We have listed many options to generate a compilation database in our docs.

To answer your CMake question, assuming that your example has CMakeLists.txt in the same level of nestedness as Folder 1 and Folder 2, then the glob pattern in your file command needs to account for the directories as far as I can see:

file(GLOB SOURCES "${SOURCE_DIR}/*/*.c")

Please also note that it is generally not recommended to use glob to collect sources. See the official docs.

I hope this helps,

Best regards,
Michael