mirror of
https://github.com/Kitware/CMake.git
synced 2026-04-28 09:59:20 -05:00
GHS: fix build event script error on Linux
On Linux run build events scripts as "/bin/sh script.sh". Prefer using _WIN32 over variable for host platform decisions. -- This is consistant with other parts of CMake.
This commit is contained in:
@@ -36,11 +36,6 @@ cmGhsMultiTargetGenerator::cmGhsMultiTargetGenerator(cmGeneratorTarget* target)
|
|||||||
static_cast<cmLocalGhsMultiGenerator*>(target->GetLocalGenerator()))
|
static_cast<cmLocalGhsMultiGenerator*>(target->GetLocalGenerator()))
|
||||||
, Makefile(target->Target->GetMakefile())
|
, Makefile(target->Target->GetMakefile())
|
||||||
, Name(target->GetName())
|
, Name(target->GetName())
|
||||||
#ifdef _WIN32
|
|
||||||
, CmdWindowsShell(true)
|
|
||||||
#else
|
|
||||||
, CmdWindowsShell(false)
|
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
// Store the configuration name that is being used
|
// Store the configuration name that is being used
|
||||||
if (cmValue config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE")) {
|
if (cmValue config = this->Makefile->GetDefinition("CMAKE_BUILD_TYPE")) {
|
||||||
@@ -316,19 +311,37 @@ void cmGhsMultiTargetGenerator::WriteTargetLinkLine(std::ostream& fout,
|
|||||||
|
|
||||||
void cmGhsMultiTargetGenerator::WriteBuildEvents(std::ostream& fout)
|
void cmGhsMultiTargetGenerator::WriteBuildEvents(std::ostream& fout)
|
||||||
{
|
{
|
||||||
this->WriteBuildEventsHelper(
|
this->WriteBuildEventsHelper(fout,
|
||||||
fout, this->GeneratorTarget->GetPreBuildCommands(),
|
this->GeneratorTarget->GetPreBuildCommands(),
|
||||||
std::string("prebuild"), std::string("preexecShell"));
|
std::string("prebuild"),
|
||||||
|
#ifdef _WIN32
|
||||||
|
std::string("preexecShell")
|
||||||
|
#else
|
||||||
|
std::string("preexec")
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
|
||||||
if (this->TagType != GhsMultiGpj::CUSTOM_TARGET) {
|
if (this->TagType != GhsMultiGpj::CUSTOM_TARGET) {
|
||||||
this->WriteBuildEventsHelper(
|
this->WriteBuildEventsHelper(fout,
|
||||||
fout, this->GeneratorTarget->GetPreLinkCommands(),
|
this->GeneratorTarget->GetPreLinkCommands(),
|
||||||
std::string("prelink"), std::string("preexecShell"));
|
std::string("prelink"),
|
||||||
|
#ifdef _WIN32
|
||||||
|
std::string("preexecShell")
|
||||||
|
#else
|
||||||
|
std::string("preexec")
|
||||||
|
#endif
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->WriteBuildEventsHelper(
|
this->WriteBuildEventsHelper(fout,
|
||||||
fout, this->GeneratorTarget->GetPostBuildCommands(),
|
this->GeneratorTarget->GetPostBuildCommands(),
|
||||||
std::string("postbuild"), std::string("postexecShell"));
|
std::string("postbuild"),
|
||||||
|
#ifdef _WIN32
|
||||||
|
std::string("postexecShell")
|
||||||
|
#else
|
||||||
|
std::string("postexec")
|
||||||
|
#endif
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmGhsMultiTargetGenerator::WriteBuildEventsHelper(
|
void cmGhsMultiTargetGenerator::WriteBuildEventsHelper(
|
||||||
@@ -336,6 +349,13 @@ void cmGhsMultiTargetGenerator::WriteBuildEventsHelper(
|
|||||||
std::string const& name, std::string const& cmd)
|
std::string const& name, std::string const& cmd)
|
||||||
{
|
{
|
||||||
int cmdcount = 0;
|
int cmdcount = 0;
|
||||||
|
#ifdef _WIN32
|
||||||
|
std::string fext = ".bat";
|
||||||
|
std::string shell;
|
||||||
|
#else
|
||||||
|
std::string fext = ".sh";
|
||||||
|
std::string shell = "/bin/sh ";
|
||||||
|
#endif
|
||||||
|
|
||||||
for (cmCustomCommand const& cc : ccv) {
|
for (cmCustomCommand const& cc : ccv) {
|
||||||
cmCustomCommandGenerator ccg(cc, this->ConfigName, this->LocalGenerator);
|
cmCustomCommandGenerator ccg(cc, this->ConfigName, this->LocalGenerator);
|
||||||
@@ -343,14 +363,14 @@ void cmGhsMultiTargetGenerator::WriteBuildEventsHelper(
|
|||||||
std::string fname =
|
std::string fname =
|
||||||
cmStrCat(this->LocalGenerator->GetCurrentBinaryDirectory(), '/',
|
cmStrCat(this->LocalGenerator->GetCurrentBinaryDirectory(), '/',
|
||||||
this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget),
|
this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget),
|
||||||
'/', this->Name, '_', name, cmdcount++,
|
'/', this->Name, '_', name, cmdcount++, fext);
|
||||||
this->CmdWindowsShell ? ".bat" : ".sh");
|
|
||||||
cmGeneratedFileStream f(fname);
|
cmGeneratedFileStream f(fname);
|
||||||
f.SetCopyIfDifferent(true);
|
f.SetCopyIfDifferent(true);
|
||||||
this->WriteCustomCommandsHelper(f, ccg);
|
this->WriteCustomCommandsHelper(f, ccg);
|
||||||
f.Close();
|
f.Close();
|
||||||
if (this->TagType != GhsMultiGpj::CUSTOM_TARGET) {
|
if (this->TagType != GhsMultiGpj::CUSTOM_TARGET) {
|
||||||
fout << " :" << cmd << "=\"" << fname << "\"\n";
|
fout << " :" << cmd << "=\"" << shell << fname << "\"\n";
|
||||||
} else {
|
} else {
|
||||||
fout << fname << "\n :outputName=\"" << fname << ".rule\"\n";
|
fout << fname << "\n :outputName=\"" << fname << ".rule\"\n";
|
||||||
}
|
}
|
||||||
@@ -409,15 +429,15 @@ void cmGhsMultiTargetGenerator::WriteCustomCommandsHelper(
|
|||||||
//
|
//
|
||||||
bool useCall = false;
|
bool useCall = false;
|
||||||
|
|
||||||
if (this->CmdWindowsShell) {
|
#ifdef _WIN32
|
||||||
std::string suffix;
|
std::string suffix;
|
||||||
if (cmd.size() > 4) {
|
if (cmd.size() > 4) {
|
||||||
suffix = cmSystemTools::LowerCase(cmd.substr(cmd.size() - 4));
|
suffix = cmSystemTools::LowerCase(cmd.substr(cmd.size() - 4));
|
||||||
if (suffix == ".bat" || suffix == ".cmd") {
|
if (suffix == ".bat" || suffix == ".cmd") {
|
||||||
useCall = true;
|
useCall = true;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
cmSystemTools::ReplaceString(cmd, "/./", "/");
|
cmSystemTools::ReplaceString(cmd, "/./", "/");
|
||||||
// Convert the command to a relative path only if the current
|
// Convert the command to a relative path only if the current
|
||||||
@@ -645,6 +665,11 @@ void cmGhsMultiTargetGenerator::WriteSources(std::ostream& fout_proj)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
int cmdcount = 0;
|
int cmdcount = 0;
|
||||||
|
#ifdef _WIN32
|
||||||
|
std::string fext = ".bat";
|
||||||
|
#else
|
||||||
|
std::string fext = ".sh";
|
||||||
|
#endif
|
||||||
for (auto& sf : customCommands) {
|
for (auto& sf : customCommands) {
|
||||||
const cmCustomCommand* cc = sf->GetCustomCommand();
|
const cmCustomCommand* cc = sf->GetCustomCommand();
|
||||||
cmCustomCommandGenerator ccg(*cc, this->ConfigName,
|
cmCustomCommandGenerator ccg(*cc, this->ConfigName,
|
||||||
@@ -655,8 +680,8 @@ void cmGhsMultiTargetGenerator::WriteSources(std::ostream& fout_proj)
|
|||||||
this->LocalGenerator->GetCurrentBinaryDirectory(), '/',
|
this->LocalGenerator->GetCurrentBinaryDirectory(), '/',
|
||||||
this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget),
|
this->LocalGenerator->GetTargetDirectory(this->GeneratorTarget),
|
||||||
'/', this->Name, "_cc", cmdcount++, '_',
|
'/', this->Name, "_cc", cmdcount++, '_',
|
||||||
(sf->GetLocation()).GetName(),
|
(sf->GetLocation()).GetName(), fext);
|
||||||
this->CmdWindowsShell ? ".bat" : ".sh");
|
|
||||||
cmGeneratedFileStream f(fname);
|
cmGeneratedFileStream f(fname);
|
||||||
f.SetCopyIfDifferent(true);
|
f.SetCopyIfDifferent(true);
|
||||||
this->WriteCustomCommandsHelper(f, ccg);
|
this->WriteCustomCommandsHelper(f, ccg);
|
||||||
|
|||||||
@@ -78,6 +78,5 @@ private:
|
|||||||
std::string TargetNameReal;
|
std::string TargetNameReal;
|
||||||
GhsMultiGpj::Types TagType;
|
GhsMultiGpj::Types TagType;
|
||||||
std::string const Name;
|
std::string const Name;
|
||||||
std::string ConfigName; /* CMAKE_BUILD_TYPE */
|
std::string ConfigName; /* CMAKE_BUILD_TYPE */
|
||||||
bool const CmdWindowsShell; /* custom commands run in cmd.exe or /bin/sh */
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user