Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake: How to add a add_custom_command that just executes a shellscript?

When I use the classic gnu Make I put in post build actions like flash the device (if it is a embedded device) and other similiar actions. The actual flashing is usually hidden behind a little sctipt or some commands.

Then I can type something like

make flash

so I first build the code and then it ends up on the target. The classic Makefile could have something like in it:

.PHONY: flash
flash: main.bin
    scripts/do_flash.pl main.bin

But how do I add this kind of post build actions to a cmake build?

How do I add a "custom command" that just executes a shellscript?

This questions talks about add_custom_command: The question cmake add custom command feels like it is close, but the add_custom_command seems to need a "output file" to work. But in this case there is something happening, not generated.

What would I put in the CMakeLists.txt to add such a custom action?

/Thanks


For reference, a link into the cmake documentation on this topic

  • http://www.cmake.org/cmake/help/cmake2.6docs.html#command:add_custom_target
like image 752
Johan Avatar asked Feb 03 '23 12:02

Johan


1 Answers

Try this:

add_custom_target(flash
    COMMAND ${PERL_EXECUTABLE} ${CMAKE_SOURCE_DIR}/scripts/do_flash.pl ${MAIN_BIN_FILE}
    DEPENDS ${MAIN_BIN_FILE}
)
like image 111
arrowd Avatar answered Feb 05 '23 00:02

arrowd