Ninja: win fixes: escape back slash/colon, use cd. as cmd.exe nop

This commit is contained in:
Peter Kuemmel 2012-02-18 08:07:11 +01:00
parent 5d19e8aa6a
commit 7fb2bb3e8b
4 changed files with 21 additions and 7 deletions

View File

@ -353,9 +353,8 @@ IF (WIN32)
ENDIF(NOT UNIX)
ENDIF (WIN32)
# Ninja only works on UNIX.
IF(UNIX)
SET(SRCS ${SRCS}
SET(SRCS ${SRCS}
cmGlobalNinjaGenerator.cxx
cmGlobalNinjaGenerator.h
cmNinjaTypes.h
@ -368,8 +367,8 @@ IF(UNIX)
cmNinjaUtilityTargetGenerator.cxx
cmNinjaUtilityTargetGenerator.h
)
ADD_DEFINITIONS(-DCMAKE_USE_NINJA)
ENDIF(UNIX)
ADD_DEFINITIONS(-DCMAKE_USE_NINJA)
# create a library used by the command line and the GUI
ADD_LIBRARY(CMakeLib ${SRCS})

View File

@ -59,6 +59,7 @@ static bool IsIdentChar(char c)
(c == '_') || (c == '$') || (c == '\\');
}
std::string cmGlobalNinjaGenerator::EncodeIdent(const std::string &ident,
std::ostream &vars) {
if (std::find_if(ident.begin(), ident.end(),
@ -69,14 +70,19 @@ std::string cmGlobalNinjaGenerator::EncodeIdent(const std::string &ident,
vars << names.str() << " = " << ident << "\n";
return "$" + names.str();
} else {
return ident;
return EncodeLiteral(ident);
}
}
std::string cmGlobalNinjaGenerator::EncodeLiteral(const std::string &lit)
{
std::string result = lit;
cmSystemTools::ReplaceString(result, "$", "$$");
cmSystemTools::ReplaceString(result, ":", "$:");
#ifdef _WIN32
cmSystemTools::ReplaceString(result, "/", "\\");
#endif
return result;
}
@ -200,7 +206,8 @@ cmGlobalNinjaGenerator::WriteCustomCommandBuild(const std::string& command,
this->AddCustomCommandRule();
cmNinjaVars vars;
vars["COMMAND"] = command;
vars["COMMAND"] = EncodeLiteral(command);
vars["DESC"] = EncodeLiteral(description);
cmGlobalNinjaGenerator::WriteBuild(*this->BuildFileStream,

View File

@ -294,7 +294,11 @@ std::string cmLocalNinjaGenerator::BuildCommandLine(
// This happens when building a POST_BUILD value for link targets that
// don't use POST_BUILD.
if (cmdLines.empty())
#ifdef _WIN32
return "cd.";
#else
return ":";
#endif
// TODO: This will work only on Unix platforms. I don't
// want to use a link.txt file because I will lose the benefit of the

View File

@ -172,6 +172,10 @@ cmNinjaNormalTargetGenerator
i != linkCmds.end();
++i)
{
#ifdef _WIN32
// HACK: no TARGET_IMPLIB here???
cmSystemTools::ReplaceString(*i, "/implib:", "");
#endif
this->GetLocalGenerator()->ExpandRuleVariables(*i, vars);
}
linkCmds.insert(linkCmds.begin(), "$PRE_LINK");