Closer to nmake build

This commit is contained in:
Bill Hoffman 2001-11-14 18:12:22 -05:00
parent a8d47b7221
commit 94f82edd07
8 changed files with 102 additions and 44 deletions

View File

@ -438,6 +438,18 @@ std::string cmSystemTools::LowerCase(const std::string& s)
return n; return n;
} }
// Return a lower case string
std::string cmSystemTools::UpperCase(const std::string& s)
{
std::string n;
n.resize(s.size());
for (size_t i = 0; i < s.size(); i++)
{
n[i] = toupper(s[i]);
}
return n;
}
// convert windows slashes to unix slashes \ with / // convert windows slashes to unix slashes \ with /
const char *cmSystemTools::ConvertToUnixSlashes(std::string& path) const char *cmSystemTools::ConvertToUnixSlashes(std::string& path)

View File

@ -100,6 +100,11 @@ public:
*/ */
static std::string LowerCase(const std::string&); static std::string LowerCase(const std::string&);
/**
* Return a lower case string
*/
static std::string UpperCase(const std::string&);
/** /**
* Replace Windows file system slashes with Unix-style slashes. * Replace Windows file system slashes with Unix-style slashes.
*/ */

View File

@ -291,17 +291,20 @@ void cmUnixMakefileGenerator::OutputTargetRules(std::ostream& fout)
{ {
if(l->second.GetType() == cmTarget::STATIC_LIBRARY) if(l->second.GetType() == cmTarget::STATIC_LIBRARY)
{ {
fout << " \\\n" << m_LibraryOutputPath << "lib" << l->first.c_str() fout << " \\\n" << m_LibraryOutputPath << m_LibraryPrefix
<< ".a"; << l->first.c_str()
<< m_StaticLibraryExtension;
} }
else if(l->second.GetType() == cmTarget::SHARED_LIBRARY) else if(l->second.GetType() == cmTarget::SHARED_LIBRARY)
{ {
fout << " \\\n" << m_LibraryOutputPath << "lib" << l->first.c_str() fout << " \\\n" << m_LibraryOutputPath << m_LibraryPrefix
<< l->first.c_str()
<< m_Makefile->GetDefinition("CMAKE_SHLIB_SUFFIX"); << m_Makefile->GetDefinition("CMAKE_SHLIB_SUFFIX");
} }
else if(l->second.GetType() == cmTarget::MODULE_LIBRARY) else if(l->second.GetType() == cmTarget::MODULE_LIBRARY)
{ {
fout << " \\\n" << m_LibraryOutputPath << "lib" << l->first.c_str() fout << " \\\n" << m_LibraryOutputPath << m_LibraryPrefix
<< l->first.c_str()
<< m_Makefile->GetDefinition("CMAKE_MODULE_SUFFIX"); << m_Makefile->GetDefinition("CMAKE_MODULE_SUFFIX");
} }
} }
@ -792,18 +795,19 @@ void cmUnixMakefileGenerator::OutputLibDepend(std::ostream& fout,
if(m_LibraryOutputPath.size()) if(m_LibraryOutputPath.size())
{ {
libpath = m_LibraryOutputPath; libpath = m_LibraryOutputPath;
libpath += "lib"; libpath += m_LibraryPrefix;
} }
else else
{ {
libpath += "/lib"; libpath += "/";
libpath += m_LibraryPrefix;
} }
} }
else else
{ {
// library is in current Makefile so use lib as a prefix // library is in current Makefile so use lib as a prefix
libpath = m_LibraryOutputPath; libpath = m_LibraryOutputPath;
libpath += "lib"; libpath += m_LibraryPrefix;
} }
// add the library name // add the library name
libpath += name; libpath += name;
@ -821,7 +825,7 @@ void cmUnixMakefileGenerator::OutputLibDepend(std::ostream& fout,
} }
else else
{ {
libpath += ".a"; libpath += m_StaticLibraryExtension;
} }
fout << libpath << " "; fout << libpath << " ";
} }
@ -1043,16 +1047,22 @@ void cmUnixMakefileGenerator::OutputCustomRules(std::ostream& fout)
// with no outputs // with no outputs
if(commandFiles.m_Outputs.size() == 0) if(commandFiles.m_Outputs.size() == 0)
{ {
fout << source.c_str() << ": "; std::string depends;
// Write out all the dependencies for this rule. // collect out all the dependencies for this rule.
for(std::set<std::string>::const_iterator d = for(std::set<std::string>::const_iterator d =
commandFiles.m_Depends.begin(); commandFiles.m_Depends.begin();
d != commandFiles.m_Depends.end(); ++d) d != commandFiles.m_Depends.end(); ++d)
{ {
std::string dep = cmSystemTools::EscapeSpaces(d->c_str()); std::string dep = cmSystemTools::EscapeSpaces(d->c_str());
fout << " " << dep.c_str(); depends += " ";
} depends += dep;
fout << "\n\t" << command.c_str() << "\n\n"; }
// output rule
this->OutputMakeRule(fout,
"Custom command",
source.c_str(),
depends.c_str(),
command.c_str());
} }
// Write a rule for every output generated by this command. // Write a rule for every output generated by this command.
for(std::set<std::string>::const_iterator output = for(std::set<std::string>::const_iterator output =
@ -1060,16 +1070,23 @@ void cmUnixMakefileGenerator::OutputCustomRules(std::ostream& fout)
output != commandFiles.m_Outputs.end(); ++output) output != commandFiles.m_Outputs.end(); ++output)
{ {
std::string src = cmSystemTools::EscapeSpaces(source.c_str()); std::string src = cmSystemTools::EscapeSpaces(source.c_str());
fout << output->c_str() << ": " << src.c_str(); std::string depends;
// Write out all the dependencies for this rule. depends += src;
// Collect out all the dependencies for this rule.
for(std::set<std::string>::const_iterator d = for(std::set<std::string>::const_iterator d =
commandFiles.m_Depends.begin(); commandFiles.m_Depends.begin();
d != commandFiles.m_Depends.end(); ++d) d != commandFiles.m_Depends.end(); ++d)
{ {
std::string dep = cmSystemTools::EscapeSpaces(d->c_str()); std::string dep = cmSystemTools::EscapeSpaces(d->c_str());
fout << " " << dep.c_str(); depends += " ";
} depends += dep;
fout << "\n\t" << command.c_str() << "\n\n"; }
// output rule
this->OutputMakeRule(fout,
"Custom command",
output->c_str(),
depends.c_str(),
command.c_str());
} }
} }
} }
@ -1510,6 +1527,7 @@ void cmUnixMakefileGenerator::OutputSourceObjectBuildRules(std::ostream& fout)
sourceName = source->GetFullPath(); sourceName = source->GetFullPath();
shortName = cmSystemTools::GetFilenameName(source->GetSourceName()); shortName = cmSystemTools::GetFilenameName(source->GetSourceName());
} }
shortName += source->GetSourceExtension();
// Only output a rule for each .o once. // Only output a rule for each .o once.
if(rules.find(shortName) == rules.end()) if(rules.find(shortName) == rules.end())
{ {

View File

@ -156,11 +156,12 @@ protected:
void SetStaticLibraryExtension(const char* e) {m_StaticLibraryExtension = e;} void SetStaticLibraryExtension(const char* e) {m_StaticLibraryExtension = e;}
void SetSharedLibraryExtension(const char* e) {m_SharedLibraryExtension = e;} void SetSharedLibraryExtension(const char* e) {m_SharedLibraryExtension = e;}
void SetLibraryPrefix(const char* e) { m_LibraryPrefix = e;} void SetLibraryPrefix(const char* e) { m_LibraryPrefix = e;}
protected:
std::string m_ExecutableOutputPath;
std::string m_LibraryOutputPath;
private: private:
bool m_CacheOnly; bool m_CacheOnly;
bool m_Recurse; bool m_Recurse;
std::string m_ExecutableOutputPath;
std::string m_LibraryOutputPath;
std::string m_ObjectFileExtension; std::string m_ObjectFileExtension;
std::string m_ExecutableExtension; std::string m_ExecutableExtension;
std::string m_StaticLibraryExtension; std::string m_StaticLibraryExtension;

View File

@ -45,6 +45,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#if defined(_WIN32) && !defined(__CYGWIN__) #if defined(_WIN32) && !defined(__CYGWIN__)
#include "cmMSProjectGenerator.h" #include "cmMSProjectGenerator.h"
#include "cmBorlandMakefileGenerator.h" #include "cmBorlandMakefileGenerator.h"
#include "cmNMakeMakefileGenerator.h"
#else #else
#include "cmUnixMakefileGenerator.h" #include "cmUnixMakefileGenerator.h"
#endif #endif
@ -54,6 +55,7 @@ cmake::cmake()
m_Verbose = false; m_Verbose = false;
#if defined(_WIN32) && !defined(__CYGWIN__) #if defined(_WIN32) && !defined(__CYGWIN__)
cmMakefileGenerator::RegisterGenerator(new cmMSProjectGenerator); cmMakefileGenerator::RegisterGenerator(new cmMSProjectGenerator);
// cmMakefileGenerator::RegisterGenerator(new cmNMakeMakefileGenerator);
cmMakefileGenerator::RegisterGenerator(new cmBorlandMakefileGenerator); cmMakefileGenerator::RegisterGenerator(new cmBorlandMakefileGenerator);
#else #else
cmMakefileGenerator::RegisterGenerator(new cmUnixMakefileGenerator); cmMakefileGenerator::RegisterGenerator(new cmUnixMakefileGenerator);
@ -72,7 +74,7 @@ void cmake::Usage(const char* program)
for(std::vector<std::string>::iterator i =names.begin(); for(std::vector<std::string>::iterator i =names.begin();
i != names.end(); ++i) i != names.end(); ++i)
{ {
std::cerr << i->c_str() << " "; std::cerr << "\"" << i->c_str() << "\" ";
} }
std::cerr << ")\n"; std::cerr << ")\n";
} }

View File

@ -40,6 +40,7 @@ int main (int argc, char *argv[])
cmSystemTools::ChangeDirectory(binaryDirectory); cmSystemTools::ChangeDirectory(binaryDirectory);
cmake cm; cmake cm;
std::vector<std::string> args; std::vector<std::string> args;
// make sure the same generator is used
// use this program as the cmake to be run, it should not // use this program as the cmake to be run, it should not
// be run that way but the cmake object requires a vailid path // be run that way but the cmake object requires a vailid path
std::string cmakeCommand = CMAKE_COMMAND; std::string cmakeCommand = CMAKE_COMMAND;
@ -53,6 +54,10 @@ int main (int argc, char *argv[])
} }
args.push_back(cmakeCommand.c_str()); args.push_back(cmakeCommand.c_str());
args.push_back(sourceDirectory); args.push_back(sourceDirectory);
std::string generator = "-G";
generator += CMAKE_GENERATOR;
args.push_back(generator);
if (cm.Generate(args) != 0) if (cm.Generate(args) != 0)
{ {
std::cerr << "Error: cmake execution failed\n"; std::cerr << "Error: cmake execution failed\n";
@ -63,26 +68,33 @@ int main (int argc, char *argv[])
cmListFileCache::GetInstance()->ClearCache(); cmListFileCache::GetInstance()->ClearCache();
// now build the test // now build the test
std::string makeCommand = MAKEPROGRAM; std::string makeCommand = MAKEPROGRAM;
#if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__BORLANDC__) std::string lowerCaseCommand = makeCommand;
// if there are spaces in the makeCommand, assume a full path cmSystemTools::LowerCase(lowerCaseCommand);
// and convert it to a path with no spaces in it as the // if msdev is the make program then do the following
// RunCommand does not like spaces if(lowerCaseCommand.find("msdev") != std::string::npos)
if(makeCommand.find(' ') != std::string::npos)
{ {
char *buffer = new char[makeCommand.size()+1]; // if there are spaces in the makeCommand, assume a full path
if(GetShortPathName(makeCommand.c_str(), buffer, // and convert it to a path with no spaces in it as the
makeCommand.size()+1) != 0) // RunCommand does not like spaces
if(makeCommand.find(' ') != std::string::npos)
{ {
makeCommand = buffer; char *buffer = new char[makeCommand.size()+1];
delete [] buffer; if(GetShortPathName(makeCommand.c_str(), buffer,
makeCommand.size()+1) != 0)
{
makeCommand = buffer;
delete [] buffer;
}
} }
makeCommand += " ";
makeCommand += executableName;
makeCommand += ".dsw /MAKE \"ALL_BUILD - Debug\" /REBUILD";
}
else
{
// assume a make sytle program
makeCommand += " all";
} }
makeCommand += " ";
makeCommand += executableName;
makeCommand += ".dsw /MAKE \"ALL_BUILD - Debug\" /REBUILD";
#else
makeCommand += " all";
#endif
if (!cmSystemTools::RunCommand(makeCommand.c_str(), output)) if (!cmSystemTools::RunCommand(makeCommand.c_str(), output))
{ {
std::cerr << "Error: " << makeCommand.c_str() << " execution failed\n"; std::cerr << "Error: " << makeCommand.c_str() << " execution failed\n";

View File

@ -1,3 +1,3 @@
#define CMAKE_COMMAND "${CMAKE_COMMAND}" #define CMAKE_COMMAND "${CMAKE_COMMAND}"
#define MAKEPROGRAM "${MAKEPROGRAM}" #define MAKEPROGRAM "${MAKEPROGRAM}"
#define CMAKE_GENERATOR "${CMAKE_GENERATOR}"

View File

@ -6,8 +6,10 @@ SET (CMAKE_CXX_COMPILER cl CACHE FILEPATH
"Name of C++ compiler used.") "Name of C++ compiler used.")
SET (CMAKE_C_COMPILER cl CACHE FILEPATH SET (CMAKE_C_COMPILER cl CACHE FILEPATH
"Name of C compiler used.") "Name of C compiler used.")
SET (CMAKE_CFLAGS cl CACHE FILEPATH SET (CMAKE_CFLAGS "/W3 /Zm1000" CACHE STRING
"Flags for C compiler.") "Flags for C compiler.")
SET (CMAKE_BUILD_TYPE Debug CACHE STRING
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel")
SET (CMAKE_CXX_FLAGS_RELEASE "/MD /O2" CACHE STRING SET (CMAKE_CXX_FLAGS_RELEASE "/MD /O2" CACHE STRING
"Flags used by the compiler during release builds (/MD /Ob1 /Oi /Ot /Oy /Gs will produce slightly less optimized but smaller files)") "Flags used by the compiler during release builds (/MD /Ob1 /Oi /Ot /Oy /Gs will produce slightly less optimized but smaller files)")
SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MD /Zi /O2" CACHE STRING SET (CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MD /Zi /O2" CACHE STRING
@ -19,3 +21,9 @@ SET (CMAKE_CXX_FLAGS_DEBUG "/MDd /Zi /Od /GZ" CACHE STRING
SET (CMAKE_CXX_FLAGS "/W3 /Zm1000 /GX /GR" CACHE STRING SET (CMAKE_CXX_FLAGS "/W3 /Zm1000 /GX /GR" CACHE STRING
"Flags used by the compiler during all build types, /GX /GR are for exceptions and rtti in VC++, /Zm1000 increases the compiler's memory allocation to support ANSI C++/stdlib") "Flags used by the compiler during all build types, /GX /GR are for exceptions and rtti in VC++, /Zm1000 increases the compiler's memory allocation to support ANSI C++/stdlib")
SET (CMAKE_USE_WIN32_THREADS 1 CACHE BOOL "Use the win32 thread library") SET (CMAKE_USE_WIN32_THREADS 1 CACHE BOOL "Use the win32 thread library")
SET (CMAKE_STANDARD_WINDOWS_LIBRARIES "kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib" CACHE STRING "Libraries linked by defalut with all applications")
SET (CMAKE_SHLIB_SUFFIX ".dll" CACHE STRING "Shared library suffix")
SET (CMAKE_MODULE_SUFFIX ".dll" CACHE STRING "Module library suffix")