diff --git a/Modules/CTestUseLaunchers.cmake b/Modules/CTestUseLaunchers.cmake index dc015f805f..c26c840b61 100644 --- a/Modules/CTestUseLaunchers.cmake +++ b/Modules/CTestUseLaunchers.cmake @@ -60,7 +60,7 @@ endif() if(CTEST_USE_LAUNCHERS) set(__launch_common_options - "--target-name --current-build-dir ") + "--target-name --current-build-dir --build-dir --object-dir ") set(__launch_compile_options "${__launch_common_options} --output --source --language ") diff --git a/Source/CTest/cmCTestLaunch.cxx b/Source/CTest/cmCTestLaunch.cxx index a929b395df..286715f9d1 100644 --- a/Source/CTest/cmCTestLaunch.cxx +++ b/Source/CTest/cmCTestLaunch.cxx @@ -14,6 +14,7 @@ #include "cmsys/FStream.hxx" #include "cmsys/RegularExpression.hxx" +#include "cmCMakePath.h" #include "cmCTestLaunchReporter.h" #include "cmGlobalGenerator.h" #include "cmInstrumentation.h" @@ -71,7 +72,8 @@ bool cmCTestLaunch::ParseArguments(int argc, char const* const* argv) DoingCurrentBuildDir, DoingCount, DoingFilterPrefix, - DoingConfig + DoingConfig, + DoingObjectDir }; Doing doing = DoingNone; int arg0 = 0; @@ -103,6 +105,8 @@ bool cmCTestLaunch::ParseArguments(int argc, char const* const* argv) doing = DoingFilterPrefix; } else if (strcmp(arg, "--config") == 0) { doing = DoingConfig; + } else if (strcmp(arg, "--object-dir") == 0) { + doing = DoingObjectDir; } else if (doing == DoingOutput) { this->Reporter.OptionOutput = arg; doing = DoingNone; @@ -142,9 +146,28 @@ bool cmCTestLaunch::ParseArguments(int argc, char const* const* argv) } else if (doing == DoingConfig) { this->Reporter.OptionConfig = arg; doing = DoingNone; + } else if (doing == DoingObjectDir) { + this->Reporter.OptionObjectDir = arg; + doing = DoingNone; } } + // Older builds do not pass `--object-dir`, so construct a default if the + // components are available. + if (this->Reporter.OptionObjectDir.empty() && + !this->Reporter.OptionCurrentBuildDir.empty() && + !this->Reporter.OptionTargetName.empty()) { + this->Reporter.OptionObjectDir = + cmStrCat(this->Reporter.OptionCurrentBuildDir, "/CMakeFiles/", + this->Reporter.OptionTargetName, ".dir"); + } + if (!this->Reporter.OptionObjectDir.empty() && + !cmCMakePath(this->Reporter.OptionObjectDir).IsAbsolute() && + !this->Reporter.OptionBuildDir.empty()) { + this->Reporter.OptionObjectDir = cmStrCat( + this->Reporter.OptionBuildDir, '/', this->Reporter.OptionObjectDir); + } + // Extract the real command line. if (arg0) { for (int i = 0; i < argc - arg0; ++i) { diff --git a/Source/CTest/cmCTestLaunchReporter.cxx b/Source/CTest/cmCTestLaunchReporter.cxx index 2e1d2bbf52..a768e2707c 100644 --- a/Source/CTest/cmCTestLaunchReporter.cxx +++ b/Source/CTest/cmCTestLaunchReporter.cxx @@ -78,13 +78,12 @@ void cmCTestLaunchReporter::ComputeFileNames() void cmCTestLaunchReporter::LoadLabels() { - if (this->OptionCurrentBuildDir.empty() || this->OptionTargetName.empty()) { + if (this->OptionObjectDir.empty()) { return; } // Labels are listed in per-target files. - std::string fname = cmStrCat(this->OptionCurrentBuildDir, "/CMakeFiles/", - this->OptionTargetName, ".dir/Labels.txt"); + std::string fname = cmStrCat(this->OptionObjectDir, "/Labels.txt"); // We are interested in per-target labels for this source file. std::string source = this->OptionSource; diff --git a/Source/CTest/cmCTestLaunchReporter.h b/Source/CTest/cmCTestLaunchReporter.h index cc32ced1e1..59692e5c09 100644 --- a/Source/CTest/cmCTestLaunchReporter.h +++ b/Source/CTest/cmCTestLaunchReporter.h @@ -43,6 +43,7 @@ public: std::string OptionCommandType; std::string OptionRole; std::string OptionConfig; + std::string OptionObjectDir; // The real command line appearing after launcher arguments. std::string CWD; diff --git a/Source/cmake.cxx b/Source/cmake.cxx index ff3b490b65..466c6f49e6 100644 --- a/Source/cmake.cxx +++ b/Source/cmake.cxx @@ -2710,7 +2710,8 @@ int cmake::ActualConfigure() if (mf->IsOn("CTEST_USE_LAUNCHERS")) { launcher = cmStrCat('"', cmSystemTools::GetCTestCommand(), "\" --launch " - "--current-build-dir "); + "--current-build-dir " + "--object-dir "); } else { launcher = cmStrCat('"', cmSystemTools::GetCTestCommand(), "\" --instrument ");