# Use CMake to do work other than building application

**URL:** https://discourse.cmake.org/t/use-cmake-to-do-work-other-than-building-application/5824
**Category:** Code
**Created:** [June 8, 2022, 3:57pm UTC](https://discourse.cmake.org/t/use-cmake-to-do-work-other-than-building-application/5824 "2022-06-08T15:57:10Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![ygao88](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/y/439d5e/32.png) [@ygao88](https://discourse.cmake.org/u/ygao88)
#### Post date: [June 8, 2022, 3:57pm UTC](https://discourse.cmake.org/t/use-cmake-to-do-work-other-than-building-application/5824/1 "2022-06-08T15:57:10Z")

</div>

Hi,

Is it proper/possible to use CMake to do work other than building code? For example, we need to generate sw package which includes pulling files from SVN, encrypt files and make tar balls.

Regards,  
Winston

---

<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: [June 8, 2022, 4:00pm UTC](https://discourse.cmake.org/t/use-cmake-to-do-work-other-than-building-application/5824/2 "2022-06-08T16:00:51Z")

</div>

It’s certainly possible. I use CMake to manage my dotfiles and I’ve also used it to perform image scoring algorithms (`make` and `ninja` are a _lot_ better at picking up where things left off than digging into logs to find out where the machine got to when it locked up from a lack of RAM overnight).

---

<div class="post-metadata">

### Author: ![ygao88](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/y/439d5e/32.png) [@ygao88](https://discourse.cmake.org/u/ygao88)
#### Post date: [June 9, 2022, 3:33pm UTC](https://discourse.cmake.org/t/use-cmake-to-do-work-other-than-building-application/5824/3 "2022-06-09T15:33:52Z")

</div>

Can you share some ideas, e.g., what the approach is? The task can be simplified to:

1. Get two files from SVN
2. Encrypt one of the file using openssl
3. Make a tar ball with the two files (one of them is encrypted in step 2)
4. Encrypt the tar ball with openssl.

Do I need to create a custom function to do all this?

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: [June 9, 2022, 3:37pm UTC](https://discourse.cmake.org/t/use-cmake-to-do-work-other-than-building-application/5824/4 "2022-06-09T15:37:17Z")

</div>

A function would be helpful, yes. But the core is basically this:

```cmake
add_custom_command(
  INPUT ${input}
  OUTPUT ${output}
  COMMAND do_something -i ${input} -o ${output}
  COMMENT "Turn ${input} into ${output}")
add_custom_command(
  INPUT ${output}
  OUTPUT ${output2}
  COMMAND do_something_else -i ${output} -o ${output2}
  COMMENT "Turn ${output} into ${output2}")
add_custom_target(${user_target_name} DEPENDS ${output2})

```

Expand the chain as long as needed and cap it with `add_custom_target`.
