In the utility CMake module tools/cmake/FindBpfObject.cmake, the step to compile BPF C source files to BPF object files is done by triggering clang with a custom command:
|
# Build BPF object file |
|
add_custom_command(OUTPUT ${BPF_O_FILE} |
|
COMMAND ${BPFOBJECT_CLANG_EXE} -g -O2 -target bpf -D__TARGET_ARCH_${ARCH} |
|
${CLANG_SYSTEM_INCLUDES} -I${GENERATED_VMLINUX_DIR} |
|
-isystem ${LIBBPF_INCLUDE_DIRS} -c ${BPF_C_FILE} -o ${BPF_O_FILE} |
|
COMMAND_EXPAND_LISTS |
|
VERBATIM |
|
DEPENDS ${BPF_C_FILE} |
|
COMMENT "[clang] Building BPF object: ${name}") |
However, when I enable the CMAKE_EXPORT_COMPILE_COMMANDS option in my CMakeLists.txt, this step will not appear in compile_commands.json because it is a custom command. And because the C/C++ extension in VS Code relies on compile_commands.json for configurations like header locations, it cannot provide proper assistance to development in BPF C source files (*.bpf.c). Could this step be changed to make CMake manage this part so that it can generate correct compile commands? Or are there other ways to work around this issue?
Thanks in advance.
In the utility CMake module tools/cmake/FindBpfObject.cmake, the step to compile BPF C source files to BPF object files is done by triggering clang with a custom command:
libbpf-bootstrap/tools/cmake/FindBpfObject.cmake
Lines 163 to 171 in be15d32
However, when I enable the
CMAKE_EXPORT_COMPILE_COMMANDSoption in myCMakeLists.txt, this step will not appear incompile_commands.jsonbecause it is a custom command. And because the C/C++ extension in VS Code relies oncompile_commands.jsonfor configurations like header locations, it cannot provide proper assistance to development in BPF C source files (*.bpf.c). Could this step be changed to make CMake manage this part so that it can generate correct compile commands? Or are there other ways to work around this issue?Thanks in advance.