CMake:为 add_custom_target 添加可执行文件

Bim*_*Bim 5 c++ cmake visual-studio-code

我有一个 CMakeLists.txt 和一些工具链文件。在我的 CMakeLists.txt 中,我有一条生成 .elf 可执行文件的语句。然后通过一些命令(使用 add_custom_target,代码来自此处)运行该可执行文件,生成 .gba 文件,这是我要启动的真正可执行文件。现在的问题是,我正在使用 VS Code 的 cmake 扩展,并且目标没有显示启动(可能是因为它不被视为可执行文件)。我尝试了 add_executable(target.gba IMPORT),但这不起作用。在 CMakeLists.txt 中:

add_executable(target.elf ${SOURCE_FILES} ${INCLUDE_FILES} ${EXTRA_DATA_FILES}) # Create the elf file
add_gba_executable(target.elf) # Generate the .gba from the .elf
Run Code Online (Sandbox Code Playgroud)

在工具链文件中:

function(add_gba_executable target)
    get_filename_component(target_name ${target} NAME_WE)
    add_custom_target(${target_name}.gba ALL SOURCES
        COMMAND ${OBJCOPY} -v -O binary ${target} ${target_name}.gba
        COMMAND ${GBAFIX} ${target_name}.gba
        DEPENDS ${target}
        VERBATIM
    )
    set_target_properties(${target} PROPERTIES LINK_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Map=${target_name}.map -specs=gba.specs")
    set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${target_name}.gba)
endfunction()
Run Code Online (Sandbox Code Playgroud)

我如何告诉 CMake add_custom_target 的结果也是可执行文件?我尝试了 add_executable(target.gba IMPORT),但这不起作用。

编辑:澄清 - 我的函数已经添加了一个目标 target.gba 并且可以选择将其构建(因此 add_custom_target 确实有效),但不会显示在要启动的目标列表中。