add target for python script

Hi

It might be weird, but I happen to need to add a target to a project that is not a C program with main, but a script python.

I’m looking for something like add_executable(), but for my custom command.
Something similar to

add_custom_target(
    target_name
    COMMAND python main.py
)

where the command will not be called during the build, but during the execution of the target

Thanks

CMake does not have an abstraction for executables that are not compiled as CMake targets. This includes shell scripts and the like. You might be able to (ab)use IMPORTED targets for this, though this generally requires that a single string be enough (i.e., no interpreter needed).

1 Like