[cmake-developers] if (FOO == BAR) ...

Alexander Neundorf neundorf at kde.org
Thu Mar 21 14:45:00 EDT 2013


On Thursday 21 March 2013, Matthew Woehlke wrote:
> On 2013-03-20 17:42, Alexander Neundorf wrote:
> > On Wednesday 20 March 2013, Matthew Woehlke wrote:
> >> On 2013-03-20 17:10, David Cole wrote:
> >>> Are you proposing that == behaves as STREQUAL, or as EQUAL?
> >> 
> >> What's the difference?
> >> 
> >> Okay, for <, >, there is an obvious answer, but for ==, I am trying and
> >> failing to think of a situation where treating the arguments as numbers
> >> would give a different result vs. treating them as strings.
> > 
> > E.g. "0" vs. "0.0"
> 
> Is "0.0" a floating-point number or a version string? In the context of
> CMake, I would have rather expected it to be the latter. (Does CMake
> even understand floating point?) If '==' assumes numbers, how do I tell
> it I really meant a version string?

EQUAL tries to convert to double:

  if (argP1 != newArgs.end() && argP2 != newArgs.end() &&
        (*(argP1) == "LESS" || *(argP1) == "GREATER" ||
         *(argP1) == "EQUAL"))
        {
        def = cmIfCommand::GetVariableOrString(arg->c_str(), makefile);
        def2 = cmIfCommand::GetVariableOrString((argP2)->c_str(), makefile);
        double lhs;
        double rhs;
        bool result;
        if(sscanf(def, "%lg", &lhs) != 1 ||
           sscanf(def2, "%lg", &rhs) != 1)


My "==" implementation simply compares the strings on both sides in the most 
simple and straightforward way.


Alex



More information about the cmake-developers mailing list