CMake's execute_process and arbitrary shell scripts

前端 未结 2 1344
悲哀的现实
悲哀的现实 2020-12-06 03:41

CMake\'s execute_process command seems to only let you, well, execute a process - not an arbitrary line you could feed a command shell. The thing is, I want to

2条回答
  •  没有蜡笔的小新
    2020-12-06 03:51

    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.

提交回复
热议问题