From dcd9a1b59f58031a1eb94841a9c1cb58d5f9eff1 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 2 Jan 2008 17:49:16 -0500 Subject: [PATCH] BUG: Make RAISE_SCOPE function work when variable is not defined. --- Source/cmMakefile.cxx | 18 +++++++++++-- Tests/FunctionTest/CMakeLists.txt | 27 +++++++++++++++++++ Tests/FunctionTest/SubDirScope/CMakeLists.txt | 3 +++ 3 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 Tests/FunctionTest/SubDirScope/CMakeLists.txt diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index 306c00bef..49fc0f1c4 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -2853,7 +2853,14 @@ void cmMakefile::RaiseScope(const char *var) // multiple scopes in this directory? if (this->DefinitionStack.size() > 1) { - this->DefinitionStack[this->DefinitionStack.size()-2][var] = varDef; + if(varDef) + { + this->DefinitionStack[this->DefinitionStack.size()-2][var] = varDef; + } + else + { + this->DefinitionStack[this->DefinitionStack.size()-2].erase(var); + } } // otherwise do the parent else @@ -2861,7 +2868,14 @@ void cmMakefile::RaiseScope(const char *var) cmMakefile *parent = this->LocalGenerator->GetParent()->GetMakefile(); if (parent) { - parent->AddDefinition(var,varDef); + if(varDef) + { + parent->AddDefinition(var,varDef); + } + else + { + parent->RemoveDefinition(var); + } } } } diff --git a/Tests/FunctionTest/CMakeLists.txt b/Tests/FunctionTest/CMakeLists.txt index 76c2511fe..5ab9bcd92 100644 --- a/Tests/FunctionTest/CMakeLists.txt +++ b/Tests/FunctionTest/CMakeLists.txt @@ -83,4 +83,31 @@ FUNCTION(ADD_EXECUTABLE exec) _ADD_EXECUTABLE(mini${exec} ${ARGN}) ENDFUNCTION(ADD_EXECUTABLE) +# var undef case +FUNCTION(undef_var m) + SET(${m}) + RAISE_SCOPE(${m}) +ENDFUNCTION(undef_var) +SET(FUNCTION_UNDEFINED 1) +undef_var(FUNCTION_UNDEFINED) +IF(DEFINED FUNCTION_UNDEFINED) + FAILED("Function Undefine Test" "(${FUNCTION_UNDEFINED})") +ELSE(DEFINED FUNCTION_UNDEFINED) + PASS("Function Undefine Test" "(${FUNCTION_UNDEFINED})") +ENDIF(DEFINED FUNCTION_UNDEFINED) + +# Subdirectory scope raise. +SET(SUBDIR_UNDEFINED 1) +ADD_SUBDIRECTORY(SubDirScope) +IF(DEFINED SUBDIR_UNDEFINED) + FAILED("Subdir Undefine Test" "(${SUBDIR_UNDEFINED})") +ELSE(DEFINED SUBDIR_UNDEFINED) + PASS("Subdir Undefine Test" "(${SUBDIR_UNDEFINED})") +ENDIF(DEFINED SUBDIR_UNDEFINED) +IF(DEFINED SUBDIR_DEFINED) + PASS("Subdir Define Test" "(${SUBDIR_DEFINED})") +ELSE(DEFINED SUBDIR_DEFINED) + FAILED("Subdir Define Test" "(${SUBDIR_DEFINED})") +ENDIF(DEFINED SUBDIR_DEFINED) + ADD_EXECUTABLE(FunctionTest functionTest.c) diff --git a/Tests/FunctionTest/SubDirScope/CMakeLists.txt b/Tests/FunctionTest/SubDirScope/CMakeLists.txt new file mode 100644 index 000000000..174b9b006 --- /dev/null +++ b/Tests/FunctionTest/SubDirScope/CMakeLists.txt @@ -0,0 +1,3 @@ +SET(SUBDIR_DEFINED 1) +SET(SUBDIR_UNDEFINED) +RAISE_SCOPE(SUBDIR_DEFINED SUBDIR_UNDEFINED)