Use CMake to do work other than building application


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.


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

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?


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

  INPUT ${input}
  OUTPUT ${output}
  COMMAND do_something -i ${input} -o ${output}
  COMMENT "Turn ${input} into ${output}")
  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.

1 Like