Browse Source

Merge topic 'fix-ninja-multi-framework-header'

63c9cd2088 Ninja Multi-Config: Fix bug with MacOS frameworks

Acked-by: Kitware Robot <[email protected]>
Merge-request: !4279
Brad King 5 years ago
parent
commit
f624b44524

+ 20 - 6
Source/cmNinjaTargetGenerator.cxx

@@ -58,12 +58,14 @@ std::unique_ptr<cmNinjaTargetGenerator> cmNinjaTargetGenerator::New(
 
 cmNinjaTargetGenerator::cmNinjaTargetGenerator(cmGeneratorTarget* target)
   : cmCommonTargetGenerator(target)
-  , MacOSXContentGenerator(nullptr)
   , OSXBundleGenerator(nullptr)
   , LocalGenerator(
       static_cast<cmLocalNinjaGenerator*>(target->GetLocalGenerator()))
 {
-  MacOSXContentGenerator = cm::make_unique<MacOSXContentGeneratorType>(this);
+  for (auto const& fileConfig : target->Makefile->GetGeneratorConfigs()) {
+    this->Configs[fileConfig].MacOSXContentGenerator =
+      cm::make_unique<MacOSXContentGeneratorType>(this, fileConfig);
+  }
 }
 
 cmNinjaTargetGenerator::~cmNinjaTargetGenerator() = default;
@@ -837,13 +839,15 @@ void cmNinjaTargetGenerator::WriteObjectBuildStatements(
     std::vector<cmSourceFile const*> headerSources;
     this->GeneratorTarget->GetHeaderSources(headerSources, config);
     this->OSXBundleGenerator->GenerateMacOSXContentStatements(
-      headerSources, this->MacOSXContentGenerator.get(), config);
+      headerSources, this->Configs[fileConfig].MacOSXContentGenerator.get(),
+      config);
   }
   {
     std::vector<cmSourceFile const*> extraSources;
     this->GeneratorTarget->GetExtraSources(extraSources, config);
     this->OSXBundleGenerator->GenerateMacOSXContentStatements(
-      extraSources, this->MacOSXContentGenerator.get(), config);
+      extraSources, this->Configs[fileConfig].MacOSXContentGenerator.get(),
+      config);
   }
   if (firstForConfig) {
     const char* pchExtension =
@@ -1452,6 +1456,16 @@ void cmNinjaTargetGenerator::MacOSXContentGeneratorType::operator()(
     this->Generator->OSXBundleGenerator->InitMacOSXContentDirectory(pkgloc,
                                                                     config);
 
+  // Reject files that collide with files from the Ninja file's native config.
+  if (config != this->FileConfig) {
+    std::string nativeMacdir =
+      this->Generator->OSXBundleGenerator->InitMacOSXContentDirectory(
+        pkgloc, this->FileConfig);
+    if (macdir == nativeMacdir) {
+      return;
+    }
+  }
+
   // Get the input file location.
   std::string input = source.GetFullPath();
   input = this->Generator->GetGlobalGenerator()->ConvertToNinjaPath(input);
@@ -1462,8 +1476,8 @@ void cmNinjaTargetGenerator::MacOSXContentGeneratorType::operator()(
   output = this->Generator->GetGlobalGenerator()->ConvertToNinjaPath(output);
 
   // Write a build statement to copy the content into the bundle.
-  this->Generator->GetGlobalGenerator()->WriteMacOSXContentBuild(input, output,
-                                                                 config);
+  this->Generator->GetGlobalGenerator()->WriteMacOSXContentBuild(
+    input, output, this->FileConfig);
 
   // Add as a dependency to the target so that it gets called.
   this->Generator->Configs[config].ExtraFiles.push_back(std::move(output));

+ 6 - 2
Source/cmNinjaTargetGenerator.h

@@ -9,6 +9,7 @@
 #include <memory>
 #include <set>
 #include <string>
+#include <utility>
 #include <vector>
 
 #include "cm_jsoncpp_value.h"
@@ -173,8 +174,10 @@ protected:
   struct MacOSXContentGeneratorType
     : cmOSXBundleGenerator::MacOSXContentGeneratorType
   {
-    MacOSXContentGeneratorType(cmNinjaTargetGenerator* g)
+    MacOSXContentGeneratorType(cmNinjaTargetGenerator* g,
+                               std::string fileConfig)
       : Generator(g)
+      , FileConfig(std::move(fileConfig))
     {
     }
 
@@ -183,10 +186,10 @@ protected:
 
   private:
     cmNinjaTargetGenerator* Generator;
+    std::string FileConfig;
   };
   friend struct MacOSXContentGeneratorType;
 
-  std::unique_ptr<MacOSXContentGeneratorType> MacOSXContentGenerator;
   // Properly initialized by sub-classes.
   std::unique_ptr<cmOSXBundleGenerator> OSXBundleGenerator;
   std::set<std::string> MacContentFolders;
@@ -209,6 +212,7 @@ private:
     Json::Value SwiftOutputMap;
     std::vector<cmCustomCommand const*> CustomCommands;
     cmNinjaDeps ExtraFiles;
+    std::unique_ptr<MacOSXContentGeneratorType> MacOSXContentGenerator;
   };
 
   std::map<std::string, ByConfig> Configs;

+ 22 - 0
Tests/RunCMake/NinjaMultiConfig/Framework.cmake

@@ -0,0 +1,22 @@
+enable_language(C)
+
+set(header "${CMAKE_CURRENT_BINARY_DIR}/header.h")
+file(GENERATE
+  OUTPUT "${header}"
+  CONTENT "/* foo */"
+  CONDITION "$<CONFIG:Release>"
+  )
+add_library(framework SHARED "${header}" empty.c)
+
+set_property(TARGET framework PROPERTY FRAMEWORK ON)
+set_property(TARGET framework APPEND PROPERTY PUBLIC_HEADER ${header})
+
+set_target_properties(framework PROPERTIES
+  LIBRARY_OUTPUT_DIRECTORY "lib"
+  LIBRARY_OUTPUT_DIRECTORY_DEBUG "lib"
+  LIBRARY_OUTPUT_DIRECTORY_RELEASE "lib"
+  DEBUG_POSTFIX "_debug"
+  )
+
+include(${CMAKE_CURRENT_LIST_DIR}/Common.cmake)
+generate_output_files(framework)

+ 7 - 0
Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake

@@ -142,6 +142,13 @@ run_ninja(SimpleCrossConfigs clean-all-in-release-graph build-Release.ninja clea
 run_cmake_build(SimpleCrossConfigs all-all-in-release-graph Release all:all)
 run_cmake_build(SimpleCrossConfigs all-relwithdebinfo-in-release-graph Release all:RelWithDebInfo)
 
+set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/Framework-build)
+set(RunCMake_TEST_OPTIONS "-DCMAKE_NINJA_MULTI_CROSS_CONFIG_ENABLE=ON")
+run_cmake_configure(Framework)
+unset(RunCMake_TEST_OPTIONS)
+include(${RunCMake_TEST_BINARY_DIR}/target_files.cmake)
+run_cmake_build(Framework framework Debug all)
+
 set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/CustomCommandGenerator-build)
 set(RunCMake_TEST_OPTIONS "-DCMAKE_NINJA_MULTI_CROSS_CONFIG_ENABLE=ON")
 run_cmake_configure(CustomCommandGenerator)