I have to use a custom command containing a dollar sign in my CMakeLists.txt (not echo of course but that will do it for now).
As my real project is rather lengthy, I made a minimal (non-)working example:
cmake_minimum_required(VERSION 3.14)
project(TEST)
add_custom_target(Testtarget)
add_custom_command(TARGET Testtarget PRE_BUILD COMMAND echo '$$ Hello')
Now, if you try to "build" this thing using standard Makefiles everything runs fine:
rm -rf build && cmake -B build -S . && cmake --build build --target Testtarget
-- The C compiler identification is GNU 9.4.0
... snip ...
-- Generating done
-- Build files have been written to: ....
Scanning dependencies of target Testtarget
$ Hello
Built target Testtarget
but as soon as I try to build it with Ninja, it won't do:
rm -rf build && cmake -B build -S . -G Ninja && cmake --build build --target Testtarget
-- The C compiler identification is GNU 9.4.0
... snip ...
-- Generating done
-- Build files have been written to: ....
ninja: error: unknown target 'Testtarget'
I tried $, $$ $, VERBATIM and some others, but whatever I try, Ninja does not find the target.
Any ideas?