Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Properly escape CMake generator expressions #15926

Open
stevenwdv opened this issue Mar 22, 2024 · 0 comments
Open

[bug] Properly escape CMake generator expressions #15926

stevenwdv opened this issue Mar 22, 2024 · 0 comments

Comments

@stevenwdv
Copy link
Contributor

stevenwdv commented Mar 22, 2024

Describe the bug

Some CMake functions, like add_compile_definitions, accept generator expressions these take the form of $<...> and are only evaluated at generation time, not at configure time such as regular variables.
the CMakeToolchain conan uses some of these functions with dynamic values in conan_toolchain.cmake. This brings some problems, however, because values need to be escaped. For example:

add_compile_definitions("$<$<CONFIG:Debug>:{{define}}>")

with define=MYMACRO=abc $<CONFIG:Debug> def > 123 becomes:

add_compile_definitions("$<$<CONFIG:Debug>:abc $<CONFIG:Debug> def > 123>")

which will evaluate (in the debug config) as: abc 1 def >. Note that first assigning define to a CMake variable and using that in the expression as in "$<$<CONFIG:Debug>:${var}>" does not save us, as ${var} is evaluated at the configuration stage, before generation time.

To solve the issue, we need to escape (besides " and the usual):

  • > as $<ANGLE-R>
  • $ as $<1:$> (think: if(1) return "$")
  • In some cases , and ; may need to be escaped as well.

Note that this should not just be done inside of generator expressions, but for all arguments that accept them, even if conan does not use them.

How to reproduce it

E.g. set tools.build:defines=['MYMACRO=abc $<CONFIG:Debug> def > 123'] and observe how the actual define passed to the compiler is not the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant