diff options
author | Bill Hoffman <bill.hoffman@kitware.com> | 2001-11-21 22:45:01 (GMT) |
---|---|---|
committer | Bill Hoffman <bill.hoffman@kitware.com> | 2001-11-21 22:45:01 (GMT) |
commit | 12551a33c394cd06a082f2df2ad550e38d762a98 (patch) | |
tree | 7d1358ac4841807d28ea9e2d7f18b65390df7acf /Source/cmNMakeMakefileGenerator.cxx | |
parent | 66135bee42c1743eab8f4f64d87585a9824d6d37 (diff) | |
download | CMake-12551a33c394cd06a082f2df2ad550e38d762a98.zip CMake-12551a33c394cd06a082f2df2ad550e38d762a98.tar.gz CMake-12551a33c394cd06a082f2df2ad550e38d762a98.tar.bz2 |
NMake with spaces in directories
Diffstat (limited to 'Source/cmNMakeMakefileGenerator.cxx')
-rw-r--r-- | Source/cmNMakeMakefileGenerator.cxx | 71 |
1 files changed, 54 insertions, 17 deletions
diff --git a/Source/cmNMakeMakefileGenerator.cxx b/Source/cmNMakeMakefileGenerator.cxx index 40b5134..224e1ac 100644 --- a/Source/cmNMakeMakefileGenerator.cxx +++ b/Source/cmNMakeMakefileGenerator.cxx @@ -46,6 +46,34 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "cmMakeDepend.h" #include "cmCacheManager.h" #include "cmGeneratedFileStream.h" +#include "windows.h" + +inline std::string ShortPath(const char* path) +{ + std::string ret = path; + // if there are no spaces in path, then just return path + if(ret.find(' ') == std::string::npos) + { + return ret; + } + + // if there are spaces then call GetShortPathName to get rid of them + char *buffer = new char[strlen(path)+1]; + if(GetShortPathName(path, buffer, + strlen(path)+1) != 0) + { + ret = buffer; + } + else + { + // if GetShortPathName failed for some reason use + // EscapeSpaces instead + ret = cmSystemTools::EscapeSpaces(path); + } + delete [] buffer; + return ret; +} + cmNMakeMakefileGenerator::cmNMakeMakefileGenerator() { @@ -76,6 +104,8 @@ void cmNMakeMakefileGenerator::ComputeSystemInfo() m_Makefile->ReadListFile(NULL,fpath.c_str()); } + + void cmNMakeMakefileGenerator::OutputMakeVariables(std::ostream& fout) { fout << "# NMake Makefile generated by cmake\n"; @@ -98,16 +128,16 @@ void cmNMakeMakefileGenerator::OutputMakeVariables(std::ostream& fout) std::string replaceVars = variables; m_Makefile->ExpandVariablesInString(replaceVars); fout << replaceVars.c_str(); - fout << "CMAKE_CURRENT_SOURCE = " << - cmSystemTools::EscapeSpaces(m_Makefile->GetStartDirectory() ) - << "\n"; + fout << "CMAKE_CURRENT_SOURCE = " + << ShortPath(m_Makefile->GetStartDirectory() ) + << "\n"; fout << "CMAKE_CURRENT_BINARY = " - << cmSystemTools::EscapeSpaces(m_Makefile->GetStartOutputDirectory()) + << ShortPath(m_Makefile->GetStartOutputDirectory()) << "\n"; - fout << "CMAKE_SOURCE_DIR = " << - cmSystemTools::EscapeSpaces(m_Makefile->GetHomeDirectory()) << "\n"; - fout << "CMAKE_BINARY_DIR = " << - cmSystemTools::EscapeSpaces(m_Makefile->GetHomeOutputDirectory() ) + fout << "CMAKE_SOURCE_DIR = " + << ShortPath(m_Makefile->GetHomeDirectory()) << "\n"; + fout << "CMAKE_BINARY_DIR = " + << ShortPath(m_Makefile->GetHomeOutputDirectory() ) << "\n"; // Output Include paths fout << "INCLUDE_FLAGS = "; @@ -139,7 +169,8 @@ void cmNMakeMakefileGenerator::BuildInSubDirectory(std::ostream& fout, { std::string dir = directory; cmSystemTools::ConvertToWindowsSlashes(dir); - fout << "\tif not exist " << dir.c_str() << " " + fout << "\tif not exist " << cmSystemTools::EscapeSpaces(dir.c_str()) + << " " << "$(MAKE) rebuild_cache\n" << "\tcd .\\" << directory << "\n" << "\t$(MAKE) -$(MAKEFLAGS) " << target1 << "\n"; @@ -150,7 +181,7 @@ void cmNMakeMakefileGenerator::BuildInSubDirectory(std::ostream& fout, } std::string currentDir = m_Makefile->GetCurrentOutputDirectory(); cmSystemTools::ConvertToWindowsSlashes(currentDir); - fout << "\tcd " << currentDir.c_str() << "\n"; + fout << "\tcd " << cmSystemTools::EscapeSpaces(currentDir.c_str()) << "\n"; } // This needs to be overriden because nmake requires commands to be quoted @@ -256,7 +287,8 @@ OutputBuildObjectFromSource(std::ostream& fout, compileCommand += "$(CMAKE_SHLIB_CFLAGS) "; } compileCommand += "$(INCLUDE_FLAGS) -c "; - compileCommand += source.GetFullPath(); + compileCommand += + cmSystemTools::EscapeSpaces(source.GetFullPath().c_str()); compileCommand += " /Fo"; compileCommand += objectFile; } @@ -265,7 +297,8 @@ OutputBuildObjectFromSource(std::ostream& fout, compileCommand = "$(RC) /fo\""; compileCommand += objectFile; compileCommand += "\" "; - compileCommand += source.GetFullPath(); + compileCommand += + cmSystemTools::EscapeSpaces(source.GetFullPath().c_str()); } else if (ext == "def") { @@ -282,7 +315,8 @@ OutputBuildObjectFromSource(std::ostream& fout, compileCommand += "$(CMAKE_SHLIB_CFLAGS) "; } compileCommand += "$(INCLUDE_FLAGS) -c "; - compileCommand += source.GetFullPath(); + compileCommand += + cmSystemTools::EscapeSpaces(source.GetFullPath().c_str()); compileCommand += " /Fo"; compileCommand += objectFile; } @@ -290,7 +324,8 @@ OutputBuildObjectFromSource(std::ostream& fout, this->OutputMakeRule(fout, comment.c_str(), objectFile.c_str(), - source.GetFullPath().c_str(), + cmSystemTools::EscapeSpaces( + source.GetFullPath().c_str()).c_str(), compileCommand.c_str()); } @@ -369,8 +404,10 @@ void cmNMakeMakefileGenerator::OutputExecutableRule(std::ostream& fout, std::string command = "$(CMAKE_CXX_COMPILER) $(CMAKE_CXXFLAGS) "; command += "$(" + std::string(name) + "_SRC_OBJS) "; - command += " /Fe" + m_ExecutableOutputPath + name; - command += ".exe /link "; + std::string path = m_ExecutableOutputPath + name + ".exe"; + command += " /Fe" + + cmSystemTools::EscapeSpaces(path.c_str()); + command += " /link "; if(t.GetType() == cmTarget::WIN32_EXECUTABLE) { command += " /subsystem:windows "; @@ -405,7 +442,7 @@ void cmNMakeMakefileGenerator::OutputLinkLibraries(std::ostream& fout, for(std::vector<std::string>::iterator libDir = libdirs.begin(); libDir != libdirs.end(); ++libDir) { - std::string libpath = cmSystemTools::EscapeSpaces(libDir->c_str()); + std::string libpath = ShortPath(libDir->c_str()); if(emitted.insert(libpath).second) { linkLibs += "-LIBPATH:"; |