custom_command ECHO with special character

2019-07-11 06:40发布

I am trying to add a custom_command with CMake and call COMMAND echo "$" > file.txt

as long as I put $ in it, the config file will generate but failed to build.

I have also tried echo "\$" and doesn't seems to work.

add_custom_command( TARGET ${TARGET_NAME}
                    POST_BUILD
                    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/out
                    COMMAND echo "-keep class com.android.**\$* { ; }" >> ./proguard.txt
                  )

The cmake command works but as long as I call ninja, I got the following error:

error: 'src', needed by 'all', missing and no known rule to make it 

Seems like cmake is unable to generate the build step. My intention is to print that **$ into a file.

标签: cmake
1条回答
地球回转人心会变
2楼-- · 2019-07-11 07:19

Both

COMMAND echo "$$" > file.txt

and

COMMAND echo "$" > file.txt VERBATIM

output $ sign into given file.

EDIT: This works on makefile generators, and only when make is run from the terminal. Generally redirection sign ">" is not worked as expected in COMMAND expression.

查看更多
登录 后发表回答