From 686c5c864dbe4791d5cef605757df8e6700ed0b9 Mon Sep 17 00:00:00 2001
From: Geoff Viola <geoffrey.viola@asirobots.com>
Date: Sun, 29 Mar 2015 20:56:21 -0600
Subject: [PATCH] Fixed tests by finding make program when cleaning

---
 Source/cmGhsMultiTargetGenerator.cxx | 27 ++++++++++++++++++++-------
 Source/cmGlobalGhsMultiGenerator.cxx | 20 ++++++++++++--------
 Source/cmGlobalGhsMultiGenerator.h   |  7 ++++---
 3 files changed, 36 insertions(+), 18 deletions(-)

diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx
index 0c3595b..e0a7356 100644
--- a/Source/cmGhsMultiTargetGenerator.cxx
+++ b/Source/cmGhsMultiTargetGenerator.cxx
@@ -188,21 +188,34 @@ void cmGhsMultiTargetGenerator::WriteTypeSpecifics(const std::string &config,
 void cmGhsMultiTargetGenerator::WriteDebugOptions(std::string const &config,
                                                   bool const notKernel)
 {
-  if ("DEBUG" == config)
+  if (notKernel)
     {
-    if (notKernel)
+    // Create debug symbols
+    if ("DEBUG" == config || "RELWITHDEBINFO" == config)
       {
       *this->GetFolderBuildStreams() << "    -G" << std::endl;
-      *this->GetFolderBuildStreams() << "    -Onone" << std::endl;
       }
-    else
+
+    // Set optimization
+    if ("DEBUG" == config)
       {
-      *this->GetFolderBuildStreams() << "    -ldebug" << std::endl;
+      *this->GetFolderBuildStreams() << "    -Odebug" << std::endl;
+      }
+    else if ("RELWITHDEBINFO" == config || "RELEASE" == config)
+      {
+      *this->GetFolderBuildStreams() << "    -O" << std::endl;
+      }
+    else if ("MINSIZEREL" == config)
+      {
+      *this->GetFolderBuildStreams() << "    -Osize" << std::endl;
       }
     }
-  else if (notKernel)
+  else
     {
-    *this->GetFolderBuildStreams() << "    -O" << std::endl;
+      if ("DEBUG" == config || "RELWITHDEBINFO" == config)
+      {
+      *this->GetFolderBuildStreams() << "    -ldebug" << std::endl;
+      }
     }
 }
 
diff --git a/Source/cmGlobalGhsMultiGenerator.cxx b/Source/cmGlobalGhsMultiGenerator.cxx
index afd05ae..fa06d4f 100644
--- a/Source/cmGlobalGhsMultiGenerator.cxx
+++ b/Source/cmGlobalGhsMultiGenerator.cxx
@@ -19,6 +19,7 @@
 #include <cmAlgorithms.h>
 
 const char *cmGlobalGhsMultiGenerator::FILE_EXTENSION = ".gpj";
+const char *cmGlobalGhsMultiGenerator::DEFAULT_MAKE_PROGRAM = "gbuild";
 
 cmGlobalGhsMultiGenerator::cmGlobalGhsMultiGenerator()
   : OSDirRelative(false)
@@ -88,26 +89,29 @@ void cmGlobalGhsMultiGenerator::FindMakeProgram(cmMakefile *mf)
   if (cmSystemTools::IsOff(mf->GetDefinition("CMAKE_MAKE_PROGRAM")))
     {
     mf->AddDefinition("CMAKE_MAKE_PROGRAM",
-                      this->GetGhsBuildCommand().c_str());
+                      this->GetGhsBuildCommand(mf).c_str());
     }
 }
 
-std::string const &cmGlobalGhsMultiGenerator::GetGhsBuildCommand()
+std::string const &cmGlobalGhsMultiGenerator::GetGhsBuildCommand(cmMakefile *mf)
 {
   if (!this->GhsBuildCommandInitialized)
     {
     this->GhsBuildCommandInitialized = true;
-    this->GhsBuildCommand = this->FindGhsBuildCommand();
+    this->GhsBuildCommand = this->FindGhsBuildCommand(mf);
     }
   return this->GhsBuildCommand;
 }
 
-std::string cmGlobalGhsMultiGenerator::FindGhsBuildCommand()
+std::string cmGlobalGhsMultiGenerator::FindGhsBuildCommand(cmMakefile *mf)
 {
-  std::string makeProgram = cmSystemTools::FindProgram("gbuild");
+  std::vector<std::string> userPaths;
+  userPaths.push_back(mf->GetDefinition("GHS_COMP_ROOT"));
+  std::string makeProgram =
+      cmSystemTools::FindProgram(DEFAULT_MAKE_PROGRAM, userPaths);
   if (makeProgram.empty())
     {
-    makeProgram = "gbuild";
+    makeProgram = DEFAULT_MAKE_PROGRAM;
     }
   return makeProgram;
 }
@@ -301,8 +305,8 @@ void cmGlobalGhsMultiGenerator::GenerateBuildCommand(
   std::vector<std::string> const &makeOptions)
 {
   makeCommand.push_back(
-    this->SelectMakeProgram(makeProgram, this->GetGhsBuildCommand())
-    );
+    this->SelectMakeProgram(makeProgram, this->GhsBuildCommand)
+  );
 
   makeCommand.insert(makeCommand.end(),
                      makeOptions.begin(), makeOptions.end());
diff --git a/Source/cmGlobalGhsMultiGenerator.h b/Source/cmGlobalGhsMultiGenerator.h
index d5948da..6b09f6a 100644
--- a/Source/cmGlobalGhsMultiGenerator.h
+++ b/Source/cmGlobalGhsMultiGenerator.h
@@ -50,7 +50,7 @@ public:
   /*
   * Determine what program to use for building the project.
   */
-  virtual void FindMakeProgram(cmMakefile *);
+  virtual void FindMakeProgram(cmMakefile *mf);
 
   cmGeneratedFileStream *GetBuildFileStream()
   {
@@ -87,8 +87,8 @@ protected:
     );
 
 private:
-  std::string const &GetGhsBuildCommand();
-  std::string FindGhsBuildCommand();
+  std::string const &GetGhsBuildCommand(cmMakefile *mf);
+  std::string FindGhsBuildCommand(cmMakefile *mf);
   std::string GetCompRoot();
   std::vector<std::string> GetCompRootHardPaths();
   std::vector<std::string> GetCompRootRegistry();
@@ -120,6 +120,7 @@ private:
   bool OSDirRelative;
   bool GhsBuildCommandInitialized;
   std::string GhsBuildCommand;
+  static const char *DEFAULT_MAKE_PROGRAM;
 };
 
 #endif
-- 
1.8.1.msysgit.1

