0

I'm running cmake on VSCode. I'm trying to set it up to invoke a custom script I wrote to flash the executable into my target mcu.

I'm reading about CROSSCOMPILING_EMULATOR, CMAKE_CROSSCOMPILING_EMULATOR and CMAKE_CROSSCOMPILING but I can't find an example of how to use them properly.

The main issue is that after the building is complete cmake is trying to run the *.elf file.

How can I flash the binary after building?

5
  • You want to flash the result of compilation or run tests on your target? How do you "flash the executable into my target mcu" without cmake? Commented Feb 28, 2022 at 11:04
  • @KamilCuk I want to flash the result of compilation on my target mcu. I have a script that does that and I execute it manually after each build. I want to invoke that script from cmake after building Commented Feb 28, 2022 at 11:09
  • The target's property CROSSCOMPILING_EMULATOR affects only the way how executable will be used in COMMAND clauses of CMake commands like add_test or add_custom_command. Variable CMAKE_CROSSCOMPILING_EMULATOR is additionally used in try_compile. In VSCode you need to specify command line to be used as "run" action. In that command line you could do whatever you want: run your script, pass it parameters, etc. See also stackoverflow.com/questions/49583381/… Commented Feb 28, 2022 at 11:19
  • @Tsyvarev Yes, that's what I want. But I haven't found the way to do it yet. Commented Feb 28, 2022 at 11:58
  • @Tsyvarev I think you cannot change the action takes place after hitting "run" button in cmake extension of vscode. Commented Feb 28, 2022 at 12:18

1 Answer 1

0

I have a script that does that and I execute it manually after each build. I want to invoke that script from cmake after building

Generally:

add_executable(the_executable_target ...)
add_custom_target(flashit
    COMMAND
          ${YOUR_INTERPRETER_LIKE_BASH_OR_SOMTHING}
          ./your_script 
          $<TARGET_FILE:the_executable_target>
    COMMENT "flashes it"
)
add_dependencies(flashit the_executable_taregt)

You could add ALL. You could also interest in add_custom_commnad(POST_BUILD ....

CMAKE_CROSSCOMPILING_EMULATOR is used for try_run, but most importantly for running tests.

Sign up to request clarification or add additional context in comments.

1 Comment

No, it won't work. It still tries to run my_executable.elf after cmake --build, instead of my script

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.