Skip to content

FindBpfObject.cmake not injecting "Build BPF object file" step to compile_commands.json #138

@yanghanlin

Description

@yanghanlin

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions