Is it possible to export compile commands for custom commands?

I configured the project libbpf-bootstrap with following shell commands:

cmake -S examples/c -B build -DCMAKE_EXPORT_COMPILE_COMMANDS=ON

However, in the generated compile_commands.json, there were no items for *.bpf.c files. Those files are compiled through macro bpf_object, which is defined in tools/cmake/FindBpfObject.cmake and uses add_custom_command to compile these files.

  # 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}")

Is it possible for CMake to append these commands into the compile_commands.json?

Thanks in advance.

No, custom commands are not considered for compile_commands.json. It may be better to add support for BPF as a target (it’d probably look similar to WASM support I suppose).