浏览代码

Merge topic 'xcode-object-arch-dir'

8c346bbc Xcode: Compute a concrete object file arch dir if possible
5f4e26df Xcode: Refactor object directory name computation
5b29fd6d Xcode: Refactor internal architecture list construction
b1eb493c cmGlobalGenerator: Abort generation earlier on export() error

Acked-by: Kitware Robot <[email protected]>
Merge-request: !688
Brad King 8 年之前
父节点
当前提交
80ea73f288
共有 3 个文件被更改,包括 61 次插入31 次删除
  1. 5 4
      Source/cmGlobalGenerator.cxx
  2. 51 27
      Source/cmGlobalXCodeGenerator.cxx
  3. 5 0
      Source/cmGlobalXCodeGenerator.h

+ 5 - 4
Source/cmGlobalGenerator.cxx

@@ -1347,10 +1347,11 @@ void cmGlobalGenerator::Generate()
   for (std::map<std::string, cmExportBuildFileGenerator*>::iterator it =
   for (std::map<std::string, cmExportBuildFileGenerator*>::iterator it =
          this->BuildExportSets.begin();
          this->BuildExportSets.begin();
        it != this->BuildExportSets.end(); ++it) {
        it != this->BuildExportSets.end(); ++it) {
-    if (!it->second->GenerateImportFile() &&
-        !cmSystemTools::GetErrorOccuredFlag()) {
-      this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR,
-                                             "Could not write export file.");
+    if (!it->second->GenerateImportFile()) {
+      if (!cmSystemTools::GetErrorOccuredFlag()) {
+        this->GetCMakeInstance()->IssueMessage(cmake::FATAL_ERROR,
+                                               "Could not write export file.");
+      }
       return;
       return;
     }
     }
   }
   }

+ 51 - 27
Source/cmGlobalXCodeGenerator.cxx

@@ -152,6 +152,9 @@ cmGlobalXCodeGenerator::cmGlobalXCodeGenerator(cmake* cm,
   this->CurrentLocalGenerator = 0;
   this->CurrentLocalGenerator = 0;
   this->XcodeBuildCommandInitialized = false;
   this->XcodeBuildCommandInitialized = false;
 
 
+  this->ObjectDirArchDefault = "$(CURRENT_ARCH)";
+  this->ComputeObjectDirArch();
+
   cm->GetState()->SetIsGeneratorMultiConfig(true);
   cm->GetState()->SetIsGeneratorMultiConfig(true);
 }
 }
 
 
@@ -282,13 +285,7 @@ void cmGlobalXCodeGenerator::EnableLanguage(
   }
   }
   mf->AddDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV", "1");
   mf->AddDefinition("CMAKE_GENERATOR_NO_COMPILER_ENV", "1");
   this->cmGlobalGenerator::EnableLanguage(lang, mf, optional);
   this->cmGlobalGenerator::EnableLanguage(lang, mf, optional);
-  const char* osxArch = mf->GetDefinition("CMAKE_OSX_ARCHITECTURES");
-  const char* sysroot = mf->GetDefinition("CMAKE_OSX_SYSROOT");
-  if (osxArch && sysroot) {
-    this->Architectures.clear();
-    cmSystemTools::ExpandListArgument(std::string(osxArch),
-                                      this->Architectures);
-  }
+  this->ComputeArchitectures(mf);
 }
 }
 
 
 void cmGlobalXCodeGenerator::GenerateBuildCommand(
 void cmGlobalXCodeGenerator::GenerateBuildCommand(
@@ -3089,23 +3086,16 @@ bool cmGlobalXCodeGenerator::CreateXCodeObjects(
                            this->CreateString(defaultConfigName));
                            this->CreateString(defaultConfigName));
   cmXCodeObject* buildSettings =
   cmXCodeObject* buildSettings =
     this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
     this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP);
-  const char* osxArch =
-    this->CurrentMakefile->GetDefinition("CMAKE_OSX_ARCHITECTURES");
   const char* sysroot =
   const char* sysroot =
     this->CurrentMakefile->GetDefinition("CMAKE_OSX_SYSROOT");
     this->CurrentMakefile->GetDefinition("CMAKE_OSX_SYSROOT");
   const char* deploymentTarget =
   const char* deploymentTarget =
     this->CurrentMakefile->GetDefinition("CMAKE_OSX_DEPLOYMENT_TARGET");
     this->CurrentMakefile->GetDefinition("CMAKE_OSX_DEPLOYMENT_TARGET");
-  std::string archs;
   if (sysroot) {
   if (sysroot) {
-    if (osxArch) {
-      // recompute this as it may have been changed since enable language
-      this->Architectures.clear();
-      cmSystemTools::ExpandListArgument(std::string(osxArch),
-                                        this->Architectures);
-      archs = cmJoin(this->Architectures, " ");
-    }
     buildSettings->AddAttribute("SDKROOT", this->CreateString(sysroot));
     buildSettings->AddAttribute("SDKROOT", this->CreateString(sysroot));
   }
   }
+  // recompute this as it may have been changed since enable language
+  this->ComputeArchitectures(this->CurrentMakefile);
+  std::string const archs = cmJoin(this->Architectures, " ");
   if (archs.empty()) {
   if (archs.empty()) {
     // Tell Xcode to use NATIVE_ARCH instead of ARCHS.
     // Tell Xcode to use NATIVE_ARCH instead of ARCHS.
     buildSettings->AddAttribute("ONLY_ACTIVE_ARCH", this->CreateString("YES"));
     buildSettings->AddAttribute("ONLY_ACTIVE_ARCH", this->CreateString("YES"));
@@ -3212,6 +3202,48 @@ std::string cmGlobalXCodeGenerator::GetObjectsNormalDirectory(
   return dir;
   return dir;
 }
 }
 
 
+void cmGlobalXCodeGenerator::ComputeArchitectures(cmMakefile* mf)
+{
+  this->Architectures.clear();
+  const char* osxArch = mf->GetDefinition("CMAKE_OSX_ARCHITECTURES");
+  const char* sysroot = mf->GetDefinition("CMAKE_OSX_SYSROOT");
+  if (osxArch && sysroot) {
+    cmSystemTools::ExpandListArgument(std::string(osxArch),
+                                      this->Architectures);
+  }
+
+  if (this->Architectures.empty()) {
+    // With no ARCHS we use ONLY_ACTIVE_ARCH.
+    // Look up the arch that Xcode chooses in this case.
+    if (const char* arch = mf->GetDefinition("CMAKE_XCODE_CURRENT_ARCH")) {
+      this->ObjectDirArchDefault = arch;
+    }
+  }
+
+  this->ComputeObjectDirArch();
+}
+
+void cmGlobalXCodeGenerator::ComputeObjectDirArch()
+{
+  if (this->XcodeVersion >= 21) {
+    if (this->Architectures.size() > 1) {
+      this->ObjectDirArch = "$(CURRENT_ARCH)";
+    } else if (!this->Architectures.empty()) {
+      this->ObjectDirArch = this->Architectures[0];
+    } else {
+      this->ObjectDirArch = this->ObjectDirArchDefault;
+    }
+  } else {
+#if defined(__ppc__)
+    this->ObjectDirArch = "ppc";
+#elif defined(__i386)
+    this->ObjectDirArch = "i386";
+#else
+    this->ObjectDirArch = "";
+#endif
+  }
+}
+
 void cmGlobalXCodeGenerator::CreateXCodeDependHackTarget(
 void cmGlobalXCodeGenerator::CreateXCodeDependHackTarget(
   std::vector<cmXCodeObject*>& targets)
   std::vector<cmXCodeObject*>& targets)
 {
 {
@@ -3721,15 +3753,7 @@ void cmGlobalXCodeGenerator::ComputeTargetObjectDirectory(
   std::string configName = this->GetCMakeCFGIntDir();
   std::string configName = this->GetCMakeCFGIntDir();
   std::string dir =
   std::string dir =
     this->GetObjectsNormalDirectory("$(PROJECT_NAME)", configName, gt);
     this->GetObjectsNormalDirectory("$(PROJECT_NAME)", configName, gt);
-  if (this->XcodeVersion >= 21) {
-    dir += "$(CURRENT_ARCH)/";
-  } else {
-#ifdef __ppc__
-    dir += "ppc/";
-#endif
-#ifdef __i386
-    dir += "i386/";
-#endif
-  }
+  dir += this->ObjectDirArch;
+  dir += "/";
   gt->ObjectDirectory = dir;
   gt->ObjectDirectory = dir;
 }
 }

+ 5 - 0
Source/cmGlobalXCodeGenerator.h

@@ -240,6 +240,9 @@ private:
                                         const std::string& configName,
                                         const std::string& configName,
                                         const cmGeneratorTarget* t) const;
                                         const cmGeneratorTarget* t) const;
 
 
+  void ComputeArchitectures(cmMakefile* mf);
+  void ComputeObjectDirArch();
+
   void addObject(cmXCodeObject* obj);
   void addObject(cmXCodeObject* obj);
   std::string PostBuildMakeTarget(std::string const& tName,
   std::string PostBuildMakeTarget(std::string const& tName,
                                   std::string const& configName);
                                   std::string const& configName);
@@ -261,6 +264,8 @@ private:
   std::map<std::string, cmXCodeObject*> FileRefs;
   std::map<std::string, cmXCodeObject*> FileRefs;
   std::map<cmGeneratorTarget const*, cmXCodeObject*> XCodeObjectMap;
   std::map<cmGeneratorTarget const*, cmXCodeObject*> XCodeObjectMap;
   std::vector<std::string> Architectures;
   std::vector<std::string> Architectures;
+  std::string ObjectDirArchDefault;
+  std::string ObjectDirArch;
   std::string GeneratorToolset;
   std::string GeneratorToolset;
 };
 };