summaryrefslogtreecommitdiffstats
path: root/Source/cmNMakeMakefileGenerator.cxx
diff options
context:
space:
mode:
authorBerk Geveci <berk.geveci@kitware.com>2001-11-27 22:53:05 (GMT)
committerBerk Geveci <berk.geveci@kitware.com>2001-11-27 22:53:05 (GMT)
commit0180d3156f6f016d0923fd150d1a93d883b0b257 (patch)
treece917961bde88036f891e6b2568f46d380232b6b /Source/cmNMakeMakefileGenerator.cxx
parent1944e1887df5a08abb9969268b0f8be272275c01 (diff)
downloadCMake-0180d3156f6f016d0923fd150d1a93d883b0b257.zip
CMake-0180d3156f6f016d0923fd150d1a93d883b0b257.tar.gz
CMake-0180d3156f6f016d0923fd150d1a93d883b0b257.tar.bz2
ENH: nmake generator much closer to working with spaces
Diffstat (limited to 'Source/cmNMakeMakefileGenerator.cxx')
-rw-r--r--Source/cmNMakeMakefileGenerator.cxx88
1 files changed, 74 insertions, 14 deletions
diff --git a/Source/cmNMakeMakefileGenerator.cxx b/Source/cmNMakeMakefileGenerator.cxx
index 224e1ac..1e5a2f7 100644
--- a/Source/cmNMakeMakefileGenerator.cxx
+++ b/Source/cmNMakeMakefileGenerator.cxx
@@ -48,6 +48,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "cmGeneratedFileStream.h"
#include "windows.h"
+// convert to windows short paths if there are spaces
+// in path
inline std::string ShortPath(const char* path)
{
std::string ret = path;
@@ -75,6 +77,34 @@ inline std::string ShortPath(const char* path)
}
+// convert a command to a short path if it has spaces
+// this separates the arguments from the command and puts
+// them back together
+inline std::string ShortPathCommand(const char* command)
+{
+ if(!strchr(command, ' '))
+ {
+ return command;
+ }
+ cmRegularExpression reg("^\"([^\"]*)\"(.*)");
+ if(reg.find(command))
+ {
+ std::string c = reg.match(1);
+ cmRegularExpression removeIntDir("(.*)/\\$\\(IntDir\\)(.*)");
+ if(removeIntDir.find(c))
+ {
+ c = removeIntDir.match(1) + removeIntDir.match(2);
+ }
+ c = ShortPath(c.c_str());
+ std::string ret = c;
+ std::string args = reg.match(2);
+ ret += args;
+ return ret;
+ }
+ return command;
+}
+
+
cmNMakeMakefileGenerator::cmNMakeMakefileGenerator()
{
this->SetObjectFileExtension(".obj");
@@ -89,6 +119,7 @@ cmNMakeMakefileGenerator::~cmNMakeMakefileGenerator()
{
}
+
void cmNMakeMakefileGenerator::ComputeSystemInfo()
{
// now load the settings
@@ -184,6 +215,9 @@ void cmNMakeMakefileGenerator::BuildInSubDirectory(std::ostream& fout,
fout << "\tcd " << cmSystemTools::EscapeSpaces(currentDir.c_str()) << "\n";
}
+
+
+
// This needs to be overriden because nmake requires commands to be quoted
// if the are full paths to the executable????
@@ -232,25 +266,25 @@ void cmNMakeMakefileGenerator::OutputMakeRule(std::ostream& fout,
}
if(command)
{
- replace = command;
+ replace = ShortPathCommand(command);
m_Makefile->ExpandVariablesInString(replace);
fout << startCommand << replace.c_str() << endCommand;
}
if(command2)
{
- replace = command2;
+ replace = ShortPathCommand(command2);
m_Makefile->ExpandVariablesInString(replace);
fout << startCommand << replace.c_str() << endCommand;
}
if(command3)
{
- replace = command3;
+ replace = ShortPathCommand(command3);
m_Makefile->ExpandVariablesInString(replace);
fout << startCommand << replace.c_str() << endCommand;
}
if(command4)
{
- replace = command4;
+ replace = ShortPathCommand(command4);
m_Makefile->ExpandVariablesInString(replace);
fout << startCommand << replace.c_str() << endCommand;
}
@@ -339,7 +373,8 @@ void cmNMakeMakefileGenerator::OutputSharedLibraryRule(std::ostream& fout,
depend += "_SRC_OBJS) $(" + std::string(name) + "_DEPEND_LIBS)";
std::string command = "link /dll @<<\n";
command += "$(" + std::string(name) + "_SRC_OBJS) /out:";
- command += m_LibraryOutputPath + std::string(name) + ".dll ";
+ std::string dllpath = m_LibraryOutputPath + std::string(name) + ".dll ";
+ command += cmSystemTools::EscapeSpaces(dllpath.c_str());
std::strstream linklibs;
this->OutputLinkLibraries(linklibs, name, t);
linklibs << std::ends;
@@ -378,9 +413,9 @@ void cmNMakeMakefileGenerator::OutputStaticLibraryRule(std::ostream& fout,
std::string depend = "$(";
depend += std::string(name) + "_SRC_OBJS)";
std::string command = "link -lib @<<\n\t/nologo /out:";
- command += m_LibraryOutputPath;
- command += name;
- command += ".lib $(";
+ std::string libpath = m_LibraryOutputPath + std::string(name) + ".lib";
+ command += cmSystemTools::EscapeSpaces(libpath.c_str());
+ command += " $(";
command += std::string(name) + "_SRC_OBJS)";
command += "\n<<\n";
std::string comment = "rule to build static library: ";
@@ -466,16 +501,25 @@ void cmNMakeMakefileGenerator::OutputLinkLibraries(std::ostream& fout,
// skip zero size library entries, this may happen
// if a variable expands to nothing.
if (lib->first.size() == 0) continue;
- // if it is a full path break it into -L and -l
if(emitted.insert(lib->first).second)
{
- linkLibs += lib->first;
- linkLibs += ".lib ";
+ cmRegularExpression reg(".*\\.lib$");
+ // if it ends in .lib, then it is a full path and should
+ // be escaped, and does not need .lib added
+ if(reg.find(lib->first))
+ {
+ librariesLinked += ShortPath(lib->first.c_str());
+ librariesLinked += " ";
+ }
+ else
+ {
+ librariesLinked += lib->first;
+ librariesLinked += ".lib ";
+ }
}
- linkLibs += librariesLinked;
-
- fout << linkLibs;
}
+ linkLibs += librariesLinked;
+ fout << linkLibs;
fout << "$(CMAKE_STANDARD_WINDOWS_LIBRARIES) ";
}
@@ -505,3 +549,19 @@ void cmNMakeMakefileGenerator::OutputIncludeMakefile(std::ostream& fout,
fout << "!include " << file << "\n";
}
+
+
+void cmNMakeMakefileGenerator::OutputBuildLibraryInDir(std::ostream& fout,
+ const char* path,
+ const char* ,
+ const char* fullpath)
+{
+
+ std::string currentDir = m_Makefile->GetCurrentOutputDirectory();
+ cmSystemTools::ConvertToWindowsSlashes(currentDir);
+ fout << cmSystemTools::EscapeSpaces(fullpath)
+ << ":\n\tcd " << cmSystemTools::EscapeSpaces(path)
+ << "\n\t$(MAKE) " << cmSystemTools::EscapeSpaces(fullpath)
+ << "\n\tcd " <<
+ cmSystemTools::EscapeSpaces(currentDir.c_str()) << "\n";
+}