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,8 +353,7 @@ IF (WIN32)
ENDIF(NOT UNIX) ENDIF(NOT UNIX)
ENDIF (WIN32) ENDIF (WIN32)
# Ninja only works on UNIX.
IF(UNIX)
SET(SRCS ${SRCS} SET(SRCS ${SRCS}
cmGlobalNinjaGenerator.cxx cmGlobalNinjaGenerator.cxx
cmGlobalNinjaGenerator.h cmGlobalNinjaGenerator.h
@ -369,7 +368,7 @@ IF(UNIX)
cmNinjaUtilityTargetGenerator.h cmNinjaUtilityTargetGenerator.h
) )
ADD_DEFINITIONS(-DCMAKE_USE_NINJA) ADD_DEFINITIONS(-DCMAKE_USE_NINJA)
ENDIF(UNIX)
# create a library used by the command line and the GUI # create a library used by the command line and the GUI
ADD_LIBRARY(CMakeLib ${SRCS}) ADD_LIBRARY(CMakeLib ${SRCS})

View File

@ -59,6 +59,7 @@ static bool IsIdentChar(char c)
(c == '_') || (c == '$') || (c == '\\'); (c == '_') || (c == '$') || (c == '\\');
} }
std::string cmGlobalNinjaGenerator::EncodeIdent(const std::string &ident, std::string cmGlobalNinjaGenerator::EncodeIdent(const std::string &ident,
std::ostream &vars) { std::ostream &vars) {
if (std::find_if(ident.begin(), ident.end(), 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"; vars << names.str() << " = " << ident << "\n";
return "$" + names.str(); return "$" + names.str();
} else { } else {
return ident; return EncodeLiteral(ident);
} }
} }
std::string cmGlobalNinjaGenerator::EncodeLiteral(const std::string &lit) std::string cmGlobalNinjaGenerator::EncodeLiteral(const std::string &lit)
{ {
std::string result = lit; std::string result = lit;
cmSystemTools::ReplaceString(result, "$", "$$"); cmSystemTools::ReplaceString(result, "$", "$$");
cmSystemTools::ReplaceString(result, ":", "$:");
#ifdef _WIN32
cmSystemTools::ReplaceString(result, "/", "\\");
#endif
return result; return result;
} }
@ -200,7 +206,8 @@ cmGlobalNinjaGenerator::WriteCustomCommandBuild(const std::string& command,
this->AddCustomCommandRule(); this->AddCustomCommandRule();
cmNinjaVars vars; cmNinjaVars vars;
vars["COMMAND"] = command;
vars["COMMAND"] = EncodeLiteral(command);
vars["DESC"] = EncodeLiteral(description); vars["DESC"] = EncodeLiteral(description);
cmGlobalNinjaGenerator::WriteBuild(*this->BuildFileStream, 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 // This happens when building a POST_BUILD value for link targets that
// don't use POST_BUILD. // don't use POST_BUILD.
if (cmdLines.empty()) if (cmdLines.empty())
#ifdef _WIN32
return "cd.";
#else
return ":"; return ":";
#endif
// TODO: This will work only on Unix platforms. I don't // 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 // 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 != linkCmds.end();
++i) ++i)
{ {
#ifdef _WIN32
// HACK: no TARGET_IMPLIB here???
cmSystemTools::ReplaceString(*i, "/implib:", "");
#endif
this->GetLocalGenerator()->ExpandRuleVariables(*i, vars); this->GetLocalGenerator()->ExpandRuleVariables(*i, vars);
} }
linkCmds.insert(linkCmds.begin(), "$PRE_LINK"); linkCmds.insert(linkCmds.begin(), "$PRE_LINK");