Merge topic 'ninja-multi-cross-configs'

b7a2baf38c Ninja Multi-Config: Add variable to control configs used in cross-config build

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !4269
diff --git a/Help/generator/Ninja Multi-Config.rst b/Help/generator/Ninja Multi-Config.rst
index 41cd5c2..e7f362e 100644
--- a/Help/generator/Ninja Multi-Config.rst
+++ b/Help/generator/Ninja Multi-Config.rst
@@ -31,6 +31,12 @@
 Ninja for the same file to be output with different commands in the same build
 graph.
 
+You can additionally use :variable:`CMAKE_NINJA_MULTI_CROSS_CONFIGS` to limit
+the configurations that get cross-generated. If this variable is set, each
+``build-<Config>.ninja`` file will only contain rules for the configurations
+listed in the variable, plus their own configuration. This also affects which
+configurations are built by the ``<target>:all`` target.
+
 If :variable:`CMAKE_NINJA_MULTI_CROSS_CONFIG_ENABLE` is not enabled, you can
 still build any target in ``build-<Config>.ninja`` by specifying
 ``<target>:<Config>`` or ``<target>``, but not ``<target>:<OtherConfig>`` or
diff --git a/Help/manual/cmake-variables.7.rst b/Help/manual/cmake-variables.7.rst
index bac8415..1f5b39c 100644
--- a/Help/manual/cmake-variables.7.rst
+++ b/Help/manual/cmake-variables.7.rst
@@ -425,6 +425,7 @@
    /variable/CMAKE_MODULE_LINKER_FLAGS_INIT
    /variable/CMAKE_MSVCIDE_RUN_PATH
    /variable/CMAKE_MSVC_RUNTIME_LIBRARY
+   /variable/CMAKE_NINJA_MULTI_CROSS_CONFIGS
    /variable/CMAKE_NINJA_MULTI_CROSS_CONFIG_ENABLE
    /variable/CMAKE_NINJA_MULTI_DEFAULT_BUILD_ALIAS
    /variable/CMAKE_NINJA_MULTI_DEFAULT_BUILD_TYPE
diff --git a/Help/variable/CMAKE_NINJA_MULTI_CROSS_CONFIGS.rst b/Help/variable/CMAKE_NINJA_MULTI_CROSS_CONFIGS.rst
new file mode 100644
index 0000000..48f6985
--- /dev/null
+++ b/Help/variable/CMAKE_NINJA_MULTI_CROSS_CONFIGS.rst
@@ -0,0 +1,7 @@
+CMAKE_NINJA_MULTI_CROSS_CONFIGS
+-------------------------------
+
+Set which configurations get cross-built if
+:variable:`CMAKE_NINJA_MULTI_CROSS_CONFIG_ENABLE` is set. See the
+documentation for the :generator:`Ninja Multi-Config` generator for more
+information.
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx
index 308644e..2dd89e3 100644
--- a/Source/cmGlobalNinjaGenerator.cxx
+++ b/Source/cmGlobalNinjaGenerator.cxx
@@ -1200,8 +1200,7 @@
     build.Outputs.front() = ta.first;
     build.ExplicitDeps.clear();
     if (ta.second.Config == "all") {
-      for (auto const& config :
-           ta.second.GeneratorTarget->Makefile->GetGeneratorConfigs()) {
+      for (auto const& config : this->GetCrossConfigs("")) {
         this->AppendTargetOutputs(ta.second.GeneratorTarget,
                                   build.ExplicitDeps, config);
       }
@@ -1209,7 +1208,9 @@
       this->AppendTargetOutputs(ta.second.GeneratorTarget, build.ExplicitDeps,
                                 ta.second.Config);
     }
-    this->WriteBuild(this->EnableCrossConfigBuild()
+    this->WriteBuild(this->EnableCrossConfigBuild() &&
+                         (ta.second.Config == "all" ||
+                          this->GetCrossConfigs("").count(ta.second.Config))
                        ? os
                        : *this->GetImplFileStream(ta.second.Config),
                      build);
@@ -1310,9 +1311,11 @@
         }
       }
       // Write target
-      this->WriteBuild(
-        this->EnableCrossConfigBuild() ? os : *this->GetImplFileStream(config),
-        build);
+      this->WriteBuild(this->EnableCrossConfigBuild() &&
+                           this->GetCrossConfigs("").count(config)
+                         ? os
+                         : *this->GetImplFileStream(config),
+                       build);
     }
 
     // Add shortcut target
@@ -1339,7 +1342,7 @@
     // Add target for all configs
     if (this->EnableCrossConfigBuild()) {
       build.ExplicitDeps.clear();
-      for (auto const& config : configs) {
+      for (auto const& config : this->GetCrossConfigs("")) {
         build.ExplicitDeps.push_back(this->BuildAlias(
           this->ConvertToNinjaPath(currentBinaryDir + "/all"), config));
       }
@@ -1794,11 +1797,19 @@
       build.ExplicitDeps.clear();
 
       if (additionalFiles) {
-        build.ExplicitDeps.push_back(
-          this->NinjaOutputPath(this->GetAdditionalCleanTargetName()));
+        for (auto const& config : this->GetCrossConfigs("")) {
+          build.ExplicitDeps.push_back(this->BuildAlias(
+            this->NinjaOutputPath(this->GetAdditionalCleanTargetName()),
+            config));
+        }
       }
 
-      build.Variables["TARGETS"] = "";
+      std::vector<std::string> byproducts;
+      for (auto const& config : this->GetCrossConfigs("")) {
+        byproducts.push_back(
+          this->BuildAlias(GetByproductsForCleanTargetName(), config));
+      }
+      build.Variables["TARGETS"] = cmJoin(byproducts, " ");
 
       for (auto const& fileConfig : configs) {
         build.Variables["FILE_ARG"] = cmStrCat(
@@ -2368,6 +2379,15 @@
   }
 }
 
+std::set<std::string> cmGlobalNinjaGenerator::GetCrossConfigs(
+  const std::string& /*fileConfig*/) const
+{
+  std::set<std::string> result;
+  result.insert(
+    this->Makefiles.front()->GetSafeDefinition("CMAKE_BUILD_TYPE"));
+  return result;
+}
+
 const char* cmGlobalNinjaMultiGenerator::NINJA_COMMON_FILE =
   "CMakeFiles/common.ninja";
 const char* cmGlobalNinjaMultiGenerator::NINJA_FILE_EXTENSION = ".ninja";
@@ -2534,3 +2554,25 @@
 
   return this->GetDefaultBuildType();
 }
+
+std::set<std::string> cmGlobalNinjaMultiGenerator::GetCrossConfigs(
+  const std::string& fileConfig) const
+{
+  std::vector<std::string> configs;
+  if (this->EnableCrossConfigBuild()) {
+    auto configsValue = this->Makefiles.front()->GetSafeDefinition(
+      "CMAKE_NINJA_MULTI_CROSS_CONFIGS");
+    if (!configsValue.empty()) {
+      cmExpandList(configsValue, configs);
+    } else {
+      configs = this->Makefiles.front()->GetGeneratorConfigs();
+    }
+  }
+
+  std::set<std::string> result(configs.cbegin(), configs.cend());
+  if (!fileConfig.empty()) {
+    result.insert(fileConfig);
+  }
+
+  return result;
+}
diff --git a/Source/cmGlobalNinjaGenerator.h b/Source/cmGlobalNinjaGenerator.h
index b61999f..d00a061 100644
--- a/Source/cmGlobalNinjaGenerator.h
+++ b/Source/cmGlobalNinjaGenerator.h
@@ -412,6 +412,9 @@
 
   virtual const char* GetDefaultBuildAlias() const { return nullptr; }
 
+  virtual std::set<std::string> GetCrossConfigs(
+    const std::string& fileConfig) const;
+
 protected:
   void Generate() override;
 
@@ -623,6 +626,9 @@
 
   const char* GetDefaultBuildAlias() const override;
 
+  std::set<std::string> GetCrossConfigs(
+    const std::string& fileConfig) const override;
+
 protected:
   bool OpenBuildFileStreams() override;
   void CloseBuildFileStreams() override;
diff --git a/Source/cmNinjaNormalTargetGenerator.cxx b/Source/cmNinjaNormalTargetGenerator.cxx
index a871a92..437548a 100644
--- a/Source/cmNinjaNormalTargetGenerator.cxx
+++ b/Source/cmNinjaNormalTargetGenerator.cxx
@@ -72,8 +72,9 @@
   // Write the build statements
   bool firstForConfig = true;
   for (auto const& fileConfig : this->GetConfigNames()) {
-    if (fileConfig != config &&
-        !this->GetGlobalGenerator()->EnableCrossConfigBuild()) {
+    if (!this->GetGlobalGenerator()
+           ->GetCrossConfigs(fileConfig)
+           .count(config)) {
       continue;
     }
     this->WriteObjectBuildStatements(config, fileConfig, firstForConfig);
@@ -85,8 +86,9 @@
   } else {
     firstForConfig = true;
     for (auto const& fileConfig : this->GetConfigNames()) {
-      if (fileConfig != config &&
-          !this->GetGlobalGenerator()->EnableCrossConfigBuild()) {
+      if (!this->GetGlobalGenerator()
+             ->GetCrossConfigs(fileConfig)
+             .count(config)) {
         continue;
       }
       // If this target has cuda language link inputs, and we need to do
diff --git a/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake b/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake
index 7d32b27..9fd64b0 100644
--- a/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake
+++ b/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake
@@ -128,6 +128,20 @@
 run_ninja(SimpleNoCross all-all build-Debug.ninja all:all)
 run_cmake_build(SimpleNoCross all-clean Debug clean:all)
 
+set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/SimpleCrossConfigs-build)
+set(RunCMake_TEST_OPTIONS "-DCMAKE_NINJA_MULTI_CROSS_CONFIG_ENABLE=ON;-DCMAKE_NINJA_MULTI_CROSS_CONFIGS=Debug\\;Release")
+run_cmake_configure(SimpleCrossConfigs)
+include(${RunCMake_TEST_BINARY_DIR}/target_files.cmake)
+run_ninja(SimpleCrossConfigs release-in-release-graph build-Release.ninja simpleexe)
+run_cmake_build(SimpleCrossConfigs debug-in-release-graph Release simpleexe:Debug)
+run_cmake_build(SimpleCrossConfigs relwithdebinfo-in-release-graph Release simpleexe:RelWithDebInfo)
+run_ninja(SimpleCrossConfigs relwithdebinfo-in-relwithdebinfo-graph build-RelWithDebInfo.ninja simpleexe:RelWithDebInfo)
+run_ninja(SimpleCrossConfigs release-in-relwithdebinfo-graph build-RelWithDebInfo.ninja simplestatic:Release)
+run_cmake_build(SimpleCrossConfigs all-in-relwithdebinfo-graph RelWithDebInfo simplestatic:all)
+run_ninja(SimpleCrossConfigs clean-all-in-release-graph build-Release.ninja clean:all)
+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}/CustomCommandGenerator-build)
 set(RunCMake_TEST_OPTIONS "-DCMAKE_NINJA_MULTI_CROSS_CONFIG_ENABLE=ON")
 run_cmake_configure(CustomCommandGenerator)
diff --git a/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-all-all-in-release-graph-build-check.cmake b/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-all-all-in-release-graph-build-check.cmake
new file mode 100644
index 0000000..fee5951
--- /dev/null
+++ b/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-all-all-in-release-graph-build-check.cmake
@@ -0,0 +1,45 @@
+check_files("${RunCMake_TEST_BINARY_DIR}"
+  INCLUDE
+    ${GENERATED_FILES}
+
+    ${TARGET_FILE_simpleexe_Debug}
+    ${TARGET_OBJECT_FILES_simpleexe_Debug}
+
+    ${TARGET_FILE_simpleshared_Debug}
+    ${TARGET_LINKER_FILE_simpleshared_Debug}
+    ${TARGET_OBJECT_FILES_simpleshared_Debug}
+
+    ${TARGET_FILE_simplestatic_Debug}
+    ${TARGET_OBJECT_FILES_simplestatic_Debug}
+
+    ${TARGET_OBJECT_FILES_simpleobj_Debug}
+
+    ${TARGET_FILE_simpleexe_Release}
+    ${TARGET_OBJECT_FILES_simpleexe_Release}
+
+    ${TARGET_FILE_simpleshared_Release}
+    ${TARGET_LINKER_FILE_simpleshared_Release}
+    ${TARGET_OBJECT_FILES_simpleshared_Release}
+
+    ${TARGET_FILE_simplestatic_Release}
+    ${TARGET_OBJECT_FILES_simplestatic_Release}
+
+    ${TARGET_OBJECT_FILES_simpleobj_Release}
+
+    ${TARGET_FILE_simpleexe_RelWithDebInfo}
+    ${TARGET_OBJECT_FILES_simpleexe_RelWithDebInfo}
+
+    ${TARGET_FILE_simpleshared_RelWithDebInfo}
+    ${TARGET_LINKER_FILE_simpleshared_RelWithDebInfo}
+    ${TARGET_OBJECT_FILES_simpleshared_RelWithDebInfo}
+
+    ${TARGET_OBJECT_FILES_simpleobj_RelWithDebInfo}
+
+  EXCLUDE
+    ${TARGET_OBJECT_FILES_simpleexe_MinSizeRel}
+    ${TARGET_OBJECT_FILES_simpleshared_MinSizeRel}
+    ${TARGET_OBJECT_FILES_simplestatic_MinSizeRel}
+    ${TARGET_OBJECT_FILES_simpleobj_MinSizeRel}
+
+    ${TARGET_OBJECT_FILES_simplestatic_RelWithDebInfo}
+  )
diff --git a/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-all-in-relwithdebinfo-graph-build-check.cmake b/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-all-in-relwithdebinfo-graph-build-check.cmake
new file mode 100644
index 0000000..fee5951
--- /dev/null
+++ b/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-all-in-relwithdebinfo-graph-build-check.cmake
@@ -0,0 +1,45 @@
+check_files("${RunCMake_TEST_BINARY_DIR}"
+  INCLUDE
+    ${GENERATED_FILES}
+
+    ${TARGET_FILE_simpleexe_Debug}
+    ${TARGET_OBJECT_FILES_simpleexe_Debug}
+
+    ${TARGET_FILE_simpleshared_Debug}
+    ${TARGET_LINKER_FILE_simpleshared_Debug}
+    ${TARGET_OBJECT_FILES_simpleshared_Debug}
+
+    ${TARGET_FILE_simplestatic_Debug}
+    ${TARGET_OBJECT_FILES_simplestatic_Debug}
+
+    ${TARGET_OBJECT_FILES_simpleobj_Debug}
+
+    ${TARGET_FILE_simpleexe_Release}
+    ${TARGET_OBJECT_FILES_simpleexe_Release}
+
+    ${TARGET_FILE_simpleshared_Release}
+    ${TARGET_LINKER_FILE_simpleshared_Release}
+    ${TARGET_OBJECT_FILES_simpleshared_Release}
+
+    ${TARGET_FILE_simplestatic_Release}
+    ${TARGET_OBJECT_FILES_simplestatic_Release}
+
+    ${TARGET_OBJECT_FILES_simpleobj_Release}
+
+    ${TARGET_FILE_simpleexe_RelWithDebInfo}
+    ${TARGET_OBJECT_FILES_simpleexe_RelWithDebInfo}
+
+    ${TARGET_FILE_simpleshared_RelWithDebInfo}
+    ${TARGET_LINKER_FILE_simpleshared_RelWithDebInfo}
+    ${TARGET_OBJECT_FILES_simpleshared_RelWithDebInfo}
+
+    ${TARGET_OBJECT_FILES_simpleobj_RelWithDebInfo}
+
+  EXCLUDE
+    ${TARGET_OBJECT_FILES_simpleexe_MinSizeRel}
+    ${TARGET_OBJECT_FILES_simpleshared_MinSizeRel}
+    ${TARGET_OBJECT_FILES_simplestatic_MinSizeRel}
+    ${TARGET_OBJECT_FILES_simpleobj_MinSizeRel}
+
+    ${TARGET_OBJECT_FILES_simplestatic_RelWithDebInfo}
+  )
diff --git a/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-all-relwithdebinfo-in-release-graph-build-check.cmake b/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-all-relwithdebinfo-in-release-graph-build-check.cmake
new file mode 100644
index 0000000..fee5951
--- /dev/null
+++ b/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-all-relwithdebinfo-in-release-graph-build-check.cmake
@@ -0,0 +1,45 @@
+check_files("${RunCMake_TEST_BINARY_DIR}"
+  INCLUDE
+    ${GENERATED_FILES}
+
+    ${TARGET_FILE_simpleexe_Debug}
+    ${TARGET_OBJECT_FILES_simpleexe_Debug}
+
+    ${TARGET_FILE_simpleshared_Debug}
+    ${TARGET_LINKER_FILE_simpleshared_Debug}
+    ${TARGET_OBJECT_FILES_simpleshared_Debug}
+
+    ${TARGET_FILE_simplestatic_Debug}
+    ${TARGET_OBJECT_FILES_simplestatic_Debug}
+
+    ${TARGET_OBJECT_FILES_simpleobj_Debug}
+
+    ${TARGET_FILE_simpleexe_Release}
+    ${TARGET_OBJECT_FILES_simpleexe_Release}
+
+    ${TARGET_FILE_simpleshared_Release}
+    ${TARGET_LINKER_FILE_simpleshared_Release}
+    ${TARGET_OBJECT_FILES_simpleshared_Release}
+
+    ${TARGET_FILE_simplestatic_Release}
+    ${TARGET_OBJECT_FILES_simplestatic_Release}
+
+    ${TARGET_OBJECT_FILES_simpleobj_Release}
+
+    ${TARGET_FILE_simpleexe_RelWithDebInfo}
+    ${TARGET_OBJECT_FILES_simpleexe_RelWithDebInfo}
+
+    ${TARGET_FILE_simpleshared_RelWithDebInfo}
+    ${TARGET_LINKER_FILE_simpleshared_RelWithDebInfo}
+    ${TARGET_OBJECT_FILES_simpleshared_RelWithDebInfo}
+
+    ${TARGET_OBJECT_FILES_simpleobj_RelWithDebInfo}
+
+  EXCLUDE
+    ${TARGET_OBJECT_FILES_simpleexe_MinSizeRel}
+    ${TARGET_OBJECT_FILES_simpleshared_MinSizeRel}
+    ${TARGET_OBJECT_FILES_simplestatic_MinSizeRel}
+    ${TARGET_OBJECT_FILES_simpleobj_MinSizeRel}
+
+    ${TARGET_OBJECT_FILES_simplestatic_RelWithDebInfo}
+  )
diff --git a/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-all-relwithdebinfo-in-release-graph-build-result.txt b/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-all-relwithdebinfo-in-release-graph-build-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-all-relwithdebinfo-in-release-graph-build-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-all-relwithdebinfo-in-release-graph-build-stderr.txt b/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-all-relwithdebinfo-in-release-graph-build-stderr.txt
new file mode 100644
index 0000000..fa8b462
--- /dev/null
+++ b/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-all-relwithdebinfo-in-release-graph-build-stderr.txt
@@ -0,0 +1 @@
+^ninja: error: unknown target 'all:RelWithDebInfo'$
diff --git a/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-clean-all-in-release-graph-ninja-check.cmake b/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-clean-all-in-release-graph-ninja-check.cmake
new file mode 100644
index 0000000..6c94369
--- /dev/null
+++ b/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-clean-all-in-release-graph-ninja-check.cmake
@@ -0,0 +1,31 @@
+check_files("${RunCMake_TEST_BINARY_DIR}"
+  INCLUDE
+    ${GENERATED_FILES}
+
+    ${TARGET_FILE_simpleexe_RelWithDebInfo}
+    ${TARGET_OBJECT_FILES_simpleexe_RelWithDebInfo}
+
+    ${TARGET_FILE_simpleshared_RelWithDebInfo}
+    ${TARGET_LINKER_FILE_simpleshared_RelWithDebInfo}
+    ${TARGET_OBJECT_FILES_simpleshared_RelWithDebInfo}
+
+    ${TARGET_OBJECT_FILES_simpleobj_RelWithDebInfo}
+
+  EXCLUDE
+    ${TARGET_OBJECT_FILES_simpleexe_Debug}
+    ${TARGET_OBJECT_FILES_simpleshared_Debug}
+    ${TARGET_OBJECT_FILES_simplestatic_Debug}
+    ${TARGET_OBJECT_FILES_simpleobj_Debug}
+
+    ${TARGET_OBJECT_FILES_simpleexe_Release}
+    ${TARGET_OBJECT_FILES_simpleshared_Release}
+    ${TARGET_OBJECT_FILES_simplestatic_Release}
+    ${TARGET_OBJECT_FILES_simpleobj_Release}
+
+    ${TARGET_OBJECT_FILES_simpleexe_MinSizeRel}
+    ${TARGET_OBJECT_FILES_simpleshared_MinSizeRel}
+    ${TARGET_OBJECT_FILES_simplestatic_MinSizeRel}
+    ${TARGET_OBJECT_FILES_simpleobj_MinSizeRel}
+
+    ${TARGET_OBJECT_FILES_simplestatic_RelWithDebInfo}
+  )
diff --git a/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-debug-in-release-graph-build-check.cmake b/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-debug-in-release-graph-build-check.cmake
new file mode 100644
index 0000000..b6c77ab
--- /dev/null
+++ b/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-debug-in-release-graph-build-check.cmake
@@ -0,0 +1,37 @@
+check_files("${RunCMake_TEST_BINARY_DIR}"
+  INCLUDE
+    ${GENERATED_FILES}
+
+    ${TARGET_FILE_simpleexe_Debug}
+    ${TARGET_OBJECT_FILES_simpleexe_Debug}
+
+    ${TARGET_FILE_simpleshared_Debug}
+    ${TARGET_LINKER_FILE_simpleshared_Debug}
+    ${TARGET_OBJECT_FILES_simpleshared_Debug}
+
+    ${TARGET_OBJECT_FILES_simpleobj_Debug}
+
+    ${TARGET_FILE_simpleexe_Release}
+    ${TARGET_OBJECT_FILES_simpleexe_Release}
+
+    ${TARGET_FILE_simpleshared_Release}
+    ${TARGET_LINKER_FILE_simpleshared_Release}
+    ${TARGET_OBJECT_FILES_simpleshared_Release}
+
+    ${TARGET_OBJECT_FILES_simpleobj_Release}
+
+  EXCLUDE
+    ${TARGET_OBJECT_FILES_simplestatic_Debug}
+
+    ${TARGET_OBJECT_FILES_simplestatic_Release}
+
+    ${TARGET_OBJECT_FILES_simpleexe_MinSizeRel}
+    ${TARGET_OBJECT_FILES_simpleshared_MinSizeRel}
+    ${TARGET_OBJECT_FILES_simplestatic_MinSizeRel}
+    ${TARGET_OBJECT_FILES_simpleobj_MinSizeRel}
+
+    ${TARGET_OBJECT_FILES_simpleexe_RelWithDebInfo}
+    ${TARGET_OBJECT_FILES_simpleshared_RelWithDebInfo}
+    ${TARGET_OBJECT_FILES_simplestatic_RelWithDebInfo}
+    ${TARGET_OBJECT_FILES_simpleobj_RelWithDebInfo}
+  )
diff --git a/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-release-in-release-graph-ninja-check.cmake b/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-release-in-release-graph-ninja-check.cmake
new file mode 100644
index 0000000..d8b5218
--- /dev/null
+++ b/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-release-in-release-graph-ninja-check.cmake
@@ -0,0 +1,31 @@
+check_files("${RunCMake_TEST_BINARY_DIR}"
+  INCLUDE
+    ${GENERATED_FILES}
+
+    ${TARGET_FILE_simpleexe_Release}
+    ${TARGET_OBJECT_FILES_simpleexe_Release}
+
+    ${TARGET_FILE_simpleshared_Release}
+    ${TARGET_LINKER_FILE_simpleshared_Release}
+    ${TARGET_OBJECT_FILES_simpleshared_Release}
+
+    ${TARGET_OBJECT_FILES_simpleobj_Release}
+
+  EXCLUDE
+    ${TARGET_OBJECT_FILES_simpleexe_Debug}
+    ${TARGET_OBJECT_FILES_simpleshared_Debug}
+    ${TARGET_OBJECT_FILES_simplestatic_Debug}
+    ${TARGET_OBJECT_FILES_simpleobj_Debug}
+
+    ${TARGET_OBJECT_FILES_simplestatic_Release}
+
+    ${TARGET_OBJECT_FILES_simpleexe_MinSizeRel}
+    ${TARGET_OBJECT_FILES_simpleshared_MinSizeRel}
+    ${TARGET_OBJECT_FILES_simplestatic_MinSizeRel}
+    ${TARGET_OBJECT_FILES_simpleobj_MinSizeRel}
+
+    ${TARGET_OBJECT_FILES_simpleexe_RelWithDebInfo}
+    ${TARGET_OBJECT_FILES_simpleshared_RelWithDebInfo}
+    ${TARGET_OBJECT_FILES_simplestatic_RelWithDebInfo}
+    ${TARGET_OBJECT_FILES_simpleobj_RelWithDebInfo}
+  )
diff --git a/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-release-in-relwithdebinfo-graph-ninja-check.cmake b/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-release-in-relwithdebinfo-graph-ninja-check.cmake
new file mode 100644
index 0000000..1a37aa3
--- /dev/null
+++ b/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-release-in-relwithdebinfo-graph-ninja-check.cmake
@@ -0,0 +1,44 @@
+check_files("${RunCMake_TEST_BINARY_DIR}"
+  INCLUDE
+    ${GENERATED_FILES}
+
+    ${TARGET_FILE_simpleexe_Debug}
+    ${TARGET_OBJECT_FILES_simpleexe_Debug}
+
+    ${TARGET_FILE_simpleshared_Debug}
+    ${TARGET_LINKER_FILE_simpleshared_Debug}
+    ${TARGET_OBJECT_FILES_simpleshared_Debug}
+
+    ${TARGET_OBJECT_FILES_simpleobj_Debug}
+
+    ${TARGET_FILE_simpleexe_Release}
+    ${TARGET_OBJECT_FILES_simpleexe_Release}
+
+    ${TARGET_FILE_simpleshared_Release}
+    ${TARGET_LINKER_FILE_simpleshared_Release}
+    ${TARGET_OBJECT_FILES_simpleshared_Release}
+
+    ${TARGET_FILE_simplestatic_Release}
+    ${TARGET_OBJECT_FILES_simplestatic_Release}
+
+    ${TARGET_OBJECT_FILES_simpleobj_Release}
+
+    ${TARGET_FILE_simpleexe_RelWithDebInfo}
+    ${TARGET_OBJECT_FILES_simpleexe_RelWithDebInfo}
+
+    ${TARGET_FILE_simpleshared_RelWithDebInfo}
+    ${TARGET_LINKER_FILE_simpleshared_RelWithDebInfo}
+    ${TARGET_OBJECT_FILES_simpleshared_RelWithDebInfo}
+
+    ${TARGET_OBJECT_FILES_simpleobj_RelWithDebInfo}
+
+  EXCLUDE
+    ${TARGET_OBJECT_FILES_simplestatic_Debug}
+
+    ${TARGET_OBJECT_FILES_simpleexe_MinSizeRel}
+    ${TARGET_OBJECT_FILES_simpleshared_MinSizeRel}
+    ${TARGET_OBJECT_FILES_simplestatic_MinSizeRel}
+    ${TARGET_OBJECT_FILES_simpleobj_MinSizeRel}
+
+    ${TARGET_OBJECT_FILES_simplestatic_RelWithDebInfo}
+  )
diff --git a/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-relwithdebinfo-in-release-graph-build-check.cmake b/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-relwithdebinfo-in-release-graph-build-check.cmake
new file mode 100644
index 0000000..b6c77ab
--- /dev/null
+++ b/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-relwithdebinfo-in-release-graph-build-check.cmake
@@ -0,0 +1,37 @@
+check_files("${RunCMake_TEST_BINARY_DIR}"
+  INCLUDE
+    ${GENERATED_FILES}
+
+    ${TARGET_FILE_simpleexe_Debug}
+    ${TARGET_OBJECT_FILES_simpleexe_Debug}
+
+    ${TARGET_FILE_simpleshared_Debug}
+    ${TARGET_LINKER_FILE_simpleshared_Debug}
+    ${TARGET_OBJECT_FILES_simpleshared_Debug}
+
+    ${TARGET_OBJECT_FILES_simpleobj_Debug}
+
+    ${TARGET_FILE_simpleexe_Release}
+    ${TARGET_OBJECT_FILES_simpleexe_Release}
+
+    ${TARGET_FILE_simpleshared_Release}
+    ${TARGET_LINKER_FILE_simpleshared_Release}
+    ${TARGET_OBJECT_FILES_simpleshared_Release}
+
+    ${TARGET_OBJECT_FILES_simpleobj_Release}
+
+  EXCLUDE
+    ${TARGET_OBJECT_FILES_simplestatic_Debug}
+
+    ${TARGET_OBJECT_FILES_simplestatic_Release}
+
+    ${TARGET_OBJECT_FILES_simpleexe_MinSizeRel}
+    ${TARGET_OBJECT_FILES_simpleshared_MinSizeRel}
+    ${TARGET_OBJECT_FILES_simplestatic_MinSizeRel}
+    ${TARGET_OBJECT_FILES_simpleobj_MinSizeRel}
+
+    ${TARGET_OBJECT_FILES_simpleexe_RelWithDebInfo}
+    ${TARGET_OBJECT_FILES_simpleshared_RelWithDebInfo}
+    ${TARGET_OBJECT_FILES_simplestatic_RelWithDebInfo}
+    ${TARGET_OBJECT_FILES_simpleobj_RelWithDebInfo}
+  )
diff --git a/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-relwithdebinfo-in-release-graph-build-result.txt b/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-relwithdebinfo-in-release-graph-build-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-relwithdebinfo-in-release-graph-build-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-relwithdebinfo-in-release-graph-build-stderr.txt b/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-relwithdebinfo-in-release-graph-build-stderr.txt
new file mode 100644
index 0000000..f3a825c
--- /dev/null
+++ b/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-relwithdebinfo-in-release-graph-build-stderr.txt
@@ -0,0 +1 @@
+^ninja: error: unknown target 'simpleexe:RelWithDebInfo'$
diff --git a/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-relwithdebinfo-in-relwithdebinfo-graph-ninja-check.cmake b/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-relwithdebinfo-in-relwithdebinfo-graph-ninja-check.cmake
new file mode 100644
index 0000000..7eddb2f
--- /dev/null
+++ b/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs-relwithdebinfo-in-relwithdebinfo-graph-ninja-check.cmake
@@ -0,0 +1,43 @@
+check_files("${RunCMake_TEST_BINARY_DIR}"
+  INCLUDE
+    ${GENERATED_FILES}
+
+    ${TARGET_FILE_simpleexe_Debug}
+    ${TARGET_OBJECT_FILES_simpleexe_Debug}
+
+    ${TARGET_FILE_simpleshared_Debug}
+    ${TARGET_LINKER_FILE_simpleshared_Debug}
+    ${TARGET_OBJECT_FILES_simpleshared_Debug}
+
+    ${TARGET_OBJECT_FILES_simpleobj_Debug}
+
+    ${TARGET_FILE_simpleexe_Release}
+    ${TARGET_OBJECT_FILES_simpleexe_Release}
+
+    ${TARGET_FILE_simpleshared_Release}
+    ${TARGET_LINKER_FILE_simpleshared_Release}
+    ${TARGET_OBJECT_FILES_simpleshared_Release}
+
+    ${TARGET_OBJECT_FILES_simpleobj_Release}
+
+    ${TARGET_FILE_simpleexe_RelWithDebInfo}
+    ${TARGET_OBJECT_FILES_simpleexe_RelWithDebInfo}
+
+    ${TARGET_FILE_simpleshared_RelWithDebInfo}
+    ${TARGET_LINKER_FILE_simpleshared_RelWithDebInfo}
+    ${TARGET_OBJECT_FILES_simpleshared_RelWithDebInfo}
+
+    ${TARGET_OBJECT_FILES_simpleobj_RelWithDebInfo}
+
+  EXCLUDE
+    ${TARGET_OBJECT_FILES_simplestatic_Debug}
+
+    ${TARGET_OBJECT_FILES_simplestatic_Release}
+
+    ${TARGET_OBJECT_FILES_simpleexe_MinSizeRel}
+    ${TARGET_OBJECT_FILES_simpleshared_MinSizeRel}
+    ${TARGET_OBJECT_FILES_simplestatic_MinSizeRel}
+    ${TARGET_OBJECT_FILES_simpleobj_MinSizeRel}
+
+    ${TARGET_OBJECT_FILES_simplestatic_RelWithDebInfo}
+  )
diff --git a/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs.cmake b/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs.cmake
new file mode 100644
index 0000000..2a5b708
--- /dev/null
+++ b/Tests/RunCMake/NinjaMultiConfig/SimpleCrossConfigs.cmake
@@ -0,0 +1 @@
+include("${CMAKE_CURRENT_SOURCE_DIR}/Simple.cmake")