diff options
author | Brad King <brad.king@kitware.com> | 2018-07-12 13:14:58 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2018-07-12 13:15:18 (GMT) |
commit | f6f5f9f75f809a077ac3f451745904d9f3faaa85 (patch) | |
tree | c8e4c761c44df04b3dde3833a48b357ded131797 /Source | |
parent | 7b04ad61cf925161c8b7f9abf6ef3db047118807 (diff) | |
parent | ce4f20ba62a3c7e0dd78cffc1669a400311f057e (diff) | |
download | CMake-f6f5f9f75f809a077ac3f451745904d9f3faaa85.zip CMake-f6f5f9f75f809a077ac3f451745904d9f3faaa85.tar.gz CMake-f6f5f9f75f809a077ac3f451745904d9f3faaa85.tar.bz2 |
Merge topic 'ghs'
ce4f20ba62 GHS: Add release notes
281c601024 GHS: Update default BSP name
01c98c6ccc GHS: Update setting default OS location for Integrity platforms
bb77dc0cee GHS: Set primary target using arch/platform values (or user specified value)
f80692cf60 GHS: Add platform selection support
a37a4a00c8 GHS: Add toolset selection support
5d40d2b44f GHS: Support ARM, PPC, 86 architectures
Acked-by: Kitware Robot <kwrobot@kitware.com>
Acked-by: Matt Soucy <matthew.soucy@baesystems.com>
Merge-request: !798
Diffstat (limited to 'Source')
-rw-r--r-- | Source/cmGlobalGhsMultiGenerator.cxx | 273 | ||||
-rw-r--r-- | Source/cmGlobalGhsMultiGenerator.h | 19 |
2 files changed, 167 insertions, 125 deletions
diff --git a/Source/cmGlobalGhsMultiGenerator.cxx b/Source/cmGlobalGhsMultiGenerator.cxx index 1e104ee..a9742c5 100644 --- a/Source/cmGlobalGhsMultiGenerator.cxx +++ b/Source/cmGlobalGhsMultiGenerator.cxx @@ -14,13 +14,13 @@ #include "cmVersion.h" const char* cmGlobalGhsMultiGenerator::FILE_EXTENSION = ".gpj"; -const char* cmGlobalGhsMultiGenerator::DEFAULT_MAKE_PROGRAM = "gbuild"; +const char* cmGlobalGhsMultiGenerator::DEFAULT_BUILD_PROGRAM = "gbuild.exe"; +const char* cmGlobalGhsMultiGenerator::DEFAULT_TOOLSET_ROOT = "C:/ghs"; cmGlobalGhsMultiGenerator::cmGlobalGhsMultiGenerator(cmake* cm) : cmGlobalGenerator(cm) , OSDirRelative(false) { - this->GhsBuildCommandInitialized = false; } cmGlobalGhsMultiGenerator::~cmGlobalGhsMultiGenerator() @@ -41,133 +41,153 @@ void cmGlobalGhsMultiGenerator::GetDocumentation(cmDocumentationEntry& entry) "Generates Green Hills MULTI files (experimental, work-in-progress)."; } -void cmGlobalGhsMultiGenerator::EnableLanguage( - std::vector<std::string> const& l, cmMakefile* mf, bool optional) +bool cmGlobalGhsMultiGenerator::SetGeneratorToolset(std::string const& ts, + cmMakefile* mf) { - mf->AddDefinition("CMAKE_SYSTEM_NAME", "GHS-MULTI"); - mf->AddDefinition("CMAKE_SYSTEM_PROCESSOR", "ARM"); - - const std::string ghsCompRoot(GetCompRoot()); - mf->AddDefinition("GHS_COMP_ROOT", ghsCompRoot.c_str()); - std::string ghsCompRootStart = - 0 == ghsCompRootStart.size() ? "" : ghsCompRoot + "/"; - mf->AddDefinition("CMAKE_C_COMPILER", - std::string(ghsCompRootStart + "ccarm.exe").c_str()); + std::string tsp; /* toolset path */ + std::string tsn = ts; /* toolset name */ + + GetToolset(mf, tsp, tsn); + + /* no toolset was found */ + if (tsn.empty()) { + return false; + } else if (ts.empty()) { + std::string message; + message = + "Green Hills MULTI: -T <toolset> not specified; defaulting to \""; + message += tsn; + message += "\""; + cmSystemTools::Message(message.c_str()); + + /* store the toolset for later use + * -- already done if -T<toolset> was specified + */ + mf->AddCacheDefinition("CMAKE_GENERATOR_TOOLSET", tsn.c_str(), + "Name of generator toolset.", + cmStateEnums::INTERNAL); + } + + /* set the build tool to use */ + const char* prevTool = mf->GetDefinition("CMAKE_MAKE_PROGRAM"); + std::string gbuild(tsp + "/" + tsn + "/" + DEFAULT_BUILD_PROGRAM); + + /* check if the toolset changed from last generate */ + if (prevTool != NULL && (gbuild != prevTool)) { + std::string message = "generator toolset: "; + message += gbuild; + message += "\nDoes not match the toolset used previously: "; + message += prevTool; + message += "\nEither remove the CMakeCache.txt file and CMakeFiles " + "directory or choose a different binary directory."; + cmSystemTools::Error(message.c_str()); + } else { + /* store the toolset that is being used for this build */ + mf->AddCacheDefinition("CMAKE_MAKE_PROGRAM", gbuild.c_str(), + "build program to use", cmStateEnums::INTERNAL, + true); + } + + mf->AddDefinition("CMAKE_SYSTEM_VERSION", tsn.c_str()); + + // FIXME: compiler detection not implemented + // gbuild uses the primaryTarget setting in the top-level project + // file to determine which compiler to use. Because compiler + // detection is not implemented these variables must be + // set to skip past these tests. However cmake will verify that + // the executable pointed to by CMAKE_<LANG>_COMPILER exists. + // To pass this additional check gbuild is used as a place holder for the + // actual compiler. + mf->AddDefinition("CMAKE_C_COMPILER", gbuild.c_str()); mf->AddDefinition("CMAKE_C_COMPILER_ID_RUN", "TRUE"); mf->AddDefinition("CMAKE_C_COMPILER_ID", "GHS"); mf->AddDefinition("CMAKE_C_COMPILER_FORCED", "TRUE"); - mf->AddDefinition("CMAKE_CXX_COMPILER", - std::string(ghsCompRootStart + "cxarm.exe").c_str()); + mf->AddDefinition("CMAKE_CXX_COMPILER", gbuild.c_str()); mf->AddDefinition("CMAKE_CXX_COMPILER_ID_RUN", "TRUE"); mf->AddDefinition("CMAKE_CXX_COMPILER_ID", "GHS"); mf->AddDefinition("CMAKE_CXX_COMPILER_FORCED", "TRUE"); - if (!ghsCompRoot.empty()) { - static const char* compPreFix = "comp_"; - std::string compFilename = - cmsys::SystemTools::FindLastString(ghsCompRoot.c_str(), compPreFix); - cmsys::SystemTools::ReplaceString(compFilename, compPreFix, ""); - mf->AddDefinition("CMAKE_SYSTEM_VERSION", compFilename.c_str()); - } - - mf->AddDefinition("GHSMULTI", "1"); // identifier for user CMake files - this->cmGlobalGenerator::EnableLanguage(l, mf, optional); + return true; } -bool cmGlobalGhsMultiGenerator::FindMakeProgram(cmMakefile* mf) +bool cmGlobalGhsMultiGenerator::SetGeneratorPlatform(std::string const& p, + cmMakefile* mf) { - // The GHS generator knows how to lookup its build tool - // directly instead of needing a helper module to do it, so we - // do not actually need to put CMAKE_MAKE_PROGRAM into the cache. - if (cmSystemTools::IsOff(mf->GetDefinition("CMAKE_MAKE_PROGRAM"))) { - mf->AddDefinition("CMAKE_MAKE_PROGRAM", - this->GetGhsBuildCommand().c_str()); + if (p == "") { + cmSystemTools::Message( + "Green Hills MULTI: -A <arch> not specified; defaulting to \"arm\""); + std::string arch = "arm"; + + /* store the platform name for later use + * -- already done if -A<arch> was specified + */ + mf->AddCacheDefinition("CMAKE_GENERATOR_PLATFORM", arch.c_str(), + "Name of generator platform.", + cmStateEnums::INTERNAL); } - return true; -} -std::string const& cmGlobalGhsMultiGenerator::GetGhsBuildCommand() -{ - if (!this->GhsBuildCommandInitialized) { - this->GhsBuildCommandInitialized = true; - this->GhsBuildCommand = this->FindGhsBuildCommand(); + const char* tgtPlatform = mf->GetDefinition("GHS_TARGET_PLATFORM"); + if (tgtPlatform == nullptr) { + tgtPlatform = "integrity"; } - return this->GhsBuildCommand; + + /* store the platform name for later use */ + mf->AddCacheDefinition("GHS_TARGET_PLATFORM", tgtPlatform, + "Name of GHS target platform.", + cmStateEnums::INTERNAL); + + return true; } -std::string cmGlobalGhsMultiGenerator::FindGhsBuildCommand() +void cmGlobalGhsMultiGenerator::EnableLanguage( + std::vector<std::string> const& l, cmMakefile* mf, bool optional) { - std::vector<std::string> userPaths; - userPaths.push_back(this->GetCompRoot()); - std::string makeProgram = - cmSystemTools::FindProgram(DEFAULT_MAKE_PROGRAM, userPaths); - if (makeProgram.empty()) { - makeProgram = DEFAULT_MAKE_PROGRAM; - } - return makeProgram; + mf->AddDefinition("CMAKE_SYSTEM_NAME", "GHS-MULTI"); + + mf->AddDefinition("GHSMULTI", "1"); // identifier for user CMake files + this->cmGlobalGenerator::EnableLanguage(l, mf, optional); } -std::string cmGlobalGhsMultiGenerator::GetCompRoot() +bool cmGlobalGhsMultiGenerator::FindMakeProgram(cmMakefile* /*mf*/) { - std::string output; - - const std::vector<std::string> potentialDirsHardPaths( - GetCompRootHardPaths()); - const std::vector<std::string> potentialDirsRegistry(GetCompRootRegistry()); - - std::vector<std::string> potentialDirsComplete; - potentialDirsComplete.insert(potentialDirsComplete.end(), - potentialDirsHardPaths.begin(), - potentialDirsHardPaths.end()); - potentialDirsComplete.insert(potentialDirsComplete.end(), - potentialDirsRegistry.begin(), - potentialDirsRegistry.end()); - - // Use latest version - std::string outputDirName; - for (std::vector<std::string>::const_iterator potentialDirsCompleteIt = - potentialDirsComplete.begin(); - potentialDirsCompleteIt != potentialDirsComplete.end(); - ++potentialDirsCompleteIt) { - const std::string dirName( - cmsys::SystemTools::GetFilenameName(*potentialDirsCompleteIt)); - if (dirName.compare(outputDirName) > 0) { - output = *potentialDirsCompleteIt; - outputDirName = dirName; - } - } + // The GHS generator only knows how to lookup its build tool + // during generation of the project files, but this + // can only be done after the toolset is specified. - return output; + return true; } -std::vector<std::string> cmGlobalGhsMultiGenerator::GetCompRootHardPaths() +void cmGlobalGhsMultiGenerator::GetToolset(cmMakefile* mf, std::string& tsd, + std::string& ts) { - std::vector<std::string> output; - cmSystemTools::Glob("C:/ghs", "comp_[^;]+", output); - for (std::vector<std::string>::iterator outputIt = output.begin(); - outputIt != output.end(); ++outputIt) { - *outputIt = "C:/ghs/" + *outputIt; + const char* ghsRoot = mf->GetDefinition("GHS_TOOLSET_ROOT"); + + if (!ghsRoot) { + ghsRoot = DEFAULT_TOOLSET_ROOT; } - return output; -} + tsd = ghsRoot; -std::vector<std::string> cmGlobalGhsMultiGenerator::GetCompRootRegistry() -{ - std::vector<std::string> output(2); - cmsys::SystemTools::ReadRegistryValue( - "HKEY_LOCAL_" - "MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\" - "Windows\\CurrentVersion\\Uninstall\\" - "GreenHillsSoftwared771f1b4;InstallLocation", - output[0]); - cmsys::SystemTools::ReadRegistryValue( - "HKEY_LOCAL_" - "MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\" - "Windows\\CurrentVersion\\Uninstall\\" - "GreenHillsSoftware9881cef6;InstallLocation", - output[1]); - return output; + if (ts.empty()) { + std::vector<std::string> output; + + // Use latest? version + cmSystemTools::Glob(tsd, "comp_[^;]+", output); + + if (output.empty()) { + cmSystemTools::Error("GHS toolset not found in ", tsd.c_str()); + ts = ""; + } else { + ts = output.back(); + } + } else { + std::string tryPath = tsd + std::string("/") + ts; + if (!cmSystemTools::FileExists(tryPath)) { + cmSystemTools::Error("GHS toolset \"", ts.c_str(), "\" not found in ", + tsd.c_str()); + ts = ""; + } + } } void cmGlobalGhsMultiGenerator::OpenBuildFileStream( @@ -216,25 +236,28 @@ void cmGlobalGhsMultiGenerator::OpenBuildFileStream() this->OSDirRelative = true; } - char const* bspName = + std::string bspName; + char const* bspCache = this->GetCMakeInstance()->GetCacheDefinition("GHS_BSP_NAME"); - if (NULL == bspName) { - bspName = ""; - cmSystemTools::Error("GHS_BSP_NAME cache variable must be set"); - } else { + if (bspCache) { + bspName = bspCache; this->GetCMakeInstance()->MarkCliAsUsed("GHS_BSP_NAME"); } - std::string fBspName(this->trimQuotes(bspName)); - std::replace(fBspName.begin(), fBspName.end(), '\\', '/'); + if (bspName.empty() || bspName.compare("IGNORE") == 0) { + const char* a = + this->GetCMakeInstance()->GetCacheDefinition("CMAKE_GENERATOR_PLATFORM"); + bspName = "sim"; + bspName += (a ? a : ""); + } + this->WriteMacros(); this->WriteHighLevelDirectives(); GhsMultiGpj::WriteGpjTag(GhsMultiGpj::PROJECT, this->GetBuildFileStream()); this->WriteDisclaimer(this->GetBuildFileStream()); *this->GetBuildFileStream() << "# Top Level Project File" << std::endl; - if (!fBspName.empty()) { - *this->GetBuildFileStream() << " -bsp " << fBspName << std::endl; - } + *this->GetBuildFileStream() << " -bsp " << bspName << std::endl; + this->WriteCompilerOptions(fOSDir); } @@ -275,8 +298,10 @@ void cmGlobalGhsMultiGenerator::GenerateBuildCommand( const std::string& targetName, const std::string& /*config*/, bool /*fast*/, int jobs, bool /*verbose*/, std::vector<std::string> const& makeOptions) { + const char* gbuild = + this->CMakeInstance->GetCacheDefinition("CMAKE_MAKE_PROGRAM"); makeCommand.push_back( - this->SelectMakeProgram(makeProgram, this->GetGhsBuildCommand())); + this->SelectMakeProgram(makeProgram, (std::string)gbuild)); if (jobs != cmake::NO_BUILD_PARALLEL_LEVEL) { makeCommand.push_back("-parallel"); @@ -313,8 +338,26 @@ void cmGlobalGhsMultiGenerator::WriteMacros() void cmGlobalGhsMultiGenerator::WriteHighLevelDirectives() { - *this->GetBuildFileStream() - << "primaryTarget=arm_integrity.tgt" << std::endl; + /* set primary target */ + std::string tgt; + const char* t = + this->GetCMakeInstance()->GetCacheDefinition("GHS_PRIMARY_TARGET"); + if (t) { + tgt = t; + this->GetCMakeInstance()->MarkCliAsUsed("GHS_PRIMARY_TARGET"); + } else { + const char* a = + this->GetCMakeInstance()->GetCacheDefinition("CMAKE_GENERATOR_PLATFORM"); + const char* p = + this->GetCMakeInstance()->GetCacheDefinition("GHS_TARGET_PLATFORM"); + tgt = (a ? a : ""); + tgt += "_"; + tgt += (p ? p : ""); + tgt += ".tgt"; + } + + *this->GetBuildFileStream() << "primaryTarget=" << tgt << std::endl; + char const* const customization = this->GetCMakeInstance()->GetCacheDefinition("GHS_CUSTOMIZATION"); if (NULL != customization && strlen(customization) > 0) { diff --git a/Source/cmGlobalGhsMultiGenerator.h b/Source/cmGlobalGhsMultiGenerator.h index ef1b66f..13c5113 100644 --- a/Source/cmGlobalGhsMultiGenerator.h +++ b/Source/cmGlobalGhsMultiGenerator.h @@ -40,13 +40,17 @@ public: * Utilized by the generator factory to determine if this generator * supports toolsets. */ - static bool SupportsToolset() { return false; } + static bool SupportsToolset() { return true; } /** * Utilized by the generator factory to determine if this generator * supports platforms. */ - static bool SupportsPlatform() { return false; } + static bool SupportsPlatform() { return true; } + + // Toolset / Platform Support + virtual bool SetGeneratorToolset(std::string const& ts, cmMakefile* mf); + virtual bool SetGeneratorPlatform(std::string const& p, cmMakefile* mf); /** * Try to determine system information such as shared library @@ -93,11 +97,7 @@ protected: std::vector<std::string> const& makeOptions = std::vector<std::string>()); private: - std::string const& GetGhsBuildCommand(); - std::string FindGhsBuildCommand(); - std::string GetCompRoot(); - std::vector<std::string> GetCompRootHardPaths(); - std::vector<std::string> GetCompRootRegistry(); + void GetToolset(cmMakefile* mf, std::string& tsd, std::string& ts); void OpenBuildFileStream(); void WriteMacros(); @@ -124,9 +124,8 @@ private: std::vector<std::string> LibDirs; bool OSDirRelative; - bool GhsBuildCommandInitialized; - std::string GhsBuildCommand; - static const char* DEFAULT_MAKE_PROGRAM; + static const char* DEFAULT_BUILD_PROGRAM; + static const char* DEFAULT_TOOLSET_ROOT; }; #endif |