How not to have dollar sign in target_link_options mangled?

Viewed 131

If I have this CMake script:

add_link_options(--preload-file=temp$.txt)
add_executable(main main.cpp)

or

add_executable(main main.cpp)
target_link_options(main PUBLIC --preload-file=temp$.txt)

and an arbitrary file named temp$.txt, it doesn't find the txt file because the dollar sign gets changed into something like \$$ in the actual compiler invocation.

(Don't mind the actual link option, it's an Emscripten specific one, but the problem I believe is not specific to Emscripten development.)

What should I do to make it find my file which has a dollar sign in its name?

1 Answers

The developers seem to agree this is a bug based on a discussion raised on their Discourse. However, fixing it will require a policy.

In the meantime, I discovered that the CMAKE_*_LINKER_FLAGS variables do not suffer from the same bad escaping behavior, so you can set your flag there (preferably in a toolchain file). For executables, the variable is CMAKE_EXE_LINKER_FLAGS.

Related