Al.Cash
Al.Cash

Reputation: 11

CMake add_custom_command run in background

I have a command executed in a POST_BUILD step using add_custom_command(). It takes quite some time, but I don't need the results to run the executable, I just want it to start after the build. Is there a way to run such a command in the background so that the executable can be run right after the build without waiting for the command to finish?

Upvotes: 1

Views: 1360

Answers (1)

Craig Scott
Craig Scott

Reputation: 10137

If you are willing to use some platform-specific logic, one way is to use a shell script to launch the command you want to run in the background. A very crude example for Unix systems may look like this:

launcher.sh:

#!/bin/sh

"$@"&

CMakeLists.txt:

add_custom_command(TARGET myTarget POST_BUILD
    COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/launcher.sh whateverYouWantToRun
)

You could add something equivalent for Windows and then test the CMAKE_HOST_SYSTEM_NAME variable to choose which launcher script to use.

Upvotes: 1

Related Questions