Browse Source

Merge topic 'set_emptyvar_PARENT_SCOPE'

bf755c7 set: Add unit tests for set/unset PARENT_SCOPE
bc280f1 set: Fix handling of empty value with PARENT_SCOPE
20afbd5 set: Handle value-less PARENT_SCOPE explicitly
Brad King 12 years ago
parent
commit
15872a3c30

+ 10 - 9
Source/cmSetCommand.cxx

@@ -62,9 +62,17 @@ bool cmSetCommand
     this->Makefile->RemoveDefinition(args[0].c_str());
     return true;
     }
+  // SET (VAR PARENT_SCOPE) // Removes the definition of VAR
+                            // in the parent scope.
+  else if (args.size() == 2 && args[args.size()-1] == "PARENT_SCOPE")
+    {
+    this->Makefile->RaiseScope(variable, 0);
+    return true;
+    }
 
   // here are the remaining options
   //  SET (VAR value )
+  //  SET (VAR value PARENT_SCOPE)
   //  SET (VAR CACHE TYPE "doc String" [FORCE])
   //  SET (VAR value CACHE TYPE "doc string" [FORCE])
   std::string value;  // optional
@@ -114,15 +122,8 @@ bool cmSetCommand
 
   if (parentScope)
     {
-    if (value.empty())
-      {
-      this->Makefile->RaiseScope(variable, 0);
-      }
-    else
-      {
-      this->Makefile->RaiseScope(variable, value.c_str());
-      }
-      return true;
+    this->Makefile->RaiseScope(variable, value.c_str());
+    return true;
     }
 
 

+ 1 - 0
Tests/RunCMake/CMakeLists.txt

@@ -107,6 +107,7 @@ add_RunCMake_test(list)
 add_RunCMake_test(message)
 add_RunCMake_test(string)
 add_RunCMake_test(try_compile)
+add_RunCMake_test(set)
 add_RunCMake_test(variable_watch)
 add_RunCMake_test(CMP0004)
 add_RunCMake_test(TargetPolicies)

+ 3 - 0
Tests/RunCMake/set/CMakeLists.txt

@@ -0,0 +1,3 @@
+cmake_minimum_required(VERSION 2.8.12)
+project(${RunCMake_TEST} NONE)
+include(${RunCMake_TEST}.cmake)

+ 1 - 0
Tests/RunCMake/set/PARENT_SCOPE-result.txt

@@ -0,0 +1 @@
+0

+ 33 - 0
Tests/RunCMake/set/PARENT_SCOPE.cmake

@@ -0,0 +1,33 @@
+set(FOO )
+set(BAR "bar")
+set(BAZ "baz")
+set(BOO "boo")
+
+function(_parent_scope)
+    set(FOO "foo" PARENT_SCOPE)
+    set(BAR "" PARENT_SCOPE)
+    set(BAZ PARENT_SCOPE)
+    unset(BOO PARENT_SCOPE)
+endfunction()
+
+_parent_scope()
+
+if(NOT DEFINED FOO)
+  message(FATAL_ERROR "FOO not defined")
+elseif(NOT "${FOO}" STREQUAL "foo")
+  message(FATAL_ERROR "FOO should be \"foo\", not \"${FOO}\"")
+endif()
+
+if(NOT DEFINED BAR)
+  message(FATAL_ERROR "BAR not defined")
+elseif(NOT "${BAR}" STREQUAL "")
+  message(FATAL_ERROR "BAR should be an empty string, not \"${BAR}\"")
+endif()
+
+if(DEFINED BAZ)
+  message(FATAL_ERROR "BAZ defined")
+endif()
+
+if(DEFINED BOO)
+  message(FATAL_ERROR "BOO defined")
+endif()

+ 3 - 0
Tests/RunCMake/set/RunCMakeTest.cmake

@@ -0,0 +1,3 @@
+include(RunCMake)
+
+run_cmake(PARENT_SCOPE)