Expected behavior for shell meta characters like $ in target_compile_definitions, target_compile_options, etcetera.

I’m trying to understand the desired CMake behavior with handling shell meta characters so I can fix some issues with Green Hills MULTI generator.

For example, what is supposed to happen with:

target_compile_definitions(exe1 PRIVATE $(TEST_USE_MACRO1) "$(TEST_USE_MACRO2)" )
target_compile_options(exe2 PRIVATE "-Dvalue=$(cache_macro)")

What I’ve seen is that when using target_compile_options the function EscapeForShell() eventually is called to transform the string to modify the string to be safe for the build tool and the shell being used. target_compiled_definitions() did not appear to always perform shell escaping.

Currently the GHS MULTI generator does not properly escape things to be handled by the build tool and what ends up on the command line is unexpected.

But I would like to add the feature to the generator so that a user can use the build tools built-in and user defined macros. The project format for macro variables are: ${var1} or $(var2). In this case you’d want to skip EscapeForShell() processing.

The easiest thing I guess is to always skip EscapeForShell() processing but I don’t know if that is an acceptable solution for the GHS MULTI generator.

Normally all such content is escaped such that the underlying tools see those exact strings. However, there are special cases for $(VAR) syntax commonly used as native buildsystem placeholders.

You could experiment with the Unix Makefiles generator to get a sense for it.