CMake and configure_file: what if I need $ ONLY instead of @ONLY?

As from the documentation configure_file

, it has a useful parameter @ONLY

used for:

Limit variable replacement to form references @VAR@

. This is useful for customizing scripts that use syntax ${VAR}

.

So far so good.

Now I am in the case where I have a file containing both @FOO@

and ${BAR}

and I want to replace S{BAR}

with a variable that comes from mine CMakeLists.tx

. On the other hand, I don't want to configure_file

try to replace @FOO@

.
In other words, I need something like a parameter $ONLY

that works like @ONLY

, but for the opposite case.

Is there a chance that I can do this with what I have now?
I tried to put a backslash in front of mine @

, but this way I end up with a file containing the pair \@

, and that's not exactly what I want.

+3


source to share


1 answer


At least I found a solution that works, even if I'm not sure what is the best approach ever.
I leave this as an answer to future readers in case no solutions emerge.

Suppose the line to be developed looks like this:

@DontTouchMe@/${PROJECT_NAME}

      

To skip the part @DontTouchMe@

when transferring the file to configure_file

, you can change the line like this:



@@Workaround@DontTouchMe@Workaround@@/${PROJECT_NAME}

      

configure_file

will match and replace parts with @Workaround@

an empty string and forget about the other @

around, so after replacing you get the following line:

@DontTouchMe@/TheNameOfTheProject

      

Dirty enough that it might break with future versions cmake

as it actually exploits the bug (for example, I'm not sure I can call it that). Either way, it works and can be a viable approach for those still looking for a possible solution.

+3


source







All Articles