I'm using cmake to manage my c++ project on Ubuntu.
In the CMakeLists.txt, I want to add a custom target to execute some linux commands, here it is:
cmake_minimum_required(VERSION 3.9)
project(MyTest CXX)
add_custom_target(
cov ALL
)
add_custom_command(
TARGET cov
COMMAND touch xxx
COMMAND echo -e '#!/bin/bash'>xxx
)
In a word, I want to create a file named xxx and redirect the string #!/bin/bash into it. However, when I execute cmake . && make, I get an error:
/bin/sh: 1: Syntax error: Unterminated quoted string. Obviously it is because the # is regarded as a comment by cmake so that this line becomes COMMAND echo -e ' .
I've also tried like this: COMMAND bash -c "echo -e '#!/bin/bash>'>xxx", but this gave me an empty xxx.