pmr
pmr

Reputation: 59841

Generate a file with CMake and add it as an executable

I have a project that generates a shell script at CMake time (with file(WRITE. How can I get CMake to treat this shell script as an executable of the project (e.g. have it cleaned up, "rebuild", and also installed)?

Upvotes: 3

Views: 4159

Answers (1)

arrowd
arrowd

Reputation: 34421

First, take a look at configure_file() function, it can do all the work for you. If you can't use it, you should add_custom_command(), which would produce your file and then add_custom_target(), which should DEPENDS on ${CMAKE_BINARY_DIR}/your_produced_file.

In add_custom_command() invokation you can use something like that:

COMMAND ${CMAKE_PROGRAM} -P ${CMAKE_SCRIPT_THAT_PRODUCES_YOUR_FILE}

Upvotes: 4

Related Questions