"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "Source/cmGhsMultiTargetGenerator.cxx" between
cmake-3.13.4.tar.gz and cmake-3.14.0-rc1.tar.gz

About: CMake is a cross-platform build system designed to build, test and package software. Release candidate.

cmGhsMultiTargetGenerator.cxx  (cmake-3.13.4):cmGhsMultiTargetGenerator.cxx  (cmake-3.14.0-rc1)
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */ file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmGhsMultiTargetGenerator.h" #include "cmGhsMultiTargetGenerator.h"
#include "cmComputeLinkInformation.h"
#include "cmGeneratedFileStream.h" #include "cmGeneratedFileStream.h"
#include "cmGeneratorTarget.h" #include "cmGeneratorTarget.h"
#include "cmGlobalGhsMultiGenerator.h" #include "cmGlobalGhsMultiGenerator.h"
#include "cmLinkLineComputer.h" #include "cmLinkLineComputer.h"
#include "cmLocalGhsMultiGenerator.h" #include "cmLocalGhsMultiGenerator.h"
#include "cmMakefile.h" #include "cmMakefile.h"
#include "cmSourceFile.h" #include "cmSourceFile.h"
#include "cmSourceGroup.h"
#include "cmTarget.h" #include "cmTarget.h"
#include <assert.h>
std::string const cmGhsMultiTargetGenerator::DDOption("-dynamic");
cmGhsMultiTargetGenerator::cmGhsMultiTargetGenerator(cmGeneratorTarget* target) cmGhsMultiTargetGenerator::cmGhsMultiTargetGenerator(cmGeneratorTarget* target)
: GeneratorTarget(target) : GeneratorTarget(target)
, LocalGenerator( , LocalGenerator(
static_cast<cmLocalGhsMultiGenerator*>(target->GetLocalGenerator())) static_cast<cmLocalGhsMultiGenerator*>(target->GetLocalGenerator()))
, Makefile(target->Target->GetMakefile()) , Makefile(target->Target->GetMakefile())
, TargetGroup(DetermineIfTargetGroup(target)) , Name(target->GetName())
, DynamicDownload(false)
{
this->RelBuildFilePath = this->GetRelBuildFilePath(target);
this->RelOutputFileName = this->RelBuildFilePath + target->GetName() + ".a";
this->RelBuildFileName = this->RelBuildFilePath;
this->RelBuildFileName += this->GetBuildFileName(target);
std::string absPathToRoot = this->GetAbsPathToRoot(target);
absPathToRoot = this->AddSlashIfNeededToPath(absPathToRoot);
this->AbsBuildFilePath = absPathToRoot + this->RelBuildFilePath;
this->AbsBuildFileName = absPathToRoot + this->RelBuildFileName;
this->AbsOutputFileName = absPathToRoot + this->RelOutputFileName;
}
cmGhsMultiTargetGenerator::~cmGhsMultiTargetGenerator()
{
cmDeleteAll(this->FolderBuildStreams);
}
std::string cmGhsMultiTargetGenerator::GetRelBuildFilePath(
const cmGeneratorTarget* target)
{ {
std::string output = target->GetEffectiveFolderName(); // Store the configuration name that is being used
cmSystemTools::ConvertToUnixSlashes(output); if (const char* config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE")) {
if (!output.empty()) { // Use the build type given by the user.
output += "/"; this->ConfigName = config;
} else {
// No configuration type given.
this->ConfigName.clear();
} }
output += target->GetName() + "/";
return output;
}
std::string cmGhsMultiTargetGenerator::GetAbsPathToRoot(
const cmGeneratorTarget* target)
{
return target->GetLocalGenerator()->GetBinaryDirectory();
}
std::string cmGhsMultiTargetGenerator::GetAbsBuildFilePath(
const cmGeneratorTarget* target)
{
std::string output;
output = cmGhsMultiTargetGenerator::GetAbsPathToRoot(target);
output = cmGhsMultiTargetGenerator::AddSlashIfNeededToPath(output);
output += cmGhsMultiTargetGenerator::GetRelBuildFilePath(target);
return output;
}
std::string cmGhsMultiTargetGenerator::GetRelBuildFileName(
const cmGeneratorTarget* target)
{
std::string output;
output = cmGhsMultiTargetGenerator::GetRelBuildFilePath(target);
output = cmGhsMultiTargetGenerator::AddSlashIfNeededToPath(output);
output += cmGhsMultiTargetGenerator::GetBuildFileName(target);
return output;
} }
std::string cmGhsMultiTargetGenerator::GetBuildFileName( cmGhsMultiTargetGenerator::~cmGhsMultiTargetGenerator()
const cmGeneratorTarget* target)
{ {
std::string output;
output = target->GetName();
output += cmGlobalGhsMultiGenerator::FILE_EXTENSION;
return output;
}
std::string cmGhsMultiTargetGenerator::AddSlashIfNeededToPath(
std::string const& input)
{
std::string output(input);
if (!cmHasLiteralSuffix(output, "/")) {
output += "/";
}
return output;
} }
void cmGhsMultiTargetGenerator::Generate() void cmGhsMultiTargetGenerator::Generate()
{ {
std::vector<cmSourceFile*> objectSources = this->GetSources(); // Determine type of target for this project
if (!objectSources.empty() && this->IncludeThisTarget()) { switch (this->GeneratorTarget->GetType()) {
if (!cmSystemTools::FileExists(this->AbsBuildFilePath.c_str())) { case cmStateEnums::EXECUTABLE: {
cmSystemTools::MakeDirectory(this->AbsBuildFilePath.c_str()); // Get the name of the executable to generate.
} std::string targetName;
cmGlobalGhsMultiGenerator::Open(std::string(""), this->AbsBuildFileName, std::string targetNameImport;
&this->FolderBuildStreams); std::string targetNamePDB;
cmGlobalGhsMultiGenerator::OpenBuildFileStream( this->GeneratorTarget->GetExecutableNames(
this->GetFolderBuildStreams()); targetName, this->TargetNameReal, targetNameImport, targetNamePDB,
std::string config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); this->ConfigName);
if (0 == config.length()) { if (cmGhsMultiTargetGenerator::DetermineIfIntegrityApp()) {
config = "RELEASE"; this->TagType = GhsMultiGpj::INTERGRITY_APPLICATION;
} } else {
const std::string language( this->TagType = GhsMultiGpj::PROGRAM;
this->GeneratorTarget->GetLinkerLanguage(config)); }
config = cmSystemTools::UpperCase(config); break;
this->DynamicDownload = this->DetermineIfDynamicDownload(config, language);
if (this->DynamicDownload) {
*this->GetFolderBuildStreams()
<< "#component integrity_dynamic_download" << std::endl;
}
GhsMultiGpj::WriteGpjTag(this->GetGpjTag(), this->GetFolderBuildStreams());
cmGlobalGhsMultiGenerator::WriteDisclaimer(this->GetFolderBuildStreams());
bool const notKernel = this->IsNotKernel(config, language);
this->WriteTypeSpecifics(config, notKernel);
this->SetCompilerFlags(config, language, notKernel);
this->WriteCompilerFlags(config, language);
this->WriteCompilerDefinitions(config, language);
this->WriteIncludes(config, language);
if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) {
this->WriteTargetLinkLibraries(config, language);
} }
this->WriteCustomCommands(); case cmStateEnums::STATIC_LIBRARY: {
std::string targetName;
std::map<const cmSourceFile*, std::string> objectNames = std::string targetNameSO;
cmGhsMultiTargetGenerator::GetObjectNames( std::string targetNameImport;
&objectSources, this->LocalGenerator, this->GeneratorTarget); std::string targetNamePDB;
this->GeneratorTarget->GetLibraryNames(
this->WriteSources(objectSources, objectNames); targetName, targetNameSO, this->TargetNameReal, targetNameImport,
} targetNamePDB, this->ConfigName);
} this->TagType = GhsMultiGpj::LIBRARY;
break;
bool cmGhsMultiTargetGenerator::IncludeThisTarget() }
{ case cmStateEnums::SHARED_LIBRARY: {
bool output = true; std::string msg = "add_library(<name> SHARED ...) not supported: ";
char const* excludeFromAll = msg += this->Name;
this->GeneratorTarget->GetProperty("EXCLUDE_FROM_ALL"); cmSystemTools::Message(msg);
if (NULL != excludeFromAll && '1' == excludeFromAll[0] && return;
'\0' == excludeFromAll[1]) { }
output = false; case cmStateEnums::OBJECT_LIBRARY: {
} std::string targetName;
return output; std::string targetNameSO;
} std::string targetNameImport;
std::string targetNamePDB;
std::vector<cmSourceFile*> cmGhsMultiTargetGenerator::GetSources() const this->GeneratorTarget->GetLibraryNames(
{ targetName, targetNameSO, this->TargetNameReal, targetNameImport,
std::vector<cmSourceFile*> output; targetNamePDB, this->ConfigName);
std::string config = this->Makefile->GetSafeDefinition("CMAKE_BUILD_TYPE"); this->TagType = GhsMultiGpj::SUBPROJECT;
this->GeneratorTarget->GetSourceFiles(output, config); break;
return output; }
} case cmStateEnums::MODULE_LIBRARY: {
std::string msg = "add_library(<name> MODULE ...) not supported: ";
GhsMultiGpj::Types cmGhsMultiTargetGenerator::GetGpjTag() const msg += this->Name;
{ cmSystemTools::Message(msg);
return cmGhsMultiTargetGenerator::GetGpjTag(this->GeneratorTarget); return;
} }
case cmStateEnums::UTILITY: {
GhsMultiGpj::Types cmGhsMultiTargetGenerator::GetGpjTag( std::string msg = "add_custom_target(<name> ...) not supported: ";
const cmGeneratorTarget* target) msg += this->Name;
{ cmSystemTools::Message(msg);
GhsMultiGpj::Types output; return;
if (cmGhsMultiTargetGenerator::DetermineIfTargetGroup(target)) { }
output = GhsMultiGpj::INTERGRITY_APPLICATION; default:
} else if (target->GetType() == cmStateEnums::STATIC_LIBRARY) { return;
output = GhsMultiGpj::LIBRARY; }
} else {
output = GhsMultiGpj::PROGRAM; // Tell the global generator the name of the project file
} this->GeneratorTarget->Target->SetProperty("GENERATOR_FILE_NAME",
return output; this->Name.c_str());
this->GeneratorTarget->Target->SetProperty(
"GENERATOR_FILE_NAME_EXT", GhsMultiGpj::GetGpjTag(this->TagType));
this->GenerateTarget();
}
void cmGhsMultiTargetGenerator::GenerateTarget()
{
// Open the filestream in copy-if-different mode.
std::string fname = this->LocalGenerator->GetCurrentBinaryDirectory();
fname += "/";
fname += this->Name;
fname += cmGlobalGhsMultiGenerator::FILE_EXTENSION;
cmGeneratedFileStream fout(fname.c_str());
fout.SetCopyIfDifferent(true);
this->GetGlobalGenerator()->WriteFileHeader(fout);
GhsMultiGpj::WriteGpjTag(this->TagType, fout);
const std::string language(
this->GeneratorTarget->GetLinkerLanguage(this->ConfigName));
this->WriteTargetSpecifics(fout, this->ConfigName);
this->SetCompilerFlags(this->ConfigName, language);
this->WriteCompilerFlags(fout, this->ConfigName, language);
this->WriteCompilerDefinitions(fout, this->ConfigName, language);
this->WriteIncludes(fout, this->ConfigName, language);
this->WriteTargetLinkLine(fout, this->ConfigName);
this->WriteCustomCommands(fout);
this->WriteSources(fout);
this->WriteReferences(fout);
fout.Close();
} }
cmGlobalGhsMultiGenerator* cmGhsMultiTargetGenerator::GetGlobalGenerator() cmGlobalGhsMultiGenerator* cmGhsMultiTargetGenerator::GetGlobalGenerator()
const const
{ {
return static_cast<cmGlobalGhsMultiGenerator*>( return static_cast<cmGlobalGhsMultiGenerator*>(
this->LocalGenerator->GetGlobalGenerator()); this->LocalGenerator->GetGlobalGenerator());
} }
void cmGhsMultiTargetGenerator::WriteTypeSpecifics(const std::string& config, void cmGhsMultiTargetGenerator::WriteTargetSpecifics(std::ostream& fout,
bool const notKernel) const std::string& config)
{ {
std::string outputDir(this->GetOutputDirectory(config)); std::string outpath;
std::string outputFilename(this->GetOutputFilename(config)); std::string rootpath = this->LocalGenerator->GetCurrentBinaryDirectory();
if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY) { if (this->TagType != GhsMultiGpj::SUBPROJECT) {
std::string const static_library_suffix = // set target binary file destination
this->Makefile->GetSafeDefinition("CMAKE_STATIC_LIBRARY_SUFFIX"); outpath = this->GeneratorTarget->GetDirectory(config);
*this->GetFolderBuildStreams() outpath =
<< " -o \"" << outputDir << outputFilename << static_library_suffix this->LocalGenerator->MaybeConvertToRelativePath(rootpath, outpath);
<< "\"" << std::endl; fout << " :binDirRelative=\"" << outpath << "\"" << std::endl;
} else if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) { fout << " -o \"" << this->TargetNameReal << "\"" << std::endl;
if (notKernel && !this->IsTargetGroup()) { }
*this->GetFolderBuildStreams() << " -relprog" << std::endl;
} // set target object file destination
if (this->IsTargetGroup()) { outpath = this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
*this->GetFolderBuildStreams() fout << " :outputDirRelative=\"" << outpath << "\"" << std::endl;
<< " -o \"" << outputDir << outputFilename << ".elf\"" << std::endl;
*this->GetFolderBuildStreams()
<< " :extraOutputFile=\"" << outputDir << outputFilename
<< ".elf.ael\"" << std::endl;
} else {
std::string const executable_suffix =
this->Makefile->GetSafeDefinition("CMAKE_EXECUTABLE_SUFFIX");
*this->GetFolderBuildStreams()
<< " -o \"" << outputDir << outputFilename << executable_suffix
<< "\"" << std::endl;
}
}
} }
void cmGhsMultiTargetGenerator::SetCompilerFlags(std::string const& config, void cmGhsMultiTargetGenerator::SetCompilerFlags(std::string const& config,
const std::string& language, const std::string& language)
bool const notKernel)
{ {
std::map<std::string, std::string>::iterator i = std::map<std::string, std::string>::iterator i =
this->FlagsByLanguage.find(language); this->FlagsByLanguage.find(language);
if (i == this->FlagsByLanguage.end()) { if (i == this->FlagsByLanguage.end()) {
std::string flags; std::string flags;
const char* lang = language.c_str(); const char* lang = language.c_str();
if (notKernel) { this->LocalGenerator->AddLanguageFlags(flags, this->GeneratorTarget, lang,
this->LocalGenerator->AddLanguageFlags(flags, this->GeneratorTarget, config);
lang, config);
} else {
this->LocalGenerator->AddLanguageFlags(flags, this->GeneratorTarget,
lang + std::string("_GHS_KERNEL"),
config);
}
this->LocalGenerator->AddCMP0018Flags(flags, this->GeneratorTarget, lang, this->LocalGenerator->AddCMP0018Flags(flags, this->GeneratorTarget, lang,
config); config);
this->LocalGenerator->AddVisibilityPresetFlags( this->LocalGenerator->AddVisibilityPresetFlags(
flags, this->GeneratorTarget, lang); flags, this->GeneratorTarget, lang);
// Append old-style preprocessor definition flags. // Append old-style preprocessor definition flags.
if (this->Makefile->GetDefineFlags() != " ") { if (this->Makefile->GetDefineFlags() != " ") {
this->LocalGenerator->AppendFlags(flags, this->LocalGenerator->AppendFlags(flags,
this->Makefile->GetDefineFlags()); this->Makefile->GetDefineFlags());
} }
skipping to change at line 270 skipping to change at line 204
} }
std::string cmGhsMultiTargetGenerator::GetDefines(const std::string& language, std::string cmGhsMultiTargetGenerator::GetDefines(const std::string& language,
std::string const& config) std::string const& config)
{ {
std::map<std::string, std::string>::iterator i = std::map<std::string, std::string>::iterator i =
this->DefinesByLanguage.find(language); this->DefinesByLanguage.find(language);
if (i == this->DefinesByLanguage.end()) { if (i == this->DefinesByLanguage.end()) {
std::set<std::string> defines; std::set<std::string> defines;
const char* lang = language.c_str(); const char* lang = language.c_str();
// Add the export symbol definition for shared library objects.
if (const char* exportMacro = this->GeneratorTarget->GetExportMacro()) {
this->LocalGenerator->AppendDefines(defines, exportMacro);
}
// Add preprocessor definitions for this target and configuration. // Add preprocessor definitions for this target and configuration.
this->LocalGenerator->AddCompileDefinitions(defines, this->GeneratorTarget, this->LocalGenerator->GetTargetDefines(this->GeneratorTarget, config,
config, language); language, defines);
std::string definesString; std::string definesString;
this->LocalGenerator->JoinDefines(defines, definesString, lang); this->LocalGenerator->JoinDefines(defines, definesString, lang);
std::map<std::string, std::string>::value_type entry(language, std::map<std::string, std::string>::value_type entry(language,
definesString); definesString);
i = this->DefinesByLanguage.insert(entry).first; i = this->DefinesByLanguage.insert(entry).first;
} }
return i->second; return i->second;
} }
void cmGhsMultiTargetGenerator::WriteCompilerFlags(std::string const&, void cmGhsMultiTargetGenerator::WriteCompilerFlags(std::ostream& fout,
std::string const&,
const std::string& language) const std::string& language)
{ {
std::map<std::string, std::string>::iterator flagsByLangI = std::map<std::string, std::string>::iterator flagsByLangI =
this->FlagsByLanguage.find(language); this->FlagsByLanguage.find(language);
if (flagsByLangI != this->FlagsByLanguage.end()) { if (flagsByLangI != this->FlagsByLanguage.end()) {
if (!flagsByLangI->second.empty()) { if (!flagsByLangI->second.empty()) {
*this->GetFolderBuildStreams() std::vector<std::string> ghsCompFlags =
<< " " << flagsByLangI->second << std::endl; cmSystemTools::ParseArguments(flagsByLangI->second.c_str());
for (auto& f : ghsCompFlags) {
fout << " " << f << std::endl;
}
} }
} }
} }
void cmGhsMultiTargetGenerator::WriteCompilerDefinitions( void cmGhsMultiTargetGenerator::WriteCompilerDefinitions(
const std::string& config, const std::string& language) std::ostream& fout, const std::string& config, const std::string& language)
{ {
std::vector<std::string> compileDefinitions; std::vector<std::string> compileDefinitions;
this->GeneratorTarget->GetCompileDefinitions(compileDefinitions, config, this->GeneratorTarget->GetCompileDefinitions(compileDefinitions, config,
language); language);
for (std::vector<std::string>::const_iterator cdI = for (std::vector<std::string>::const_iterator cdI =
compileDefinitions.begin(); compileDefinitions.begin();
cdI != compileDefinitions.end(); ++cdI) { cdI != compileDefinitions.end(); ++cdI) {
*this->GetFolderBuildStreams() << " -D" << (*cdI) << std::endl; fout << " -D" << (*cdI) << std::endl;
} }
} }
void cmGhsMultiTargetGenerator::WriteIncludes(const std::string& config, void cmGhsMultiTargetGenerator::WriteIncludes(std::ostream& fout,
const std::string& config,
const std::string& language) const std::string& language)
{ {
std::vector<std::string> includes; std::vector<std::string> includes;
this->LocalGenerator->GetIncludeDirectories(includes, this->GeneratorTarget, this->LocalGenerator->GetIncludeDirectories(includes, this->GeneratorTarget,
language, config); language, config);
for (std::vector<std::string>::const_iterator includes_i = includes.begin(); for (std::vector<std::string>::const_iterator includes_i = includes.begin();
includes_i != includes.end(); ++includes_i) { includes_i != includes.end(); ++includes_i) {
*this->GetFolderBuildStreams() fout << " -I\"" << *includes_i << "\"" << std::endl;
<< " -I\"" << *includes_i << "\"" << std::endl;
} }
} }
void cmGhsMultiTargetGenerator::WriteTargetLinkLibraries( void cmGhsMultiTargetGenerator::WriteTargetLinkLine(std::ostream& fout,
std::string const& config, std::string const& language) std::string const& config)
{ {
// library directories if (this->TagType == GhsMultiGpj::INTERGRITY_APPLICATION) {
cmTargetDependSet tds = return;
this->GetGlobalGenerator()->GetTargetDirectDepends(this->GeneratorTarget);
for (cmTargetDependSet::iterator tdsI = tds.begin(); tdsI != tds.end();
++tdsI) {
const cmGeneratorTarget* tg = *tdsI;
*this->GetFolderBuildStreams()
<< " -L\"" << GetAbsBuildFilePath(tg) << "\"" << std::endl;
}
// library targets
cmTarget::LinkLibraryVectorType llv =
this->GeneratorTarget->Target->GetOriginalLinkLibraries();
for (cmTarget::LinkLibraryVectorType::const_iterator llvI = llv.begin();
llvI != llv.end(); ++llvI) {
std::string libName = llvI->first;
// if it is a user defined target get the full path to the lib
cmTarget* tg(GetGlobalGenerator()->FindTarget(libName));
if (NULL != tg) {
libName = tg->GetName() + ".a";
}
*this->GetFolderBuildStreams()
<< " -l\"" << libName << "\"" << std::endl;
} }
if (!this->TargetGroup) { std::string linkLibraries;
std::string linkLibraries; std::string flags;
std::string flags; std::string linkFlags;
std::string linkFlags; std::string frameworkPath;
std::string frameworkPath; std::string linkPath;
std::string linkPath;
std::string createRule =
this->GeneratorTarget->GetCreateRuleVariable(language, config);
bool useWatcomQuote =
this->Makefile->IsOn(createRule + "_USE_WATCOM_QUOTE");
std::unique_ptr<cmLinkLineComputer> linkLineComputer(
this->GetGlobalGenerator()->CreateLinkLineComputer(
this->LocalGenerator,
this->LocalGenerator->GetStateSnapshot().GetDirectory()));
linkLineComputer->SetUseWatcomQuote(useWatcomQuote);
this->LocalGenerator->GetTargetFlags( std::unique_ptr<cmLinkLineComputer> linkLineComputer(
linkLineComputer.get(), config, linkLibraries, flags, linkFlags, this->GetGlobalGenerator()->CreateLinkLineComputer(
frameworkPath, linkPath, this->GeneratorTarget); this->LocalGenerator,
linkFlags = cmSystemTools::TrimWhitespace(linkFlags); this->LocalGenerator->GetStateSnapshot().GetDirectory()));
if (!linkPath.empty()) { this->LocalGenerator->GetTargetFlags(
linkPath = " " + linkPath.substr(0U, linkPath.size() - 1U); linkLineComputer.get(), config, linkLibraries, flags, linkFlags,
*this->GetFolderBuildStreams() << linkPath; frameworkPath, linkPath, this->GeneratorTarget);
}
if (!linkFlags.empty()) { // write out link options
*this->GetFolderBuildStreams() << " " << linkFlags << std::endl; std::vector<std::string> lopts =
cmSystemTools::ParseArguments(linkFlags.c_str());
for (auto& l : lopts) {
fout << " " << l << std::endl;
}
// write out link search paths
// must be quoted for paths that contain spaces
std::vector<std::string> lpath =
cmSystemTools::ParseArguments(linkPath.c_str());
for (auto& l : lpath) {
fout << " -L\"" << l << "\"" << std::endl;
}
// write out link libs
// must be quoted for filepaths that contains spaces
std::string cbd = this->LocalGenerator->GetCurrentBinaryDirectory();
std::vector<std::string> llibs =
cmSystemTools::ParseArguments(linkLibraries.c_str());
for (auto& l : llibs) {
if (l.compare(0, 2, "-l") == 0) {
fout << " \"" << l << "\"" << std::endl;
} else {
std::string rl = cmSystemTools::CollapseCombinedPath(cbd, l);
fout << " -l\"" << rl << "\"" << std::endl;
} }
} }
} }
void cmGhsMultiTargetGenerator::WriteCustomCommands() void cmGhsMultiTargetGenerator::WriteCustomCommands(std::ostream& fout)
{ {
WriteCustomCommandsHelper(this->GeneratorTarget->GetPreBuildCommands(), WriteCustomCommandsHelper(fout, this->GeneratorTarget->GetPreBuildCommands(),
cmTarget::PRE_BUILD); cmTarget::PRE_BUILD);
WriteCustomCommandsHelper(this->GeneratorTarget->GetPostBuildCommands(), WriteCustomCommandsHelper(
cmTarget::POST_BUILD); fout, this->GeneratorTarget->GetPostBuildCommands(), cmTarget::POST_BUILD);
} }
void cmGhsMultiTargetGenerator::WriteCustomCommandsHelper( void cmGhsMultiTargetGenerator::WriteCustomCommandsHelper(
std::vector<cmCustomCommand> const& commandsSet, std::ostream& fout, std::vector<cmCustomCommand> const& commandsSet,
cmTarget::CustomCommandType const commandType) cmTarget::CustomCommandType const commandType)
{ {
for (std::vector<cmCustomCommand>::const_iterator commandsSetI = for (std::vector<cmCustomCommand>::const_iterator commandsSetI =
commandsSet.begin(); commandsSet.begin();
commandsSetI != commandsSet.end(); ++commandsSetI) { commandsSetI != commandsSet.end(); ++commandsSetI) {
cmCustomCommandLines const& commands = commandsSetI->GetCommandLines(); cmCustomCommandLines const& commands = commandsSetI->GetCommandLines();
for (cmCustomCommandLines::const_iterator commandI = commands.begin(); for (cmCustomCommandLines::const_iterator commandI = commands.begin();
commandI != commands.end(); ++commandI) { commandI != commands.end(); ++commandI) {
switch (commandType) { switch (commandType) {
case cmTarget::PRE_BUILD: case cmTarget::PRE_BUILD:
*this->GetFolderBuildStreams() << " :preexecShellSafe="; fout << " :preexecShellSafe=";
break; break;
case cmTarget::POST_BUILD: case cmTarget::POST_BUILD:
*this->GetFolderBuildStreams() << " :postexecShellSafe="; fout << " :postexecShellSafe=";
break; break;
default: default:
assert("Only pre and post are supported"); assert("Only pre and post are supported");
} }
cmCustomCommandLine const& command = *commandI; cmCustomCommandLine const& command = *commandI;
for (cmCustomCommandLine::const_iterator commandLineI = command.begin(); for (cmCustomCommandLine::const_iterator commandLineI = command.begin();
commandLineI != command.end(); ++commandLineI) { commandLineI != command.end(); ++commandLineI) {
std::string subCommandE = std::string subCommandE =
this->LocalGenerator->EscapeForShell(*commandLineI, true); this->LocalGenerator->EscapeForShell(*commandLineI, true);
if (!command.empty()) { if (!command.empty()) {
*this->GetFolderBuildStreams() fout << (command.begin() == commandLineI ? "'" : " ");
<< (command.begin() == commandLineI ? "'" : " ");
// Need to double escape backslashes // Need to double escape backslashes
cmSystemTools::ReplaceString(subCommandE, "\\", "\\\\"); cmSystemTools::ReplaceString(subCommandE, "\\", "\\\\");
} }
*this->GetFolderBuildStreams() << subCommandE; fout << subCommandE;
} }
if (!command.empty()) { if (!command.empty()) {
*this->GetFolderBuildStreams() << "'" << std::endl; fout << "'" << std::endl;
} }
} }
} }
} }
std::map<const cmSourceFile*, std::string> void cmGhsMultiTargetGenerator::WriteSourceProperty(std::ostream& fout,
cmGhsMultiTargetGenerator::GetObjectNames( const cmSourceFile* sf,
std::vector<cmSourceFile*>* const objectSources, std::string propName,
cmLocalGhsMultiGenerator* const localGhsMultiGenerator, std::string propFlag)
cmGeneratorTarget* const generatorTarget) {
{ const char* prop = sf->GetProperty(propName);
std::map<std::string, std::vector<cmSourceFile*>> filenameToSource; if (prop) {
std::map<cmSourceFile*, std::string> sourceToFilename; std::vector<std::string> list;
for (std::vector<cmSourceFile*>::const_iterator sf = objectSources->begin(); cmSystemTools::ExpandListArgument(prop, list);
sf != objectSources->end(); ++sf) { for (auto& p : list) {
const std::string filename = fout << " " << propFlag << p << std::endl;
cmSystemTools::GetFilenameName((*sf)->GetFullPath());
const std::string lower_filename = cmSystemTools::LowerCase(filename);
filenameToSource[lower_filename].push_back(*sf);
sourceToFilename[*sf] = lower_filename;
}
std::vector<cmSourceFile*> duplicateSources;
for (std::map<std::string, std::vector<cmSourceFile*>>::const_iterator
msvSourceI = filenameToSource.begin();
msvSourceI != filenameToSource.end(); ++msvSourceI) {
if (msvSourceI->second.size() > 1) {
duplicateSources.insert(duplicateSources.end(),
msvSourceI->second.begin(),
msvSourceI->second.end());
} }
} }
}
void cmGhsMultiTargetGenerator::WriteSources(std::ostream& fout_proj)
{
/* vector of all sources for this target */
std::vector<cmSourceFile*> sources;
this->GeneratorTarget->GetSourceFiles(sources, this->ConfigName);
std::map<const cmSourceFile*, std::string> objectNamesCorrected; /* vector of all groups defined for this target
* -- but the vector is not expanded with sub groups or in any useful order
for (std::vector<cmSourceFile*>::const_iterator sf = */
duplicateSources.begin(); std::vector<cmSourceGroup> sourceGroups = this->Makefile->GetSourceGroups();
sf != duplicateSources.end(); ++sf) {
std::string const longestObjectDirectory( /* for each source file assign it to its group */
cmGhsMultiTargetGenerator::ComputeLongestObjectDirectory( std::map<std::string, std::vector<cmSourceFile*>> groupFiles;
localGhsMultiGenerator, generatorTarget, *sf)); std::set<std::string> groupNames;
std::string objFilenameName = for (auto& sf : sources) {
localGhsMultiGenerator->GetObjectFileNameWithoutTarget(
**sf, longestObjectDirectory);
cmsys::SystemTools::ReplaceString(objFilenameName, "/", "_");
objectNamesCorrected[*sf] = objFilenameName;
}
return objectNamesCorrected;
}
void cmGhsMultiTargetGenerator::WriteSources(
std::vector<cmSourceFile*> const& objectSources,
std::map<const cmSourceFile*, std::string> const& objectNames)
{
for (std::vector<cmSourceFile*>::const_iterator si = objectSources.begin();
si != objectSources.end(); ++si) {
std::vector<cmSourceGroup> sourceGroups(this->Makefile->GetSourceGroups());
std::string const& sourceFullPath = (*si)->GetFullPath();
cmSourceGroup* sourceGroup = cmSourceGroup* sourceGroup =
this->Makefile->FindSourceGroup(sourceFullPath, sourceGroups); this->Makefile->FindSourceGroup(sf->GetFullPath(), sourceGroups);
std::string sgPath = sourceGroup->GetFullName(); std::string gn = sourceGroup->GetFullName();
cmSystemTools::ConvertToUnixSlashes(sgPath); groupFiles[gn].push_back(sf);
cmGlobalGhsMultiGenerator::AddFilesUpToPath( groupNames.insert(gn);
this->GetFolderBuildStreams(), &this->FolderBuildStreams, }
this->LocalGenerator->GetBinaryDirectory().c_str(), sgPath,
GhsMultiGpj::SUBPROJECT, this->RelBuildFilePath); /* list of known groups and the order they are displayed in a project file */
const std::vector<std::string> standardGroups = {
std::string fullSourcePath((*si)->GetFullPath()); "Header Files", "Source Files", "CMake Rules",
if ((*si)->GetExtension() == "int" || (*si)->GetExtension() == "bsp") { "Object Files", "Object Libraries", "Resources"
*this->FolderBuildStreams[sgPath] << fullSourcePath << std::endl; };
/* list of groups in the order they are displayed in a project file*/
std::vector<std::string> groupFilesList(groupFiles.size());
/* put the groups in the order they should be listed
* - standard groups first, and then everything else
* in the order used by std::map.
*/
int i = 0;
for (const std::string& gn : standardGroups) {
auto n = groupNames.find(gn);
if (n != groupNames.end()) {
groupFilesList[i] = *n;
i += 1;
groupNames.erase(gn);
}
}
{ /* catch-all group - is last item */
std::string gn = "";
auto n = groupNames.find(gn);
if (n != groupNames.end()) {
groupFilesList.back() = *n;
groupNames.erase(gn);
}
}
for (auto& n : groupNames) {
groupFilesList[i] = n;
i += 1;
}
/* sort the files within each group */
for (auto& n : groupFilesList) {
std::sort(groupFiles[n].begin(), groupFiles[n].end(),
[](cmSourceFile* l, cmSourceFile* r) {
return l->GetFullPath() < r->GetFullPath();
});
}
/* list of open project files */
std::vector<cmGeneratedFileStream*> gfiles;
/* write files into the proper project file
* -- groups go into main project file
* unless FOLDER property or variable is set.
*/
for (auto& sg : groupFilesList) {
std::ostream* fout;
bool useProjectFile =
cmSystemTools::IsOn(
this->GeneratorTarget->GetProperty("GHS_NO_SOURCE_GROUP_FILE")) ||
cmSystemTools::IsOn(
this->Makefile->GetDefinition("GHS_NO_SOURCE_GROUP_FILE"));
if (useProjectFile || sg.empty()) {
fout = &fout_proj;
} else { } else {
// WORKAROUND: GHS MULTI needs the path to use backslashes without quotes // Open the filestream in copy-if-different mode.
// to open files in search as of version 6.1.6 std::string gname = sg;
cmsys::SystemTools::ReplaceString(fullSourcePath, "/", "\\"); cmsys::SystemTools::ReplaceString(gname, "\\", "_");
*this->FolderBuildStreams[sgPath] << fullSourcePath << std::endl; std::string lpath =
this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget);
lpath += "/";
lpath += gname;
lpath += cmGlobalGhsMultiGenerator::FILE_EXTENSION;
std::string fpath = this->LocalGenerator->GetCurrentBinaryDirectory();
fpath += "/";
fpath += lpath;
cmGeneratedFileStream* f = new cmGeneratedFileStream(fpath.c_str());
f->SetCopyIfDifferent(true);
gfiles.push_back(f);
fout = f;
this->GetGlobalGenerator()->WriteFileHeader(*f);
GhsMultiGpj::WriteGpjTag(GhsMultiGpj::SUBPROJECT, *f);
fout_proj << lpath << " ";
GhsMultiGpj::WriteGpjTag(GhsMultiGpj::SUBPROJECT, fout_proj);
}
if (useProjectFile) {
if (sg.empty()) {
*fout << "{comment} Others" << std::endl;
} else {
*fout << "{comment} " << sg << std::endl;
}
} }
if ("ld" != (*si)->GetExtension() && "int" != (*si)->GetExtension() && /* output rule for each source file */
"bsp" != (*si)->GetExtension()) { for (const cmSourceFile* si : groupFiles[sg]) {
this->WriteObjectLangOverride(this->FolderBuildStreams[sgPath], (*si));
if (objectNames.end() != objectNames.find(*si)) { // Convert filename to native system
*this->FolderBuildStreams[sgPath] // WORKAROUND: GHS MULTI 6.1.4 and 6.1.6 are known to need backslash on
<< " -o \"" << objectNames.find(*si)->second << "\"" << std::endl; // windows when opening some files from the search window.
std::string fname(si->GetFullPath());
cmSystemTools::ConvertToOutputSlashes(fname);
*fout << fname << std::endl;
if ("ld" != si->GetExtension() && "int" != si->GetExtension() &&
"bsp" != si->GetExtension()) {
this->WriteObjectLangOverride(*fout, si);
} }
this->WriteObjectDir(this->FolderBuildStreams[sgPath], this->WriteSourceProperty(*fout, si, "INCLUDE_DIRECTORIES", "-I");
this->AbsBuildFilePath + sgPath); this->WriteSourceProperty(*fout, si, "COMPILE_DEFINITIONS", "-D");
this->WriteSourceProperty(*fout, si, "COMPILE_OPTIONS", "");
/* to avoid clutter in the gui only print out the objectName if it has
* been renamed */
std::string objectName = this->GeneratorTarget->GetObjectName(si);
if (!objectName.empty() &&
this->GeneratorTarget->HasExplicitObjectName(si)) {
*fout << " -o " << objectName << std::endl;
}
} }
} }
for (cmGeneratedFileStream* f : gfiles) {
f->Close();
}
} }
void cmGhsMultiTargetGenerator::WriteObjectLangOverride( void cmGhsMultiTargetGenerator::WriteObjectLangOverride(
cmGeneratedFileStream* fileStream, cmSourceFile* sourceFile) std::ostream& fout, const cmSourceFile* sourceFile)
{ {
const char* rawLangProp = sourceFile->GetProperty("LANGUAGE"); const char* rawLangProp = sourceFile->GetProperty("LANGUAGE");
if (NULL != rawLangProp) { if (NULL != rawLangProp) {
std::string sourceLangProp(rawLangProp); std::string sourceLangProp(rawLangProp);
std::string extension(sourceFile->GetExtension()); std::string extension(sourceFile->GetExtension());
if ("CXX" == sourceLangProp && ("c" == extension || "C" == extension)) { if ("CXX" == sourceLangProp && ("c" == extension || "C" == extension)) {
*fileStream << " -dotciscxx" << std::endl; fout << " -dotciscxx" << std::endl;
} }
} }
} }
void cmGhsMultiTargetGenerator::WriteObjectDir( void cmGhsMultiTargetGenerator::WriteReferences(std::ostream& fout)
cmGeneratedFileStream* fileStream, std::string const& dir)
{ {
std::string workingDir(dir); // This only applies to INTEGRITY Applications
cmSystemTools::ConvertToUnixSlashes(workingDir); if (this->TagType != GhsMultiGpj::INTERGRITY_APPLICATION) {
if (!workingDir.empty()) { return;
workingDir += "/";
}
workingDir += "Objs";
*fileStream << " -object_dir=\"" << workingDir << "\"" << std::endl;
}
std::string cmGhsMultiTargetGenerator::GetOutputDirectory(
const std::string& config) const
{
std::string outputDir(AbsBuildFilePath);
const char* runtimeOutputProp =
this->GeneratorTarget->GetProperty("RUNTIME_OUTPUT_DIRECTORY");
if (NULL != runtimeOutputProp) {
outputDir = runtimeOutputProp;
} }
std::string configCapped(cmSystemTools::UpperCase(config)); // Get the targets that this one depends upon
const char* runtimeOutputSProp = this->GeneratorTarget->GetProperty( cmTargetDependSet unordered =
"RUNTIME_OUTPUT_DIRECTORY_" + configCapped); this->GetGlobalGenerator()->GetTargetDirectDepends(this->GeneratorTarget);
if (NULL != runtimeOutputSProp) { cmGlobalGhsMultiGenerator::OrderedTargetDependSet ordered(unordered,
outputDir = runtimeOutputSProp; this->Name);
} for (auto& t : ordered) {
cmSystemTools::ConvertToUnixSlashes(outputDir); std::string tname = t->GetName();
std::string tpath = t->LocalGenerator->GetCurrentBinaryDirectory();
if (!outputDir.empty()) { std::string rootpath = this->LocalGenerator->GetCurrentBinaryDirectory();
outputDir += "/"; std::string outpath =
} this->LocalGenerator->MaybeConvertToRelativePath(rootpath, tpath) + "/" +
tname + "REF" + cmGlobalGhsMultiGenerator::FILE_EXTENSION;
return outputDir;
} fout << outpath;
fout << " ";
std::string cmGhsMultiTargetGenerator::GetOutputFilename( GhsMultiGpj::WriteGpjTag(GhsMultiGpj::REFERENCE, fout);
const std::string& config) const
{ // Tell the global generator that a refernce project needs to be created
std::string outputFilename(this->GeneratorTarget->GetName()); t->Target->SetProperty("GHS_REFERENCE_PROJECT", "ON");
const char* outputNameProp =
this->GeneratorTarget->GetProperty("OUTPUT_NAME");
if (NULL != outputNameProp) {
outputFilename = outputNameProp;
}
std::string configCapped(cmSystemTools::UpperCase(config));
const char* outputNameSProp =
this->GeneratorTarget->GetProperty(configCapped + "_OUTPUT_NAME");
if (NULL != outputNameSProp) {
outputFilename = outputNameSProp;
}
return outputFilename;
}
std::string cmGhsMultiTargetGenerator::ComputeLongestObjectDirectory(
cmLocalGhsMultiGenerator const* localGhsMultiGenerator,
cmGeneratorTarget* const generatorTarget, cmSourceFile* const sourceFile)
{
std::string dir_max;
dir_max +=
localGhsMultiGenerator->GetMakefile()->GetCurrentBinaryDirectory();
dir_max += "/";
dir_max += generatorTarget->Target->GetName();
dir_max += "/";
std::vector<cmSourceGroup> sourceGroups(
localGhsMultiGenerator->GetMakefile()->GetSourceGroups());
std::string const& sourceFullPath = sourceFile->GetFullPath();
cmSourceGroup* sourceGroup =
localGhsMultiGenerator->GetMakefile()->FindSourceGroup(sourceFullPath,
sourceGroups);
std::string const& sgPath = sourceGroup->GetFullName();
dir_max += sgPath;
dir_max += "/Objs/libs/";
dir_max += generatorTarget->Target->GetName();
dir_max += "/";
return dir_max;
}
bool cmGhsMultiTargetGenerator::IsNotKernel(std::string const& config,
const std::string& language)
{
bool output;
std::vector<std::string> options;
this->GeneratorTarget->GetCompileOptions(options, config, language);
output =
options.end() == std::find(options.begin(), options.end(), "-kernel");
return output;
}
bool cmGhsMultiTargetGenerator::DetermineIfTargetGroup(
const cmGeneratorTarget* target)
{
bool output = false;
std::vector<cmSourceFile*> sources;
std::string config =
target->Target->GetMakefile()->GetSafeDefinition("CMAKE_BUILD_TYPE");
target->GetSourceFiles(sources, config);
for (std::vector<cmSourceFile*>::const_iterator sources_i = sources.begin();
sources.end() != sources_i; ++sources_i) {
if ("int" == (*sources_i)->GetExtension()) {
output = true;
}
} }
return output;
} }
bool cmGhsMultiTargetGenerator::DetermineIfDynamicDownload( bool cmGhsMultiTargetGenerator::DetermineIfIntegrityApp(void)
std::string const& config, const std::string& language) {
{ const char* p = this->GeneratorTarget->GetProperty("ghs_integrity_app");
std::vector<std::string> options; if (p) {
bool output = false; return cmSystemTools::IsOn(
this->GeneratorTarget->GetCompileOptions(options, config, language); this->GeneratorTarget->GetProperty("ghs_integrity_app"));
for (std::vector<std::string>::const_iterator options_i = options.begin(); } else {
options_i != options.end(); ++options_i) { std::vector<cmSourceFile*> sources;
std::string option = *options_i; this->GeneratorTarget->GetSourceFiles(sources, this->ConfigName);
if (this->DDOption == option) { for (auto& sf : sources) {
output = true; if ("int" == sf->GetExtension()) {
return true;
}
} }
return false;
} }
return output;
} }
 End of changes. 55 change blocks. 
460 lines changed or deleted 381 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)