cmake/Source/cmGlobalGhsMultiGenerator.cxx

539 lines
18 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2015-08-17 11:37:30 +02:00
#include "cmGlobalGhsMultiGenerator.h"
2016-07-09 11:21:54 +02:00
2017-07-20 19:35:53 +02:00
#include "cmsys/SystemTools.hxx"
2017-04-14 19:02:05 +02:00
#include "cmAlgorithms.h"
#include "cmDocumentationEntry.h"
2016-07-09 11:21:54 +02:00
#include "cmGeneratedFileStream.h"
2016-10-30 18:24:19 +01:00
#include "cmGeneratorTarget.h"
2016-07-09 11:21:54 +02:00
#include "cmGhsMultiTargetGenerator.h"
2015-08-17 11:37:30 +02:00
#include "cmLocalGhsMultiGenerator.h"
#include "cmMakefile.h"
#include "cmVersion.h"
2016-07-09 11:21:54 +02:00
const char* cmGlobalGhsMultiGenerator::FILE_EXTENSION = ".gpj";
2018-10-28 12:09:07 +01:00
const char* cmGlobalGhsMultiGenerator::DEFAULT_BUILD_PROGRAM = "gbuild.exe";
const char* cmGlobalGhsMultiGenerator::DEFAULT_TOOLSET_ROOT = "C:/ghs";
2015-08-17 11:37:30 +02:00
cmGlobalGhsMultiGenerator::cmGlobalGhsMultiGenerator(cmake* cm)
2016-07-09 11:21:54 +02:00
: cmGlobalGenerator(cm)
, OSDirRelative(false)
2015-08-17 11:37:30 +02:00
{
}
cmGlobalGhsMultiGenerator::~cmGlobalGhsMultiGenerator()
{
cmDeleteAll(TargetFolderBuildStreams);
}
2016-07-09 11:21:54 +02:00
cmLocalGenerator* cmGlobalGhsMultiGenerator::CreateLocalGenerator(
cmMakefile* mf)
2015-08-17 11:37:30 +02:00
{
2015-11-17 17:22:37 +01:00
return new cmLocalGhsMultiGenerator(this, mf);
2015-08-17 11:37:30 +02:00
}
2016-07-09 11:21:54 +02:00
void cmGlobalGhsMultiGenerator::GetDocumentation(cmDocumentationEntry& entry)
2015-08-17 11:37:30 +02:00
{
entry.Name = GetActualName();
entry.Brief =
"Generates Green Hills MULTI files (experimental, work-in-progress).";
}
2018-10-28 12:09:07 +01:00
bool cmGlobalGhsMultiGenerator::SetGeneratorToolset(std::string const& ts,
cmMakefile* mf)
2015-08-17 11:37:30 +02:00
{
2018-10-28 12:09:07 +01:00
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());
2015-08-17 11:37:30 +02:00
mf->AddDefinition("CMAKE_C_COMPILER_ID_RUN", "TRUE");
mf->AddDefinition("CMAKE_C_COMPILER_ID", "GHS");
mf->AddDefinition("CMAKE_C_COMPILER_FORCED", "TRUE");
2018-10-28 12:09:07 +01:00
mf->AddDefinition("CMAKE_CXX_COMPILER", gbuild.c_str());
2015-08-17 11:37:30 +02:00
mf->AddDefinition("CMAKE_CXX_COMPILER_ID_RUN", "TRUE");
mf->AddDefinition("CMAKE_CXX_COMPILER_ID", "GHS");
mf->AddDefinition("CMAKE_CXX_COMPILER_FORCED", "TRUE");
2018-10-28 12:09:07 +01:00
return true;
2015-08-17 11:37:30 +02:00
}
2018-10-28 12:09:07 +01:00
bool cmGlobalGhsMultiGenerator::SetGeneratorPlatform(std::string const& p,
cmMakefile* mf)
2015-08-17 11:37:30 +02:00
{
2018-10-28 12:09:07 +01:00
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);
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
2018-10-28 12:09:07 +01:00
const char* tgtPlatform = mf->GetDefinition("GHS_TARGET_PLATFORM");
if (tgtPlatform == nullptr) {
tgtPlatform = "integrity";
2016-07-09 11:21:54 +02:00
}
2018-10-28 12:09:07 +01:00
/* store the platform name for later use */
mf->AddCacheDefinition("GHS_TARGET_PLATFORM", tgtPlatform,
"Name of GHS target platform.",
cmStateEnums::INTERNAL);
return true;
2015-08-17 11:37:30 +02:00
}
2018-10-28 12:09:07 +01:00
void cmGlobalGhsMultiGenerator::EnableLanguage(
std::vector<std::string> const& l, cmMakefile* mf, bool optional)
2015-08-17 11:37:30 +02:00
{
2018-10-28 12:09:07 +01:00
mf->AddDefinition("CMAKE_SYSTEM_NAME", "GHS-MULTI");
mf->AddDefinition("GHSMULTI", "1"); // identifier for user CMake files
this->cmGlobalGenerator::EnableLanguage(l, mf, optional);
2015-08-17 11:37:30 +02:00
}
2018-10-28 12:09:07 +01:00
bool cmGlobalGhsMultiGenerator::FindMakeProgram(cmMakefile* /*mf*/)
2015-08-17 11:37:30 +02:00
{
2018-10-28 12:09:07 +01:00
// 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.
2015-08-17 11:37:30 +02:00
2018-10-28 12:09:07 +01:00
return true;
2015-08-17 11:37:30 +02:00
}
2018-10-28 12:09:07 +01:00
void cmGlobalGhsMultiGenerator::GetToolset(cmMakefile* mf, std::string& tsd,
std::string& ts)
2015-08-17 11:37:30 +02:00
{
2018-10-28 12:09:07 +01:00
const char* ghsRoot = mf->GetDefinition("GHS_TOOLSET_ROOT");
if (!ghsRoot) {
ghsRoot = DEFAULT_TOOLSET_ROOT;
2016-07-09 11:21:54 +02:00
}
2018-10-28 12:09:07 +01:00
tsd = ghsRoot;
2015-08-17 11:37:30 +02:00
2018-10-28 12:09:07 +01:00
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 = "";
}
}
2015-08-17 11:37:30 +02:00
}
void cmGlobalGhsMultiGenerator::OpenBuildFileStream(
2016-07-09 11:21:54 +02:00
std::string const& filepath, cmGeneratedFileStream** filestream)
2015-08-17 11:37:30 +02:00
{
// Get a stream where to generate things.
2016-07-09 11:21:54 +02:00
if (NULL == *filestream) {
2015-08-17 11:37:30 +02:00
*filestream = new cmGeneratedFileStream(filepath.c_str());
2016-07-09 11:21:54 +02:00
if (NULL != *filestream) {
2015-08-17 11:37:30 +02:00
OpenBuildFileStream(*filestream);
}
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
}
void cmGlobalGhsMultiGenerator::OpenBuildFileStream(
2016-07-09 11:21:54 +02:00
cmGeneratedFileStream* filestream)
2015-08-17 11:37:30 +02:00
{
*filestream << "#!gbuild" << std::endl;
}
void cmGlobalGhsMultiGenerator::OpenBuildFileStream()
{
// Compute GHS MULTI's build file path.
std::string buildFilePath =
this->GetCMakeInstance()->GetHomeOutputDirectory();
buildFilePath += "/";
buildFilePath += "default";
buildFilePath += FILE_EXTENSION;
this->Open(std::string(""), buildFilePath, &this->TargetFolderBuildStreams);
OpenBuildFileStream(GetBuildFileStream());
2016-07-09 11:21:54 +02:00
char const* osDir =
2015-08-17 11:37:30 +02:00
this->GetCMakeInstance()->GetCacheDefinition("GHS_OS_DIR");
2016-07-09 11:21:54 +02:00
if (NULL == osDir) {
2015-08-17 11:37:30 +02:00
osDir = "";
cmSystemTools::Error("GHS_OS_DIR cache variable must be set");
2016-07-09 11:21:54 +02:00
} else {
2015-08-17 11:37:30 +02:00
this->GetCMakeInstance()->MarkCliAsUsed("GHS_OS_DIR");
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
std::string fOSDir(this->trimQuotes(osDir));
2016-07-09 11:21:54 +02:00
std::replace(fOSDir.begin(), fOSDir.end(), '\\', '/');
if (!fOSDir.empty() && ('c' == fOSDir[0] || 'C' == fOSDir[0])) {
2015-08-17 11:37:30 +02:00
this->OSDirRelative = false;
2016-07-09 11:21:54 +02:00
} else {
2015-08-17 11:37:30 +02:00
this->OSDirRelative = true;
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
2018-10-28 12:09:07 +01:00
std::string bspName;
char const* bspCache =
2015-08-17 11:37:30 +02:00
this->GetCMakeInstance()->GetCacheDefinition("GHS_BSP_NAME");
2018-10-28 12:09:07 +01:00
if (bspCache) {
bspName = bspCache;
2015-08-17 11:37:30 +02:00
this->GetCMakeInstance()->MarkCliAsUsed("GHS_BSP_NAME");
2016-07-09 11:21:54 +02:00
}
2018-10-28 12:09:07 +01:00
if (bspName.empty() || bspName.compare("IGNORE") == 0) {
const char* a =
this->GetCMakeInstance()->GetCacheDefinition("CMAKE_GENERATOR_PLATFORM");
bspName = "sim";
bspName += (a ? a : "");
}
2015-08-17 11:37:30 +02:00
this->WriteMacros();
this->WriteHighLevelDirectives();
GhsMultiGpj::WriteGpjTag(GhsMultiGpj::PROJECT, this->GetBuildFileStream());
this->WriteDisclaimer(this->GetBuildFileStream());
*this->GetBuildFileStream() << "# Top Level Project File" << std::endl;
2018-10-28 12:09:07 +01:00
*this->GetBuildFileStream() << " -bsp " << bspName << std::endl;
2015-08-17 11:37:30 +02:00
this->WriteCompilerOptions(fOSDir);
}
void cmGlobalGhsMultiGenerator::CloseBuildFileStream(
2016-07-09 11:21:54 +02:00
cmGeneratedFileStream** filestream)
2015-08-17 11:37:30 +02:00
{
2016-07-09 11:21:54 +02:00
if (filestream) {
2015-08-17 11:37:30 +02:00
delete *filestream;
*filestream = NULL;
2016-07-09 11:21:54 +02:00
} else {
2015-08-17 11:37:30 +02:00
cmSystemTools::Error("Build file stream was not open.");
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
}
void cmGlobalGhsMultiGenerator::Generate()
{
this->cmGlobalGenerator::Generate();
2016-07-09 11:21:54 +02:00
if (!this->LocalGenerators.empty()) {
2015-08-17 11:37:30 +02:00
this->OpenBuildFileStream();
// Build all the folder build files
2016-07-09 11:21:54 +02:00
for (unsigned int i = 0; i < this->LocalGenerators.size(); ++i) {
cmLocalGhsMultiGenerator* lg =
static_cast<cmLocalGhsMultiGenerator*>(this->LocalGenerators[i]);
2018-01-26 17:06:56 +01:00
const std::vector<cmGeneratorTarget*>& tgts = lg->GetGeneratorTargets();
2016-03-13 13:35:51 +01:00
this->UpdateBuildFiles(tgts);
2015-08-17 11:37:30 +02:00
}
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
cmDeleteAll(TargetFolderBuildStreams);
this->TargetFolderBuildStreams.clear();
}
void cmGlobalGhsMultiGenerator::GenerateBuildCommand(
2016-07-09 11:21:54 +02:00
std::vector<std::string>& makeCommand, const std::string& makeProgram,
const std::string& /*projectName*/, const std::string& /*projectDir*/,
const std::string& targetName, const std::string& /*config*/, bool /*fast*/,
2018-08-09 18:06:22 +02:00
int jobs, bool /*verbose*/, std::vector<std::string> const& makeOptions)
2015-08-17 11:37:30 +02:00
{
2018-10-28 12:09:07 +01:00
const char* gbuild =
this->CMakeInstance->GetCacheDefinition("CMAKE_MAKE_PROGRAM");
2015-08-17 11:37:30 +02:00
makeCommand.push_back(
2018-10-28 12:09:07 +01:00
this->SelectMakeProgram(makeProgram, (std::string)gbuild));
2016-07-09 11:21:54 +02:00
2018-08-09 18:06:22 +02:00
if (jobs != cmake::NO_BUILD_PARALLEL_LEVEL) {
makeCommand.push_back("-parallel");
if (jobs != cmake::DEFAULT_BUILD_PARALLEL_LEVEL) {
makeCommand.push_back(std::to_string(jobs));
}
}
2016-07-09 11:21:54 +02:00
makeCommand.insert(makeCommand.end(), makeOptions.begin(),
makeOptions.end());
if (!targetName.empty()) {
if (targetName == "clean") {
2015-08-17 11:37:30 +02:00
makeCommand.push_back("-clean");
2016-07-09 11:21:54 +02:00
} else {
2015-08-17 11:37:30 +02:00
makeCommand.push_back(targetName);
}
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
}
void cmGlobalGhsMultiGenerator::WriteMacros()
{
2016-07-09 11:21:54 +02:00
char const* ghsGpjMacros =
2015-08-17 11:37:30 +02:00
this->GetCMakeInstance()->GetCacheDefinition("GHS_GPJ_MACROS");
2016-07-09 11:21:54 +02:00
if (NULL != ghsGpjMacros) {
2015-08-17 11:37:30 +02:00
std::vector<std::string> expandedList;
cmSystemTools::ExpandListArgument(std::string(ghsGpjMacros), expandedList);
for (std::vector<std::string>::const_iterator expandedListI =
expandedList.begin();
2016-07-09 11:21:54 +02:00
expandedListI != expandedList.end(); ++expandedListI) {
2015-08-17 11:37:30 +02:00
*this->GetBuildFileStream() << "macro " << *expandedListI << std::endl;
}
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
}
void cmGlobalGhsMultiGenerator::WriteHighLevelDirectives()
{
2018-10-28 12:09:07 +01:00
/* 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;
2016-07-09 11:21:54 +02:00
char const* const customization =
2015-08-17 11:37:30 +02:00
this->GetCMakeInstance()->GetCacheDefinition("GHS_CUSTOMIZATION");
2016-07-09 11:21:54 +02:00
if (NULL != customization && strlen(customization) > 0) {
*this->GetBuildFileStream()
<< "customization=" << trimQuotes(customization) << std::endl;
2015-08-17 11:37:30 +02:00
this->GetCMakeInstance()->MarkCliAsUsed("GHS_CUSTOMIZATION");
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
}
2016-07-09 11:21:54 +02:00
void cmGlobalGhsMultiGenerator::WriteCompilerOptions(std::string const& fOSDir)
2015-08-17 11:37:30 +02:00
{
2018-08-09 18:06:22 +02:00
*this->GetBuildFileStream()
<< " -os_dir=\"" << fOSDir << "\"" << std::endl;
2015-08-17 11:37:30 +02:00
}
2016-07-09 11:21:54 +02:00
void cmGlobalGhsMultiGenerator::WriteDisclaimer(std::ostream* os)
2015-08-17 11:37:30 +02:00
{
(*os) << "#" << std::endl
<< "# CMAKE generated file: DO NOT EDIT!" << std::endl
<< "# Generated by \"" << GetActualName() << "\""
<< " Generator, CMake Version " << cmVersion::GetMajorVersion() << "."
<< cmVersion::GetMinorVersion() << std::endl
<< "#" << std::endl;
}
void cmGlobalGhsMultiGenerator::AddFilesUpToPath(
2016-07-09 11:21:54 +02:00
cmGeneratedFileStream* mainBuildFile,
std::map<std::string, cmGeneratedFileStream*>* targetFolderBuildStreams,
char const* homeOutputDirectory, std::string const& path,
GhsMultiGpj::Types projType, std::string const& relPath)
2015-08-17 11:37:30 +02:00
{
std::string workingPath(path);
cmSystemTools::ConvertToUnixSlashes(workingPath);
2018-10-28 12:09:07 +01:00
std::vector<std::string> splitPath = cmSystemTools::SplitString(workingPath);
2015-08-17 11:37:30 +02:00
std::string workingRelPath(relPath);
cmSystemTools::ConvertToUnixSlashes(workingRelPath);
2016-07-09 11:21:54 +02:00
if (!workingRelPath.empty()) {
2015-08-17 11:37:30 +02:00
workingRelPath += "/";
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
std::string pathUpTo;
2018-10-28 12:09:07 +01:00
for (std::vector<std::string>::const_iterator splitPathI = splitPath.begin();
2016-07-09 11:21:54 +02:00
splitPath.end() != splitPathI; ++splitPathI) {
2015-08-17 11:37:30 +02:00
pathUpTo += *splitPathI;
if (targetFolderBuildStreams->end() ==
2016-07-09 11:21:54 +02:00
targetFolderBuildStreams->find(pathUpTo)) {
2015-08-17 11:37:30 +02:00
AddFilesUpToPathNewBuildFile(
2016-07-09 11:21:54 +02:00
mainBuildFile, targetFolderBuildStreams, homeOutputDirectory, pathUpTo,
splitPath.begin() == splitPathI, workingRelPath, projType);
}
2015-08-17 11:37:30 +02:00
AddFilesUpToPathAppendNextFile(targetFolderBuildStreams, pathUpTo,
splitPathI, splitPath.end(), projType);
pathUpTo += "/";
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
}
void cmGlobalGhsMultiGenerator::Open(
2016-07-09 11:21:54 +02:00
std::string const& mapKeyName, std::string const& fileName,
std::map<std::string, cmGeneratedFileStream*>* fileMap)
2015-08-17 11:37:30 +02:00
{
2016-07-09 11:21:54 +02:00
if (fileMap->end() == fileMap->find(fileName)) {
cmGeneratedFileStream* temp(new cmGeneratedFileStream);
2015-08-17 11:37:30 +02:00
temp->open(fileName.c_str());
(*fileMap)[mapKeyName] = temp;
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
}
void cmGlobalGhsMultiGenerator::AddFilesUpToPathNewBuildFile(
2016-07-09 11:21:54 +02:00
cmGeneratedFileStream* mainBuildFile,
std::map<std::string, cmGeneratedFileStream*>* targetFolderBuildStreams,
char const* homeOutputDirectory, std::string const& pathUpTo,
bool const isFirst, std::string const& relPath,
2015-08-17 11:37:30 +02:00
GhsMultiGpj::Types const projType)
{
// create folders up to file path
std::string absPath = std::string(homeOutputDirectory) + "/" + relPath;
std::string newPath = absPath + pathUpTo;
2016-07-09 11:21:54 +02:00
if (!cmSystemTools::FileExists(newPath.c_str())) {
2015-08-17 11:37:30 +02:00
cmSystemTools::MakeDirectory(newPath.c_str());
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
// Write out to filename for first time
std::string relFilename(GetFileNameFromPath(pathUpTo));
std::string absFilename = absPath + relFilename;
Open(pathUpTo, absFilename, targetFolderBuildStreams);
OpenBuildFileStream((*targetFolderBuildStreams)[pathUpTo]);
GhsMultiGpj::WriteGpjTag(projType, (*targetFolderBuildStreams)[pathUpTo]);
WriteDisclaimer((*targetFolderBuildStreams)[pathUpTo]);
// Add to main build file
2016-07-09 11:21:54 +02:00
if (isFirst) {
2015-08-17 11:37:30 +02:00
*mainBuildFile << relFilename << " ";
GhsMultiGpj::WriteGpjTag(projType, mainBuildFile);
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
}
void cmGlobalGhsMultiGenerator::AddFilesUpToPathAppendNextFile(
2016-07-09 11:21:54 +02:00
std::map<std::string, cmGeneratedFileStream*>* targetFolderBuildStreams,
std::string const& pathUpTo,
2018-10-28 12:09:07 +01:00
std::vector<std::string>::const_iterator splitPathI,
std::vector<std::string>::const_iterator end,
2015-08-17 11:37:30 +02:00
GhsMultiGpj::Types const projType)
{
2018-10-28 12:09:07 +01:00
std::vector<std::string>::const_iterator splitPathNextI = splitPathI + 1;
2015-08-17 11:37:30 +02:00
if (end != splitPathNextI &&
targetFolderBuildStreams->end() ==
2016-07-09 11:21:54 +02:00
targetFolderBuildStreams->find(pathUpTo + "/" + *splitPathNextI)) {
2015-08-17 11:37:30 +02:00
std::string nextFilename(*splitPathNextI);
nextFilename = GetFileNameFromPath(nextFilename);
*(*targetFolderBuildStreams)[pathUpTo] << nextFilename << " ";
GhsMultiGpj::WriteGpjTag(projType, (*targetFolderBuildStreams)[pathUpTo]);
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
}
2016-07-09 11:21:54 +02:00
std::string cmGlobalGhsMultiGenerator::GetFileNameFromPath(
std::string const& path)
2015-08-17 11:37:30 +02:00
{
std::string output(path);
2016-07-09 11:21:54 +02:00
if (!path.empty()) {
2015-08-17 11:37:30 +02:00
cmSystemTools::ConvertToUnixSlashes(output);
2018-10-28 12:09:07 +01:00
std::vector<std::string> splitPath = cmSystemTools::SplitString(output);
2015-08-17 11:37:30 +02:00
output += "/" + splitPath.back() + FILE_EXTENSION;
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
return output;
}
void cmGlobalGhsMultiGenerator::UpdateBuildFiles(
2018-01-26 17:06:56 +01:00
const std::vector<cmGeneratorTarget*>& tgts)
2015-08-17 11:37:30 +02:00
{
2018-01-26 17:06:56 +01:00
for (std::vector<cmGeneratorTarget*>::const_iterator tgtsI = tgts.begin();
2016-07-09 11:21:54 +02:00
tgtsI != tgts.end(); ++tgtsI) {
const cmGeneratorTarget* tgt = *tgtsI;
if (IsTgtForBuild(tgt)) {
2017-04-14 19:02:05 +02:00
std::string folderName = tgt->GetEffectiveFolderName();
2015-08-17 11:37:30 +02:00
if (this->TargetFolderBuildStreams.end() ==
2016-07-09 11:21:54 +02:00
this->TargetFolderBuildStreams.find(folderName)) {
2015-08-17 11:37:30 +02:00
this->AddFilesUpToPath(
GetBuildFileStream(), &this->TargetFolderBuildStreams,
2018-04-23 21:13:27 +02:00
this->GetCMakeInstance()->GetHomeOutputDirectory().c_str(),
folderName, GhsMultiGpj::PROJECT);
2016-07-09 11:21:54 +02:00
}
2018-10-28 12:09:07 +01:00
std::vector<std::string> splitPath = cmSystemTools::SplitString(
2016-07-09 11:21:54 +02:00
cmGhsMultiTargetGenerator::GetRelBuildFileName(tgt));
2015-08-17 11:37:30 +02:00
std::string foldNameRelBuildFile(*(splitPath.end() - 2) + "/" +
splitPath.back());
*this->TargetFolderBuildStreams[folderName] << foldNameRelBuildFile
<< " ";
2016-07-09 11:21:54 +02:00
GhsMultiGpj::WriteGpjTag(cmGhsMultiTargetGenerator::GetGpjTag(tgt),
2015-08-17 11:37:30 +02:00
this->TargetFolderBuildStreams[folderName]);
}
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
}
2016-07-09 11:21:54 +02:00
bool cmGlobalGhsMultiGenerator::IsTgtForBuild(const cmGeneratorTarget* tgt)
2015-08-17 11:37:30 +02:00
{
const std::string config =
2016-03-13 13:35:51 +01:00
tgt->Target->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE");
2016-07-09 11:21:54 +02:00
std::vector<cmSourceFile*> tgtSources;
2015-08-17 11:37:30 +02:00
tgt->GetSourceFiles(tgtSources, config);
bool tgtInBuild = true;
2016-07-09 11:21:54 +02:00
char const* excludeFromAll = tgt->GetProperty("EXCLUDE_FROM_ALL");
2015-08-17 11:37:30 +02:00
if (NULL != excludeFromAll && '1' == excludeFromAll[0] &&
2016-07-09 11:21:54 +02:00
'\0' == excludeFromAll[1]) {
2015-08-17 11:37:30 +02:00
tgtInBuild = false;
}
return !tgtSources.empty() && tgtInBuild;
}
2016-07-09 11:21:54 +02:00
std::string cmGlobalGhsMultiGenerator::trimQuotes(std::string const& str)
2015-08-17 11:37:30 +02:00
{
std::string result;
result.reserve(str.size());
2016-07-09 11:21:54 +02:00
for (const char* ch = str.c_str(); *ch != '\0'; ++ch) {
if (*ch != '"') {
2015-08-17 11:37:30 +02:00
result += *ch;
}
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
return result;
}