`compile_commands.json` does not contains c++ modules' information
I am testing c++ modules with llvm-16 and cmake 3.26.0. My test sample compiles but the IDE cannot get information from compile_commands.json
and thus the autocompletion is broken.
The CMakeList.txt is as follows:
cmake_minimum_required(VERSION 3.26.0)
project("nativetest")
set(CMAKE_EXPERIMENTAL_CXX_MODULE_CMAKE_API "2182bf5c-ef0d-489a-91da-49dbc3090d2a")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1)
string(CONCAT CMAKE_EXPERIMENTAL_CXX_SCANDEP_SOURCE
"${CMAKE_CXX_COMPILER_CLANG_SCAN_DEPS}"
" -format=p1689"
" --"
" <CMAKE_CXX_COMPILER> <DEFINES> <INCLUDES> <FLAGS>"
" -x c++ <SOURCE> -c -o <OBJECT>"
" -MT <DYNDEP_FILE>"
" -MD -MF <DEP_FILE>"
" > <DYNDEP_FILE>")
set(CMAKE_EXPERIMENTAL_CXX_MODULE_MAP_FORMAT "clang")
set(CMAKE_EXPERIMENTAL_CXX_MODULE_MAP_FLAG "@<MODULE_MAP_FILE>")
set(CMAKE_CXX_EXTENSIONS OFF)
add_executable(my_program)
target_sources(
my_program
PRIVATE
main.cxx
PRIVATE FILE_SET CXX_MODULES
BASE_DIRS .
FILES
importable.cxx
)
target_compile_features(my_program PUBLIC cxx_std_20)
main.cxx on the other hand is:
import importable;
int main(int argc, char **argv) {
return from_import();
}
and importable.cxx is:
export module importable;
export int from_import() {
return 0;
}
I used vscode with CMake tool plugin and clangd plugin, and it show errors Module 'importable' not found clang(module_not_found)
.
The generated compile_commands.json is:
[
{
"directory": "/home/loves/test/build",
"command": "/usr/bin/clang++-16 -O3 -DNDEBUG -std=c++20 -o CMakeFiles/my_program.dir/main.cxx.o -c /home/loves/test/main.cxx",
"file": "/home/loves/test/main.cxx",
"output": "CMakeFiles/my_program.dir/main.cxx.o"
},
{
"directory": "/home/loves/test/build",
"command": "/usr/bin/clang++-16 -O3 -DNDEBUG -std=c++20 -o CMakeFiles/my_program.dir/importable.cxx.o -c /home/loves/test/importable.cxx",
"file": "/home/loves/test/importable.cxx",
"output": "CMakeFiles/my_program.dir/importable.cxx.o"
}
]
Edited by 余生与君