GHS: Fix toolset selection

-- Allow -T to accept full or partial paths
-- Use "C:/ghs" if GHS_TOOLSET_ROOT is empty string
-- Put more information in error messages
This commit is contained in:
Fred Baksik 2019-01-08 12:15:59 -05:00
parent 1a66acdef2
commit 4a1ec0de3d
3 changed files with 37 additions and 26 deletions

View File

@ -12,9 +12,10 @@ The ``-A <arch>`` can be supplied for setting the target architecture.
``<arch>`` usually is one of "arm", "ppc", "86", etcetera. If the target architecture ``<arch>`` usually is one of "arm", "ppc", "86", etcetera. If the target architecture
is not specified then the default architecture of "arm" will be used. is not specified then the default architecture of "arm" will be used.
The ``-T <toolset>`` can be supplied for setting the toolset to be used. The ``-T <toolset>`` option can be used to set the directory location of the toolset.
All toolsets are expected to be located at ``GHS_TOOLSET_ROOT``. Both absolute and relative paths are valid. Relative paths use ``GHS_TOOLSET_ROOT``
If the toolset is not specified then the latest toolset will be used. as the root. If the toolset is not specified then the latest toolset found in
``GHS_TOOLSET_ROOT`` will be used.
* ``GHS_TARGET_PLATFORM`` * ``GHS_TARGET_PLATFORM``
@ -30,7 +31,7 @@ If the toolset is not specified then the latest toolset will be used.
* ``GHS_TOOLSET_ROOT`` * ``GHS_TOOLSET_ROOT``
| Root path for ``toolset``. | Root path for ``toolset`` searches.
| Defaults to ``C:/ghs``. | Defaults to ``C:/ghs``.
* ``GHS_OS_ROOT`` * ``GHS_OS_ROOT``

View File

@ -55,43 +55,44 @@ void cmGlobalGhsMultiGenerator::ComputeTargetObjectDirectory(
bool cmGlobalGhsMultiGenerator::SetGeneratorToolset(std::string const& ts, bool cmGlobalGhsMultiGenerator::SetGeneratorToolset(std::string const& ts,
cmMakefile* mf) cmMakefile* mf)
{ {
std::string tsp; /* toolset path */ std::string tsp; /* toolset path */
std::string tsn = ts; /* toolset name */
GetToolset(mf, tsp, tsn); this->GetToolset(mf, tsp, ts);
/* no toolset was found */ /* no toolset was found */
if (tsn.empty()) { if (tsp.empty()) {
return false; return false;
} else if (ts.empty()) { } else if (ts.empty()) {
std::string message; std::string message;
message = message =
"Green Hills MULTI: -T <toolset> not specified; defaulting to \""; "Green Hills MULTI: -T <toolset> not specified; defaulting to \"";
message += tsn; message += tsp;
message += "\""; message += "\"";
cmSystemTools::Message(message.c_str()); cmSystemTools::Message(message.c_str());
/* store the toolset for later use /* store the full toolset for later use
* -- already done if -T<toolset> was specified * -- already done if -T<toolset> was specified
*/ */
mf->AddCacheDefinition("CMAKE_GENERATOR_TOOLSET", tsn.c_str(), mf->AddCacheDefinition("CMAKE_GENERATOR_TOOLSET", tsp.c_str(),
"Name of generator toolset.", "Location of generator toolset.",
cmStateEnums::INTERNAL); cmStateEnums::INTERNAL);
} }
/* set the build tool to use */ /* set the build tool to use */
std::string gbuild(tsp + ((tsp.back() == '/') ? "" : "/") +
DEFAULT_BUILD_PROGRAM);
const char* prevTool = mf->GetDefinition("CMAKE_MAKE_PROGRAM"); const char* prevTool = mf->GetDefinition("CMAKE_MAKE_PROGRAM");
std::string gbuild(tsp + "/" + tsn + "/" + DEFAULT_BUILD_PROGRAM);
/* check if the toolset changed from last generate */ /* check if the toolset changed from last generate */
if (prevTool != NULL && (gbuild != prevTool)) { if (prevTool != NULL && (gbuild != prevTool)) {
std::string message = "generator toolset: "; std::string message = "toolset build tool: ";
message += gbuild; message += gbuild;
message += "\nDoes not match the toolset used previously: "; message += "\nDoes not match the previously used build tool: ";
message += prevTool; message += prevTool;
message += "\nEither remove the CMakeCache.txt file and CMakeFiles " message += "\nEither remove the CMakeCache.txt file and CMakeFiles "
"directory or choose a different binary directory."; "directory or choose a different binary directory.";
cmSystemTools::Error(message.c_str()); cmSystemTools::Error(message.c_str());
return false;
} else { } else {
/* store the toolset that is being used for this build */ /* store the toolset that is being used for this build */
mf->AddCacheDefinition("CMAKE_MAKE_PROGRAM", gbuild.c_str(), mf->AddCacheDefinition("CMAKE_MAKE_PROGRAM", gbuild.c_str(),
@ -99,7 +100,7 @@ bool cmGlobalGhsMultiGenerator::SetGeneratorToolset(std::string const& ts,
true); true);
} }
mf->AddDefinition("CMAKE_SYSTEM_VERSION", tsn.c_str()); mf->AddDefinition("CMAKE_SYSTEM_VERSION", tsp.c_str());
// FIXME: compiler detection not implemented // FIXME: compiler detection not implemented
// gbuild uses the primaryTarget setting in the top-level project // gbuild uses the primaryTarget setting in the top-level project
@ -172,11 +173,11 @@ bool cmGlobalGhsMultiGenerator::FindMakeProgram(cmMakefile* /*mf*/)
} }
void cmGlobalGhsMultiGenerator::GetToolset(cmMakefile* mf, std::string& tsd, void cmGlobalGhsMultiGenerator::GetToolset(cmMakefile* mf, std::string& tsd,
std::string& ts) const std::string& ts)
{ {
const char* ghsRoot = mf->GetDefinition("GHS_TOOLSET_ROOT"); const char* ghsRoot = mf->GetDefinition("GHS_TOOLSET_ROOT");
if (!ghsRoot) { if (!ghsRoot || ghsRoot[0] == '\0') {
ghsRoot = DEFAULT_TOOLSET_ROOT; ghsRoot = DEFAULT_TOOLSET_ROOT;
} }
tsd = ghsRoot; tsd = ghsRoot;
@ -185,20 +186,29 @@ void cmGlobalGhsMultiGenerator::GetToolset(cmMakefile* mf, std::string& tsd,
std::vector<std::string> output; std::vector<std::string> output;
// Use latest? version // Use latest? version
if (tsd.back() != '/') {
tsd += "/";
}
cmSystemTools::Glob(tsd, "comp_[^;]+", output); cmSystemTools::Glob(tsd, "comp_[^;]+", output);
if (output.empty()) { if (output.empty()) {
cmSystemTools::Error("GHS toolset not found in ", tsd.c_str()); std::string msg =
ts = ""; "No GHS toolsets found in GHS_TOOLSET_ROOT \"" + tsd + "\".";
cmSystemTools::Error(msg.c_str());
tsd = "";
} else { } else {
ts = output.back(); tsd += output.back();
} }
} else { } else {
std::string tryPath = tsd + std::string("/") + ts; std::string tryPath;
/* CollapseCombinedPath will check if ts is an absolute path */
tryPath = cmSystemTools::CollapseCombinedPath(tsd, ts);
if (!cmSystemTools::FileExists(tryPath)) { if (!cmSystemTools::FileExists(tryPath)) {
cmSystemTools::Error("GHS toolset \"", ts.c_str(), "\" not found in ", std::string msg = "GHS toolset \"" + tryPath + "\" not found.";
tsd.c_str()); cmSystemTools::Error(msg.c_str());
ts = ""; tsd = "";
} else {
tsd = tryPath;
} }
} }
} }

View File

@ -99,7 +99,7 @@ protected:
std::vector<std::string>()) override; std::vector<std::string>()) override;
private: private:
void GetToolset(cmMakefile* mf, std::string& tsd, std::string& ts); void GetToolset(cmMakefile* mf, std::string& tsd, const std::string& ts);
/* top-level project */ /* top-level project */
void OutputTopLevelProject(cmLocalGenerator* root, void OutputTopLevelProject(cmLocalGenerator* root,