Browse Source

GHS: Update toolset selection logic

-- Ensure that GHS_TOOLSET_ROOT is used as a path
   * Converts directory path slashes to CMake style
-- Use ComparePath() to properly check for path changes of build tool
   * Accounts for Windows file-system case insensitivity.
-- Don't print message "defaulting" messages (this causes CMake test failures)
-- Don't force update CMAKE_GENERATOR_TOOLSET back into cache when `-T`
   is not used on initial configure. This change avoids an unnessary
   error message when accidentally using `-T` in subsequent runs but the same
   tools are always used.
-- Use IssueMessage() for error messages.
Fred Baksik 4 years ago
parent
commit
83eb5695e9

+ 10 - 0
Modules/Platform/GHS-MULTI-Determine.cmake

@@ -16,6 +16,16 @@ if(CMAKE_GENERATOR MATCHES "Green Hills MULTI")
     mark_as_advanced(GHS_TARGET_PLATFORM)
   endif()
 
+  # Setup MULTI toolset selection variables
+  if(CMAKE_HOST_UNIX)
+    set(_ts_root "/usr/ghs")
+  else()
+    set(_ts_root "C:/ghs")
+  endif()
+  set(GHS_TOOLSET_ROOT "${_ts_root}" CACHE PATH "GHS platform toolset root directory")
+  mark_as_advanced(GHS_TOOLSET_ROOT)
+  unset(_ts_root)
+
   # Setup MULTI project variables
   set(GHS_CUSTOMIZATION "" CACHE FILEPATH "optional GHS customization")
   mark_as_advanced(GHS_CUSTOMIZATION)

+ 46 - 42
Source/cmGlobalGhsMultiGenerator.cxx

@@ -2,7 +2,6 @@
    file Copyright.txt or https://cmake.org/licensing for details.  */
 #include "cmGlobalGhsMultiGenerator.h"
 
-#include <algorithm>
 #include <map>
 #include <ostream>
 #include <utility>
@@ -18,6 +17,7 @@
 #include "cmLocalGenerator.h"
 #include "cmLocalGhsMultiGenerator.h"
 #include "cmMakefile.h"
+#include "cmMessageType.h"
 #include "cmState.h"
 #include "cmStateTypes.h"
 #include "cmStringAlgorithms.h"
@@ -29,10 +29,8 @@
 const char* cmGlobalGhsMultiGenerator::FILE_EXTENSION = ".gpj";
 #ifdef __linux__
 const char* cmGlobalGhsMultiGenerator::DEFAULT_BUILD_PROGRAM = "gbuild";
-const char* cmGlobalGhsMultiGenerator::DEFAULT_TOOLSET_ROOT = "/usr/ghs";
 #elif defined(_WIN32)
 const char* cmGlobalGhsMultiGenerator::DEFAULT_BUILD_PROGRAM = "gbuild.exe";
-const char* cmGlobalGhsMultiGenerator::DEFAULT_TOOLSET_ROOT = "C:/ghs";
 #endif
 
 cmGlobalGhsMultiGenerator::cmGlobalGhsMultiGenerator(cmake* cm)
@@ -70,31 +68,21 @@ void cmGlobalGhsMultiGenerator::ComputeTargetObjectDirectory(
 bool cmGlobalGhsMultiGenerator::SetGeneratorToolset(std::string const& ts,
                                                     bool build, cmMakefile* mf)
 {
+  /* In build mode nothing to be done.
+   * Toolset already determined and build tool absolute path is cached.
+   */
   if (build) {
     return true;
   }
-  std::string tsp; /* toolset path */
 
+  /* Determine the absolute directory for the toolset */
+  std::string tsp;
   this->GetToolset(mf, tsp, ts);
 
   /* no toolset was found */
   if (tsp.empty()) {
     return false;
   }
-  if (ts.empty()) {
-    std::string message;
-    message = cmStrCat(
-      "Green Hills MULTI: -T <toolset> not specified; defaulting to \"", tsp,
-      '"');
-    cmSystemTools::Message(message);
-
-    /* store the full toolset for later use
-     * -- already done if -T<toolset> was specified
-     */
-    mf->AddCacheDefinition("CMAKE_GENERATOR_TOOLSET", tsp,
-                           "Location of generator toolset.",
-                           cmStateEnums::INTERNAL);
-  }
 
   /* set the build tool to use */
   std::string gbuild(tsp + ((tsp.back() == '/') ? "" : "/") +
@@ -102,13 +90,13 @@ bool cmGlobalGhsMultiGenerator::SetGeneratorToolset(std::string const& ts,
   cmValue prevTool = mf->GetDefinition("CMAKE_MAKE_PROGRAM");
 
   /* check if the toolset changed from last generate */
-  if (prevTool && (gbuild != *prevTool)) {
-    std::string message =
+  if (cmNonempty(prevTool) && !cmSystemTools::ComparePath(gbuild, prevTool)) {
+    std::string const& e =
       cmStrCat("toolset build tool: ", gbuild,
-               "\nDoes not match the previously used build tool: ", *prevTool,
+               "\nDoes not match the previously used build tool: ", prevTool,
                "\nEither remove the CMakeCache.txt file and CMakeFiles "
                "directory or choose a different binary directory.");
-    cmSystemTools::Error(message);
+    mf->IssueMessage(MessageType::FATAL_ERROR, e);
     return false;
   }
 
@@ -207,43 +195,59 @@ bool cmGlobalGhsMultiGenerator::FindMakeProgram(cmMakefile* /*mf*/)
   return true;
 }
 
-void cmGlobalGhsMultiGenerator::GetToolset(cmMakefile* mf, std::string& tsd,
+void cmGlobalGhsMultiGenerator::GetToolset(cmMakefile* mf, std::string& tsp,
                                            const std::string& ts)
 {
-  cmValue ghsRoot = mf->GetDefinition("GHS_TOOLSET_ROOT");
+  /* Determine tsp - full path of the toolset from ts (toolset hint via -T) */
 
-  if (cmNonempty(ghsRoot)) {
-    tsd = *ghsRoot;
-  } else {
-    tsd = DEFAULT_TOOLSET_ROOT;
-  }
+  std::string root = mf->GetSafeDefinition("GHS_TOOLSET_ROOT");
 
+  // Check if `-T` was set by user
   if (ts.empty()) {
+    // Enter toolset search mode
     std::vector<std::string> output;
 
-    // Use latest? version
-    if (tsd.back() != '/') {
-      tsd += "/";
+    // Make sure root exists...
+    if (!cmSystemTools::PathExists(root)) {
+      std::string msg =
+        "GHS_TOOLSET_ROOT directory \"" + root + "\" does not exist.";
+      mf->IssueMessage(MessageType::FATAL_ERROR, msg);
+      tsp = "";
+      return;
+    }
+
+    // Add a directory separator
+    if (root.back() != '/') {
+      root += "/";
     }
-    cmSystemTools::Glob(tsd, "comp_[^;]+", output);
+
+    // Get all compiler directories in toolset root
+    cmSystemTools::Glob(root, "comp_[^;]+", output);
 
     if (output.empty()) {
+      // No compiler directories found
       std::string msg =
-        "No GHS toolsets found in GHS_TOOLSET_ROOT \"" + tsd + "\".";
-      cmSystemTools::Error(msg);
-      tsd = "";
+        "No GHS toolsets found in GHS_TOOLSET_ROOT \"" + root + "\".";
+      mf->IssueMessage(MessageType::FATAL_ERROR, msg);
+      tsp = "";
     } else {
-      tsd += output.back();
+      // Use latest? version
+      tsp = root + output.back();
     }
+
   } else {
+    // Toolset was provided by user
     std::string tryPath;
-    tryPath = cmSystemTools::CollapseFullPath(ts, tsd);
+
+    // NOTE: CollapseFullPath() will determine if user toolset was full path or
+    //       or relative path.
+    tryPath = cmSystemTools::CollapseFullPath(ts, root);
     if (!cmSystemTools::FileExists(tryPath)) {
-      std::string msg = "GHS toolset \"" + tryPath + "\" not found.";
-      cmSystemTools::Error(msg);
-      tsd = "";
+      std::string msg = "GHS toolset \"" + tryPath + "\" does not exist.";
+      mf->IssueMessage(MessageType::FATAL_ERROR, msg);
+      tsp = "";
     } else {
-      tsd = tryPath;
+      tsp = tryPath;
     }
   }
 }

+ 0 - 1
Source/cmGlobalGhsMultiGenerator.h

@@ -114,7 +114,6 @@ private:
 
   std::string OsDir;
   static const char* DEFAULT_BUILD_PROGRAM;
-  static const char* DEFAULT_TOOLSET_ROOT;
 
   bool ComputeTargetBuildOrder(cmGeneratorTarget const* tgt,
                                std::vector<cmGeneratorTarget const*>& build);