[CMake] Explanation....
Matthew Woehlke
mw_triad at users.sourceforge.net
Wed Apr 23 12:54:39 EDT 2014
On 2014-04-16 06:03, Rolf Eike Beer wrote:
> Am 16.04.2014 11:39, schrieb Johannes Zarl:
>> Instead of ``"${var}" STREQUAL "VALUE"'', write:
>>
>> IF ( var MATCHES "^VALUE$" )
>
> NOOOOO, please don't! I try hard to kill all those as it requires
> compiling a regular expression for a simple string match. Just change it
> to something that is no valid variable name, i.e. will never get expanded:
>
> if (" ${arg}" STREQUAL " TOTO")
set(" TOTO" "evil")
Admittedly it's much less likely that variable names containing
non-identifier characters¹ will occur "by accident", the only truly safe
way to avoid unintended implicit expansion is to either rely on implicit
expansion (i.e. always assign your operands to variables and give the
variable names as the literal arguments), or use some other command that
doesn't perform expansion.
(¹ except for '-', which will often occur in automatically created
variable names when used in project names, e.g. my-project_SOURCE_DIR.)
See also
http://permalink.gmane.org/gmane.comp.programming.tools.cmake.devel/9936.
--
Matthew
More information about the CMake
mailing list