From 2ed2d6b46f9fb8f0742ce60bef16f1d636008136 Mon Sep 17 00:00:00 2001 From: Fred Baksik Date: Sat, 5 Jan 2019 11:01:21 -0500 Subject: GHS: Place build system outputs per target output directives -- Set output and object file locations -- Suffixes are no longer being forced but will now follow the target properties By default GHS tools have no suffix for executable files so CMAKE_EXECUTABLE_SUFFIX was changed to meet this behavior -- Remove #if 0 blocked out code; it has been replaced. Forcing the -relprog option has been removed from non-kernel executable targets. The default value of this option (if it is even available) is determined by the tool-chain for the specified target and platform (Some tool-chains default to -locatedprogram). The use of -relprog can have unexpected results as it cannot always produce a fully relocated executable. -- Clarify use of CMAKE_BUILD_TYPE to control build configuration --- Help/generator/Green Hills MULTI.rst | 3 ++ Modules/Compiler/GHS.cmake | 2 +- Source/cmGhsMultiTargetGenerator.cxx | 83 ++++++++++++++++++------------------ Source/cmGhsMultiTargetGenerator.h | 7 +-- Source/cmGlobalGhsMultiGenerator.cxx | 12 ++++++ Source/cmGlobalGhsMultiGenerator.h | 2 + Source/cmLocalGhsMultiGenerator.cxx | 9 ++++ Source/cmLocalGhsMultiGenerator.h | 3 ++ 8 files changed, 75 insertions(+), 46 deletions(-) diff --git a/Help/generator/Green Hills MULTI.rst b/Help/generator/Green Hills MULTI.rst index 1b4960d..4ee1427 100644 --- a/Help/generator/Green Hills MULTI.rst +++ b/Help/generator/Green Hills MULTI.rst @@ -3,6 +3,9 @@ Green Hills MULTI Generates Green Hills MULTI project files (experimental, work-in-progress). +The buildsystem has predetermined build-configuration settings that can be controlled +via the :variable:`CMAKE_BUILD_TYPE` variable. + Customizations that are used to pick toolset and target system: The ``-A `` can be supplied for setting the target architecture. diff --git a/Modules/Compiler/GHS.cmake b/Modules/Compiler/GHS.cmake index e6a867d..0583a23 100644 --- a/Modules/Compiler/GHS.cmake +++ b/Modules/Compiler/GHS.cmake @@ -3,6 +3,6 @@ if(__COMPILER_GHS) endif() set(__COMPILER_GHS 1) -set(CMAKE_EXECUTABLE_SUFFIX ".as") +set(CMAKE_EXECUTABLE_SUFFIX "") set(CMAKE_LIBRARY_PATH_TERMINATOR "\n") set(CMAKE_LIBRARY_PATH_FLAG " -L") diff --git a/Source/cmGhsMultiTargetGenerator.cxx b/Source/cmGhsMultiTargetGenerator.cxx index 0e0607d..7d2af09 100644 --- a/Source/cmGhsMultiTargetGenerator.cxx +++ b/Source/cmGhsMultiTargetGenerator.cxx @@ -2,6 +2,7 @@ file Copyright.txt or https://cmake.org/licensing for details. */ #include "cmGhsMultiTargetGenerator.h" +#include "cmComputeLinkInformation.h" #include "cmGeneratedFileStream.h" #include "cmGeneratorTarget.h" #include "cmGlobalGhsMultiGenerator.h" @@ -35,6 +36,15 @@ cmGhsMultiTargetGenerator::cmGhsMultiTargetGenerator(cmGeneratorTarget* target) this->AbsBuildFilePath = absPathToRoot + this->RelBuildFilePath; this->AbsBuildFileName = absPathToRoot + this->RelBuildFileName; this->AbsOutputFileName = absPathToRoot + this->RelOutputFileName; + + // Store the configuration name that is being used + if (const char* config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE")) { + // Use the build type given by the user. + this->ConfigName = config; + } else { + // No configuration type given. + this->ConfigName.clear(); + } } cmGhsMultiTargetGenerator::~cmGhsMultiTargetGenerator() @@ -104,6 +114,13 @@ void cmGhsMultiTargetGenerator::Generate() // Determine type of target for this project switch (this->GeneratorTarget->GetType()) { case cmStateEnums::EXECUTABLE: { + // Get the name of the executable to generate. + std::string targetName; + std::string targetNameImport; + std::string targetNamePDB; + this->GeneratorTarget->GetExecutableNames( + targetName, this->TargetNameReal, targetNameImport, targetNamePDB, + this->ConfigName); if (cmGhsMultiTargetGenerator::DetermineIfTargetGroup( this->GeneratorTarget)) { this->TagType = GhsMultiGpj::INTERGRITY_APPLICATION; @@ -113,6 +130,13 @@ void cmGhsMultiTargetGenerator::Generate() break; } case cmStateEnums::STATIC_LIBRARY: { + std::string targetName; + std::string targetNameSO; + std::string targetNameImport; + std::string targetNamePDB; + this->GeneratorTarget->GetLibraryNames( + targetName, targetNameSO, this->TargetNameReal, targetNameImport, + targetNamePDB, this->ConfigName); this->TagType = GhsMultiGpj::LIBRARY; break; } @@ -143,6 +167,7 @@ void cmGhsMultiTargetGenerator::Generate() default: return; } + // Tell the global generator the name of the project file this->GeneratorTarget->Target->SetProperty("GENERATOR_FILE_NAME", this->Name.c_str()); @@ -182,7 +207,7 @@ void cmGhsMultiTargetGenerator::GenerateTarget() cmGlobalGhsMultiGenerator::WriteDisclaimer(&fout); bool const notKernel = this->IsNotKernel(config, language); - this->WriteTypeSpecifics(fout, config, notKernel); + this->WriteTargetSpecifics(fout, config, notKernel); this->SetCompilerFlags(config, language, notKernel); this->WriteCompilerFlags(fout, config, language); this->WriteCompilerDefinitions(fout, config, language); @@ -224,34 +249,22 @@ cmGlobalGhsMultiGenerator* cmGhsMultiTargetGenerator::GetGlobalGenerator() this->LocalGenerator->GetGlobalGenerator()); } -void cmGhsMultiTargetGenerator::WriteTypeSpecifics(std::ostream& fout, - const std::string& config, - bool const notKernel) +void cmGhsMultiTargetGenerator::WriteTargetSpecifics(std::ostream& fout, + const std::string& config, + bool const notKernel) { - std::string outputDir(this->GetOutputDirectory(config)); - std::string outputFilename(this->GetOutputFilename(config)); - - if (this->GeneratorTarget->GetType() == cmStateEnums::STATIC_LIBRARY) { - std::string const& static_library_suffix = - this->Makefile->GetSafeDefinition("CMAKE_STATIC_LIBRARY_SUFFIX"); - fout << " -o \"" << outputDir << outputFilename << static_library_suffix - << "\"" << std::endl; - } else if (this->GeneratorTarget->GetType() == cmStateEnums::EXECUTABLE) { - if (notKernel && !this->IsTargetGroup()) { - fout << " -relprog" << std::endl; - } - if (this->IsTargetGroup()) { - fout << " -o \"" << outputDir << outputFilename << ".elf\"" - << std::endl; - fout << " :extraOutputFile=\"" << outputDir << outputFilename - << ".elf.ael\"" << std::endl; - } else { - std::string const executable_suffix = - this->Makefile->GetSafeDefinition("CMAKE_EXECUTABLE_SUFFIX"); - fout << " -o \"" << outputDir << outputFilename << executable_suffix - << "\"" << std::endl; - } - } + std::string outpath; + std::string rootpath = this->LocalGenerator->GetCurrentBinaryDirectory(); + + // set target binary file destination + outpath = this->GeneratorTarget->GetDirectory(config); + outpath = this->LocalGenerator->ConvertToRelativePath(rootpath, outpath); + fout << " :binDirRelative=\"" << outpath << "\"" << std::endl; + fout << " -o \"" << this->TargetNameReal << "\"" << std::endl; + + // set target object file destination + outpath = this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget); + fout << " :outputDirRelative=\"" << outpath << "\"" << std::endl; } void cmGhsMultiTargetGenerator::SetCompilerFlags(std::string const& config, @@ -643,8 +656,6 @@ void cmGhsMultiTargetGenerator::WriteSources(std::ostream& fout_proj) *fout << " -o \"" << objectNames.find(si)->second << "\"" << std::endl; } - - this->WriteObjectDir(*fout, this->AbsBuildFilePath); } } } @@ -667,18 +678,6 @@ void cmGhsMultiTargetGenerator::WriteObjectLangOverride( } } -void cmGhsMultiTargetGenerator::WriteObjectDir(std::ostream& fout, - std::string const& dir) -{ - std::string workingDir(dir); - cmSystemTools::ConvertToUnixSlashes(workingDir); - if (!workingDir.empty()) { - workingDir += "/"; - } - workingDir += "Objs"; - fout << " -object_dir=\"" << workingDir << "\"" << std::endl; -} - std::string cmGhsMultiTargetGenerator::GetOutputDirectory( const std::string& config) const { diff --git a/Source/cmGhsMultiTargetGenerator.h b/Source/cmGhsMultiTargetGenerator.h index 6ba110a..4523498 100644 --- a/Source/cmGhsMultiTargetGenerator.h +++ b/Source/cmGhsMultiTargetGenerator.h @@ -60,8 +60,8 @@ private: bool IsTargetGroup() const { return this->TargetGroup; } - void WriteTypeSpecifics(std::ostream& fout, const std::string& config, - bool notKernel); + void WriteTargetSpecifics(std::ostream& fout, const std::string& config, + bool notKernel); void WriteCompilerFlags(std::ostream& fout, const std::string& config, const std::string& language); void WriteCompilerDefinitions(std::ostream& fout, const std::string& config, @@ -87,7 +87,6 @@ private: cmGeneratorTarget* generatorTarget); static void WriteObjectLangOverride(std::ostream* fout, const cmSourceFile* sourceFile); - static void WriteObjectDir(std::ostream& fout, std::string const& dir); std::string GetOutputDirectory(const std::string& config) const; std::string GetOutputFilename(const std::string& config) const; static std::string ComputeLongestObjectDirectory( @@ -115,8 +114,10 @@ private: std::map FlagsByLanguage; std::map DefinesByLanguage; + std::string TargetNameReal; GhsMultiGpj::Types TagType; std::string const Name; + std::string ConfigName; /* CMAKE_BUILD_TYPE */ }; #endif // ! cmGhsMultiTargetGenerator_h diff --git a/Source/cmGlobalGhsMultiGenerator.cxx b/Source/cmGlobalGhsMultiGenerator.cxx index f0f1154..7d1e594 100644 --- a/Source/cmGlobalGhsMultiGenerator.cxx +++ b/Source/cmGlobalGhsMultiGenerator.cxx @@ -41,6 +41,18 @@ void cmGlobalGhsMultiGenerator::GetDocumentation(cmDocumentationEntry& entry) "Generates Green Hills MULTI files (experimental, work-in-progress)."; } +void cmGlobalGhsMultiGenerator::ComputeTargetObjectDirectory( + cmGeneratorTarget* gt) const +{ + // Compute full path to object file directory for this target. + std::string dir; + dir += gt->LocalGenerator->GetCurrentBinaryDirectory(); + dir += "/"; + dir += gt->LocalGenerator->GetTargetDirectory(gt); + dir += "/"; + gt->ObjectDirectory = dir; +} + bool cmGlobalGhsMultiGenerator::SetGeneratorToolset(std::string const& ts, cmMakefile* mf) { diff --git a/Source/cmGlobalGhsMultiGenerator.h b/Source/cmGlobalGhsMultiGenerator.h index 8b81ba3..d992f89 100644 --- a/Source/cmGlobalGhsMultiGenerator.h +++ b/Source/cmGlobalGhsMultiGenerator.h @@ -63,6 +63,8 @@ public: */ bool FindMakeProgram(cmMakefile* mf) override; + void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const override; + cmGeneratedFileStream* GetBuildFileStream() { return this->TargetFolderBuildStreams[""]; diff --git a/Source/cmLocalGhsMultiGenerator.cxx b/Source/cmLocalGhsMultiGenerator.cxx index 3679c3e..b539a1c 100644 --- a/Source/cmLocalGhsMultiGenerator.cxx +++ b/Source/cmLocalGhsMultiGenerator.cxx @@ -18,6 +18,15 @@ cmLocalGhsMultiGenerator::~cmLocalGhsMultiGenerator() { } +std::string cmLocalGhsMultiGenerator::GetTargetDirectory( + cmGeneratorTarget const* target) const +{ + std::string dir; + dir += target->GetName(); + dir += ".dir"; + return dir; +} + void cmLocalGhsMultiGenerator::GenerateTargetsDepthFirst( cmGeneratorTarget* target, std::vector& remaining) { diff --git a/Source/cmLocalGhsMultiGenerator.h b/Source/cmLocalGhsMultiGenerator.h index 8e88205..1f55420 100644 --- a/Source/cmLocalGhsMultiGenerator.h +++ b/Source/cmLocalGhsMultiGenerator.h @@ -25,6 +25,9 @@ public: */ virtual void Generate(); + std::string GetTargetDirectory( + cmGeneratorTarget const* target) const override; + private: void GenerateTargetsDepthFirst(cmGeneratorTarget* target, std::vector& remaining); -- cgit v0.12