CMake’s execute_process and arbitrary shell scripts

You can execute any shell script, using your shell’s support for taking in a script within a string argument.

Example:

execute_process(
    COMMAND bash "-c" "echo -n hello | sed 's/hello/world/;'" 
    OUTPUT_VARIABLE FOO
)

will result in FOO containing world.

Of course, you would need to escape quotes and backslashes with care. Also remember that running bash would only work on platforms which have bash – i.e. it won’t work on Windows.

Leave a Comment