Swift/Ninja: Include all files in module in compile_commands.json
The exported compile commands by CMAKE_EXPORT_COMPILE_COMMANDS does not include all source files in the module in the exported command. As a result, LSP reports errors about unknown typenames and missing functions when those types and functions are declared in different files in the same module.
cmake_minimum_required(VERSION 3.28)
if(POLICY CMP0157)
cmake_policy(SET CMP0157 NEW)
endif()
project(Test LANGUAGES Swift)
add_library(TestLib a.swift b.swift)
CMake currently emits
[
{
"directory": "/tmp/test3/build",
"command": "swiftc -j 10 -num-threads 10 -c ... -incremental /tmp/test3/a.swift",
"file": "/tmp/test3/a.swift",
"output": "CMakeFiles/TestLib.dir/a.swift.o"
},
{
"directory": "/tmp/test3/build",
"command": "swiftc -j 10 -num-threads 10 -c ... -incremental /tmp/test3/b.swift",
"file": "/tmp/test3/b.swift",
"output": "CMakeFiles/TestLib.dir/b.swift.o"
}
]
The output should be
[
{
"directory": "/tmp/test3/build",
"command": "swiftc -j 10 -num-threads 10 -c ... -incremental /tmp/test3/a.swift /tmp/test3/b.swift",
"file": "/tmp/test3/a.swift",
"output": "CMakeFiles/TestLib.dir/a.swift.o"
},
{
"directory": "/tmp/test3/build",
"command": "swiftc -j 10 -num-threads 10 -c ... -incremental /tmp/test3/a.swift /tmp/test3/b.swift",
"file": "/tmp/test3/b.swift",
"output": "CMakeFiles/TestLib.dir/b.swift.o"
}
]