# add target for python script

**URL:** <https://discourse.cmake.org/t/add-target-for-python-script/3283>\
**Category:** Code\
**Created:** [May 9, 2021, 12:45pm UTC](https://discourse.cmake.org/t/add-target-for-python-script/3283 "2021-05-09T12:45:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tzlil\_Gavra](https://discourse.cmake.org/user_avatar/discourse.cmake.org/tzlil_gavra/32/991_2.png) [@Tzlil\_Gavra](https://discourse.cmake.org/u/Tzlil_Gavra)\
**Post date:** [May 9, 2021, 12:45pm UTC](https://discourse.cmake.org/t/add-target-for-python-script/3283/1 "2021-05-09T12:45:28Z")

</div>

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

```auto
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

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [May 9, 2021, 9:29pm UTC](https://discourse.cmake.org/t/add-target-for-python-script/3283/2 "2021-05-09T21:29:36Z")

</div>

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