3

I have a CMakeLists.txt and some toolchain files. In my CMakeLists.txt I have a statement to generate a .elf executable. This executable is then run through some commands (using add_custom_target, code from here) that generates a .gba file, which is the REAL executable I want to launch. Now the problem is that I'm using the cmake extension for VS Code and the target does not show up to launch (probably because it's not considered an executable). I tried add_executable(target.gba IMPORT), but that didn't work. In 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

In the toolchain file:

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()

How can I tell CMake the result of the add_custom_target is an executable too? I tried add_executable(target.gba IMPORT), but that didn't work.

Gama11
  • 28,518
  • 9
  • 66
  • 91
Bim
  • 941
  • 1
  • 9
  • 28

0 Answers0