MCPcopy Create free account
hub / github.com/Kitware/CMake / AppendCustomCommand

Method AppendCustomCommand

Source/cmLocalUnixMakefileGenerator3.cxx:975–1136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

973}
974
975void cmLocalUnixMakefileGenerator3::AppendCustomCommand(
976 std::vector<std::string>& commands, cmCustomCommandGenerator const& ccg,
977 cmGeneratorTarget* target, std::string const& relative, bool echo_comment,
978 std::ostream* content)
979{
980 // Optionally create a command to display the custom command's
981 // comment text. This is used for pre-build, pre-link, and
982 // post-build command comments. Custom build step commands have
983 // their comments generated elsewhere.
984 if (echo_comment) {
985 if (cm::optional<std::string> comment = ccg.GetComment()) {
986 this->AppendEcho(commands, *comment,
987 cmLocalUnixMakefileGenerator3::EchoGenerate);
988 }
989 }
990
991 // if the command specified a working directory use it.
992 std::string dir = this->GetCurrentBinaryDirectory();
993 std::string workingDir = ccg.GetWorkingDirectory();
994 if (!workingDir.empty()) {
995 dir = workingDir;
996 }
997 if (content) {
998 *content << dir;
999 }
1000
1001 auto rulePlaceholderExpander = this->CreateRulePlaceholderExpander();
1002
1003 // Add each command line to the set of commands.
1004 std::vector<std::string> commands1;
1005 for (unsigned int c = 0; c < ccg.GetNumberOfCommands(); ++c) {
1006 // Build the command line in a single string.
1007 std::string cmd = ccg.GetCommand(c);
1008 if (!cmd.empty()) {
1009 // Use "call " before any invocations of .bat or .cmd files
1010 // invoked as custom commands in the WindowsShell.
1011 //
1012 bool useCall = false;
1013
1014 if (this->IsWindowsShell()) {
1015 std::string suffix;
1016 if (cmd.size() > 4) {
1017 suffix = cmSystemTools::LowerCase(cmd.substr(cmd.size() - 4));
1018 if (suffix == ".bat" || suffix == ".cmd") {
1019 useCall = true;
1020 }
1021 }
1022 }
1023
1024 cmSystemTools::ReplaceString(cmd, "/./", "/");
1025 // Convert the command to a relative path only if the current
1026 // working directory will be the start-output directory.
1027 bool had_slash = cmd.find('/') != std::string::npos;
1028 if (workingDir.empty()) {
1029 cmd = this->MaybeRelativeToCurBinDir(cmd);
1030 }
1031 bool has_slash = cmd.find('/') != std::string::npos;
1032 if (had_slash && !has_slash) {

Callers 2

AppendCustomCommandsMethod · 0.95

Calls 15

AppendEchoMethod · 0.95
CreateCDCommandMethod · 0.95
cmNonemptyFunction · 0.85
moveFunction · 0.85
transformFunction · 0.85
appendFunction · 0.85
GetNumberOfCommandsMethod · 0.80
IsWindowsShellMethod · 0.80
GetRuleLauncherMethod · 0.80

Tested by

no test coverage detected