From 6c2944b6fe8ae264bcb107cb11512ed36d90a586 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 2 Oct 2002 17:22:56 -0400 Subject: BUG: STRLESS and STRGREATER need to treat non-existent definitions as strings. --- Source/cmIfCommand.cxx | 41 ++++++++++++++++++++--------------------- Source/cmIfCommand.h | 5 +++++ 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/Source/cmIfCommand.cxx b/Source/cmIfCommand.cxx index ffcd901..7baba12 100644 --- a/Source/cmIfCommand.cxx +++ b/Source/cmIfCommand.cxx @@ -200,11 +200,7 @@ bool cmIfCommand::IsTrue(const std::vector &args, bool &isValid, if (args.size() == 3 && (args[1] == "MATCHES")) { - def = makefile->GetDefinition(args[0].c_str()); - if (!def) - { - def = args[0].c_str(); - } + def = cmIfCommand::GetVariableOrString(args[0].c_str(), makefile); cmRegularExpression regEntry(args[2].c_str()); // check for black line or comment @@ -217,8 +213,8 @@ bool cmIfCommand::IsTrue(const std::vector &args, bool &isValid, if (args.size() == 3 && (args[1] == "LESS")) { - def = makefile->GetDefinition(args[0].c_str()); - def2 = makefile->GetDefinition(args[2].c_str()); + def = cmIfCommand::GetVariableOrString(args[0].c_str(), makefile); + def2 = cmIfCommand::GetVariableOrString(args[2].c_str(), makefile); if (!def) { def = args[0].c_str(); @@ -236,16 +232,8 @@ bool cmIfCommand::IsTrue(const std::vector &args, bool &isValid, if (args.size() == 3 && (args[1] == "GREATER")) { - def = makefile->GetDefinition(args[0].c_str()); - def2 = makefile->GetDefinition(args[2].c_str()); - if (!def) - { - def = args[0].c_str(); - } - if (!def2) - { - def2 = args[2].c_str(); - } + def = cmIfCommand::GetVariableOrString(args[0].c_str(), makefile); + def2 = cmIfCommand::GetVariableOrString(args[2].c_str(), makefile); if(atof(def) <= atof(def2)) { isTrue = false; @@ -255,8 +243,8 @@ bool cmIfCommand::IsTrue(const std::vector &args, bool &isValid, if (args.size() == 3 && (args[1] == "STRLESS")) { - def = makefile->GetDefinition(args[0].c_str()); - def2 = makefile->GetDefinition(args[2].c_str()); + def = cmIfCommand::GetVariableOrString(args[0].c_str(), makefile); + def2 = cmIfCommand::GetVariableOrString(args[2].c_str(), makefile); if(strcmp(def,def2) >= 0) { isTrue = false; @@ -266,8 +254,8 @@ bool cmIfCommand::IsTrue(const std::vector &args, bool &isValid, if (args.size() == 3 && (args[1] == "STRGREATER")) { - def = makefile->GetDefinition(args[0].c_str()); - def2 = makefile->GetDefinition(args[2].c_str()); + def = cmIfCommand::GetVariableOrString(args[0].c_str(), makefile); + def2 = cmIfCommand::GetVariableOrString(args[2].c_str(), makefile); if(strcmp(def,def2) <= 0) { isTrue = false; @@ -277,3 +265,14 @@ bool cmIfCommand::IsTrue(const std::vector &args, bool &isValid, return isTrue; } + +const char* cmIfCommand::GetVariableOrString(const char* str, + const cmMakefile* mf) +{ + const char* def = mf->GetDefinition(str); + if(!def) + { + def = str; + } + return def; +} diff --git a/Source/cmIfCommand.h b/Source/cmIfCommand.h index b5647c8..f14192a 100644 --- a/Source/cmIfCommand.h +++ b/Source/cmIfCommand.h @@ -105,6 +105,11 @@ public: static bool IsTrue(const std::vector &args, bool &isValid, const cmMakefile *mf); + // Get a definition from the makefile. If it doesn't exist, + // return the original string. + static const char* GetVariableOrString(const char* str, + const cmMakefile* mf); + cmTypeMacro(cmIfCommand, cmCommand); }; -- cgit v0.12