summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2024-01-29 15:50:22 (GMT)
committerKitware Robot <kwrobot@kitware.com>2024-01-29 15:50:34 (GMT)
commit622a498477403a18b7abf3e50124cbf62c5bb6ca (patch)
tree5e8ddc072c54db2828146da2abcbacba65d2ed2d /Source
parent87bbfa1bc59c66df132af6344f6f8ed18449ed85 (diff)
parent13ece67a58a4755807a2e9001e245fdafe9e52e2 (diff)
downloadCMake-622a498477403a18b7abf3e50124cbf62c5bb6ca.zip
CMake-622a498477403a18b7abf3e50124cbf62c5bb6ca.tar.gz
CMake-622a498477403a18b7abf3e50124cbf62c5bb6ca.tar.bz2
Merge topic 'test-launcher-emulator-genex'
13ece67a58 Add genex support to TEST_LAUNCHER and CROSSCOMPILING_EMULATOR b9ad73fcb2 cmTestGenerator: De-duplicate TEST_LAUNCHER and CROSSCOMPILING_EMULATOR impl Acked-by: Kitware Robot <kwrobot@kitware.com> Merge-request: !9198
Diffstat (limited to 'Source')
-rw-r--r--Source/cmCustomCommandGenerator.cxx13
-rw-r--r--Source/cmFileAPICodemodel.cxx28
-rw-r--r--Source/cmTestGenerator.cxx44
3 files changed, 51 insertions, 34 deletions
diff --git a/Source/cmCustomCommandGenerator.cxx b/Source/cmCustomCommandGenerator.cxx
index 634b63b..2dea338 100644
--- a/Source/cmCustomCommandGenerator.cxx
+++ b/Source/cmCustomCommandGenerator.cxx
@@ -284,8 +284,12 @@ void cmCustomCommandGenerator::FillEmulatorsWithArguments()
if (!this->LG->GetMakefile()->IsOn("CMAKE_CROSSCOMPILING")) {
return;
}
+ cmGeneratorExpression ge(*this->LG->GetCMakeInstance(),
+ this->CC->GetBacktrace());
for (unsigned int c = 0; c < this->GetNumberOfCommands(); ++c) {
+ // If the command is the plain name of an executable target,
+ // launch it with its emulator.
std::string const& argv0 = this->CommandLines[c][0];
cmGeneratorTarget* target = this->LG->FindGeneratorTargetToUse(argv0);
if (target && target->GetType() == cmStateEnums::EXECUTABLE &&
@@ -297,7 +301,12 @@ void cmCustomCommandGenerator::FillEmulatorsWithArguments()
continue;
}
- cmExpandList(*emulator_property, this->EmulatorsWithArguments[c]);
+ // Plain target names are replaced by GetArgv0Location with the
+ // path to the executable artifact in the command config, so
+ // evaluate the launcher's location in the command config too.
+ std::string const emulator =
+ ge.Parse(*emulator_property)->Evaluate(this->LG, this->CommandConfig);
+ cmExpandList(emulator, this->EmulatorsWithArguments[c]);
}
}
}
@@ -313,6 +322,8 @@ std::vector<std::string> cmCustomCommandGenerator::GetCrossCompilingEmulator(
const char* cmCustomCommandGenerator::GetArgv0Location(unsigned int c) const
{
+ // If the command is the plain name of an executable target, we replace it
+ // with the path to the executable artifact in the command config.
std::string const& argv0 = this->CommandLines[c][0];
cmGeneratorTarget* target = this->LG->FindGeneratorTargetToUse(argv0);
if (target && target->GetType() == cmStateEnums::EXECUTABLE &&
diff --git a/Source/cmFileAPICodemodel.cxx b/Source/cmFileAPICodemodel.cxx
index 30a7e67..e9302da 100644
--- a/Source/cmFileAPICodemodel.cxx
+++ b/Source/cmFileAPICodemodel.cxx
@@ -2092,18 +2092,22 @@ Json::Value Target::DumpLauncher(const char* name, const char* type)
cmValue property = this->GT->GetProperty(name);
Json::Value launcher;
if (property) {
- cmList commandWithArgs{ *property };
- std::string command(commandWithArgs[0]);
- cmSystemTools::ConvertToUnixSlashes(command);
- launcher = Json::objectValue;
- launcher["command"] = RelativeIfUnder(this->TopSource, command);
- launcher["type"] = type;
- Json::Value args;
- for (std::string const& arg : cmMakeRange(commandWithArgs).advance(1)) {
- args.append(arg);
- }
- if (!args.empty()) {
- launcher["arguments"] = std::move(args);
+ cmLocalGenerator* lg = this->GT->GetLocalGenerator();
+ cmGeneratorExpression ge(*lg->GetCMakeInstance());
+ cmList commandWithArgs{ ge.Parse(*property)->Evaluate(lg, this->Config) };
+ if (!commandWithArgs.empty() && !commandWithArgs[0].empty()) {
+ std::string command(commandWithArgs[0]);
+ cmSystemTools::ConvertToUnixSlashes(command);
+ launcher = Json::objectValue;
+ launcher["command"] = RelativeIfUnder(this->TopSource, command);
+ launcher["type"] = type;
+ Json::Value args;
+ for (std::string const& arg : cmMakeRange(commandWithArgs).advance(1)) {
+ args.append(arg);
+ }
+ if (!args.empty()) {
+ launcher["arguments"] = std::move(args);
+ }
}
}
return launcher;
diff --git a/Source/cmTestGenerator.cxx b/Source/cmTestGenerator.cxx
index 3194d8f..840d8cf 100644
--- a/Source/cmTestGenerator.cxx
+++ b/Source/cmTestGenerator.cxx
@@ -167,31 +167,33 @@ void cmTestGenerator::GenerateScriptForConfig(std::ostream& os,
if (target && target->GetType() == cmStateEnums::EXECUTABLE) {
// Use the target file on disk.
exe = target->GetFullPath(config);
- auto useEmulator = !this->GetTest()->GetCMP0158IsNew() ||
- this->LG->GetMakefile()->IsOn("CMAKE_CROSSCOMPILING");
- // Prepend with the test launcher if specified.
- cmValue launcher = target->GetProperty("TEST_LAUNCHER");
- if (cmNonempty(launcher)) {
- cmList launcherWithArgs{ *launcher };
- std::string launcherExe(launcherWithArgs[0]);
- cmSystemTools::ConvertToUnixSlashes(launcherExe);
- os << cmOutputConverter::EscapeForCMake(launcherExe) << " ";
- for (std::string const& arg : cmMakeRange(launcherWithArgs).advance(1)) {
- os << cmOutputConverter::EscapeForCMake(arg) << " ";
+ auto addLauncher = [this, &config, &ge, &os,
+ target](std::string const& propertyName) {
+ cmValue launcher = target->GetProperty(propertyName);
+ if (!cmNonempty(launcher)) {
+ return;
}
- }
+ cmList launcherWithArgs{ ge.Parse(*launcher)->Evaluate(this->LG,
+ config) };
+ if (!launcherWithArgs.empty() && !launcherWithArgs[0].empty()) {
+ std::string launcherExe(launcherWithArgs[0]);
+ cmSystemTools::ConvertToUnixSlashes(launcherExe);
+ os << cmOutputConverter::EscapeForCMake(launcherExe) << " ";
+ for (std::string const& arg :
+ cmMakeRange(launcherWithArgs).advance(1)) {
+ os << cmOutputConverter::EscapeForCMake(arg) << " ";
+ }
+ }
+ };
+
+ // Prepend with the test launcher if specified.
+ addLauncher("TEST_LAUNCHER");
// Prepend with the emulator when cross compiling if required.
- cmValue emulator = target->GetProperty("CROSSCOMPILING_EMULATOR");
- if (cmNonempty(emulator) && useEmulator) {
- cmList emulatorWithArgs{ *emulator };
- std::string emulatorExe(emulatorWithArgs[0]);
- cmSystemTools::ConvertToUnixSlashes(emulatorExe);
- os << cmOutputConverter::EscapeForCMake(emulatorExe) << " ";
- for (std::string const& arg : cmMakeRange(emulatorWithArgs).advance(1)) {
- os << cmOutputConverter::EscapeForCMake(arg) << " ";
- }
+ if (!this->GetTest()->GetCMP0158IsNew() ||
+ this->LG->GetMakefile()->IsOn("CMAKE_CROSSCOMPILING")) {
+ addLauncher("CROSSCOMPILING_EMULATOR");
}
} else {
// Use the command name given.