Răsfoiți Sursa

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
Fred Baksik 6 ani în urmă
părinte
comite
2ed2d6b46f

+ 3 - 0
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 <arch>`` can be supplied for setting the target architecture.

+ 1 - 1
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")

+ 41 - 42
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
 {

+ 4 - 3
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<std::string, std::string> FlagsByLanguage;
   std::map<std::string, std::string> DefinesByLanguage;
 
+  std::string TargetNameReal;
   GhsMultiGpj::Types TagType;
   std::string const Name;
+  std::string ConfigName; /* CMAKE_BUILD_TYPE */
 };
 
 #endif // ! cmGhsMultiTargetGenerator_h

+ 12 - 0
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)
 {

+ 2 - 0
Source/cmGlobalGhsMultiGenerator.h

@@ -63,6 +63,8 @@ public:
    */
   bool FindMakeProgram(cmMakefile* mf) override;
 
+  void ComputeTargetObjectDirectory(cmGeneratorTarget* gt) const override;
+
   cmGeneratedFileStream* GetBuildFileStream()
   {
     return this->TargetFolderBuildStreams[""];

+ 9 - 0
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<cmGeneratorTarget*>& remaining)
 {

+ 3 - 0
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<cmGeneratorTarget*>& remaining);