summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2023-03-03 14:18:27 (GMT)
committerKitware Robot <kwrobot@kitware.com>2023-03-03 14:18:34 (GMT)
commit87330a10e29c2c4b4dacd60009dc29f1630de6b7 (patch)
tree17c7651bd883ea5c8e3a6b6c0fc77f542795160d
parent10f318326fef873928311d5964a12db4f8a10d82 (diff)
parentdf38eaab2c806d15a3b2039bf96ad3e69569b5e8 (diff)
downloadCMake-87330a10e29c2c4b4dacd60009dc29f1630de6b7.zip
CMake-87330a10e29c2c4b4dacd60009dc29f1630de6b7.tar.gz
CMake-87330a10e29c2c4b4dacd60009dc29f1630de6b7.tar.bz2
Merge topic 'ninja-multi-output-path-prefix'
df38eaab2c Ninja Multi-Config: Write output path prefix Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !8280
-rw-r--r--Source/cmGlobalNinjaGenerator.cxx25
-rw-r--r--Tests/RunCMake/NinjaMultiConfig/OutputPathPrefix-all-ninja-stdout.txt1
-rw-r--r--Tests/RunCMake/NinjaMultiConfig/OutputPathPrefix.cmake1
-rw-r--r--Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake9
4 files changed, 26 insertions, 10 deletions
diff --git a/Source/cmGlobalNinjaGenerator.cxx b/Source/cmGlobalNinjaGenerator.cxx
index ba7d7a7..d29c086 100644
--- a/Source/cmGlobalNinjaGenerator.cxx
+++ b/Source/cmGlobalNinjaGenerator.cxx
@@ -571,6 +571,7 @@ void cmGlobalNinjaGenerator::Generate()
msg.str());
return;
}
+ this->InitOutputPathPrefix();
if (!this->OpenBuildFileStreams()) {
return;
}
@@ -582,7 +583,6 @@ void cmGlobalNinjaGenerator::Generate()
it.second.TargetDependsClosureLocalOutputs.clear();
}
- this->InitOutputPathPrefix();
this->TargetAll = this->NinjaOutputPath("all");
this->CMakeCacheFile = this->NinjaOutputPath("CMakeCache.txt");
this->DiagnosedCxxModuleNinjaSupport = false;
@@ -2079,9 +2079,10 @@ void cmGlobalNinjaGenerator::WriteTargetClean(std::ostream& os)
build.Outputs.front() = this->BuildAlias(
this->NinjaOutputPath(this->GetCleanTargetName()), config);
if (this->IsMultiConfig()) {
- build.Variables["TARGETS"] =
- cmStrCat(this->BuildAlias(GetByproductsForCleanTargetName(), config),
- " ", GetByproductsForCleanTargetName());
+ build.Variables["TARGETS"] = cmStrCat(
+ this->BuildAlias(
+ this->NinjaOutputPath(GetByproductsForCleanTargetName()), config),
+ " ", this->NinjaOutputPath(GetByproductsForCleanTargetName()));
}
build.ExplicitDeps.clear();
if (additionalFiles) {
@@ -2096,7 +2097,8 @@ void cmGlobalNinjaGenerator::WriteTargetClean(std::ostream& os)
if (this->IsMultiConfig()) {
build.Variables["FILE_ARG"] = cmStrCat(
"-f ",
- cmGlobalNinjaMultiGenerator::GetNinjaImplFilename(fileConfig));
+ this->NinjaOutputPath(
+ cmGlobalNinjaMultiGenerator::GetNinjaImplFilename(fileConfig)));
}
this->WriteBuild(*this->GetImplFileStream(fileConfig), build);
}
@@ -2118,8 +2120,8 @@ void cmGlobalNinjaGenerator::WriteTargetClean(std::ostream& os)
std::vector<std::string> byproducts;
byproducts.reserve(this->CrossConfigs.size());
for (auto const& config : this->CrossConfigs) {
- byproducts.push_back(
- this->BuildAlias(GetByproductsForCleanTargetName(), config));
+ byproducts.push_back(this->BuildAlias(
+ this->NinjaOutputPath(GetByproductsForCleanTargetName()), config));
}
byproducts.emplace_back(GetByproductsForCleanTargetName());
build.Variables["TARGETS"] = cmJoin(byproducts, " ");
@@ -2127,7 +2129,8 @@ void cmGlobalNinjaGenerator::WriteTargetClean(std::ostream& os)
for (auto const& fileConfig : configs) {
build.Variables["FILE_ARG"] = cmStrCat(
"-f ",
- cmGlobalNinjaMultiGenerator::GetNinjaImplFilename(fileConfig));
+ this->NinjaOutputPath(
+ cmGlobalNinjaMultiGenerator::GetNinjaImplFilename(fileConfig)));
this->WriteBuild(*this->GetImplFileStream(fileConfig), build);
}
}
@@ -2910,7 +2913,8 @@ bool cmGlobalNinjaMultiGenerator::OpenBuildFileStreams()
*this->DefaultFileStream << "# Build using rules for '"
<< this->DefaultFileConfig << "'.\n\n"
<< "include "
- << GetNinjaImplFilename(this->DefaultFileConfig)
+ << this->NinjaOutputPath(
+ GetNinjaImplFilename(this->DefaultFileConfig))
<< "\n\n";
// Write a comment about this file.
@@ -2943,7 +2947,8 @@ bool cmGlobalNinjaMultiGenerator::OpenBuildFileStreams()
*this->ConfigFileStreams[config]
<< "# This file contains aliases specific to the \"" << config
<< "\"\n# configuration.\n\n"
- << "include " << GetNinjaImplFilename(config) << "\n\n";
+ << "include " << this->NinjaOutputPath(GetNinjaImplFilename(config))
+ << "\n\n";
return true;
});
diff --git a/Tests/RunCMake/NinjaMultiConfig/OutputPathPrefix-all-ninja-stdout.txt b/Tests/RunCMake/NinjaMultiConfig/OutputPathPrefix-all-ninja-stdout.txt
new file mode 100644
index 0000000..f5bce43
--- /dev/null
+++ b/Tests/RunCMake/NinjaMultiConfig/OutputPathPrefix-all-ninja-stdout.txt
@@ -0,0 +1 @@
+tgt has been built
diff --git a/Tests/RunCMake/NinjaMultiConfig/OutputPathPrefix.cmake b/Tests/RunCMake/NinjaMultiConfig/OutputPathPrefix.cmake
new file mode 100644
index 0000000..c4e0587
--- /dev/null
+++ b/Tests/RunCMake/NinjaMultiConfig/OutputPathPrefix.cmake
@@ -0,0 +1 @@
+add_custom_target(tgt ALL COMMAND ${CMAKE_COMMAND} -E echo "tgt has been built")
diff --git a/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake b/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake
index c040e8f..47f5eee 100644
--- a/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake
+++ b/Tests/RunCMake/NinjaMultiConfig/RunCMakeTest.cmake
@@ -459,6 +459,15 @@ set(RunCMake_TEST_OPTIONS "-DCMAKE_CONFIGURATION_TYPES=Debug\\;Release;-DCMAKE_C
run_cmake(CompileCommands)
unset(RunCMake_TEST_OPTIONS)
+set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/OutputPathPrefix-build)
+run_cmake_with_options(OutputPathPrefix "-DCMAKE_NINJA_OUTPUT_PATH_PREFIX=OutputPathPrefix-build")
+set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR})
+set(RunCMake_TEST_NO_CLEAN 1)
+run_cmake_command(OutputPathPrefix-all-ninja "${RunCMake_MAKE_PROGRAM}" -f OutputPathPrefix-build/build.ninja OutputPathPrefix-build/all)
+run_cmake_command(OutputPathPrefix-clean-ninja "${RunCMake_MAKE_PROGRAM}" -f OutputPathPrefix-build/build.ninja OutputPathPrefix-build/clean)
+unset(RunCMake_TEST_NO_CLEAN)
+unset(RunCMake_TEST_BINARY_DIR)
+
# CudaSimple uses separable compilation, which is currently only supported on NVCC.
if(CMake_TEST_CUDA)
set(RunCMake_TEST_BINARY_DIR ${RunCMake_BINARY_DIR}/CudaSimple-build)