[CMake] Explanation....
Johannes Zarl
johannes.zarl at jku.at
Wed Apr 16 07:57:21 EDT 2014
On Wednesday, 16. April 2014, 12:03:30, Rolf Eike Beer wrote:
> > 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:
In principle, you are right. Not too sure, though, whether such a big "NOOOOO"
is warranted. A quick test shows the overhead to be existing, yet not too
severe:
foreach(arg RANGE 10000)
#a) if ( " ${foo}" STREQUAL " ${arg}")
#b) if ( foo MATCHES "^${arg}$")
message("Found it!")
endif()
endforeach()
Method b) has to compile 10.000 regexes, yet the runtime is "only" 30% worse.
And that is even though this example does the opposite of the normal use-case
of the regex, i.e. keeping one fixed regex and matching the variables against
it. I doubt that the overhead is even measurable in the "average" build
system.
#a)
$ time cmake .
-- Configuring done
-- Generating done
-- Build files have been written to: /home/zing/scratch/foo
real 0m0.210s
user 0m0.136s
sys 0m0.012s
#b)
$ time cmake .
-- Configuring done
-- Generating done
-- Build files have been written to: /home/zing/scratch/foo
real 0m0.278s
user 0m0.220s
sys 0m0.004s
Or are you talking about memory overhead?
>
> if (" ${arg}" STREQUAL " TOTO")
Kudos to you for presenting a (the only?) *safe* prefix.
Johannes
More information about the CMake
mailing list