diff options
author | Morné Chamberlain <thefreeman.za@gmail.com> | 2012-11-11 20:10:21 (GMT) |
---|---|---|
committer | Morné Chamberlain <thefreeman.za@gmail.com> | 2012-11-11 20:10:21 (GMT) |
commit | 44c2eee8967860499a8b86baccd188799ad25966 (patch) | |
tree | 0062a2a988958e01fc1ba2f668c54686d2284eee /Source | |
parent | 304b885d365b5814838e3c595bc17342553d3b68 (diff) | |
parent | a23ac6bec6319de6c444fa29bb330bee5ca6cc5a (diff) | |
download | CMake-44c2eee8967860499a8b86baccd188799ad25966.zip CMake-44c2eee8967860499a8b86baccd188799ad25966.tar.gz CMake-44c2eee8967860499a8b86baccd188799ad25966.tar.bz2 |
Merge branch 'master' into sublime-text-2-generator
Diffstat (limited to 'Source')
34 files changed, 1895 insertions, 570 deletions
diff --git a/Source/CMakeVersion.cmake b/Source/CMakeVersion.cmake index 563b9aa..9009d44 100644 --- a/Source/CMakeVersion.cmake +++ b/Source/CMakeVersion.cmake @@ -2,5 +2,5 @@ set(CMake_VERSION_MAJOR 2) set(CMake_VERSION_MINOR 8) set(CMake_VERSION_PATCH 10) -set(CMake_VERSION_TWEAK 20121104) +set(CMake_VERSION_TWEAK 20121111) #set(CMake_VERSION_RC 1) diff --git a/Source/CPack/cmCPackDebGenerator.cxx b/Source/CPack/cmCPackDebGenerator.cxx index 4bd5d5c..f99db58 100644 --- a/Source/CPack/cmCPackDebGenerator.cxx +++ b/Source/CPack/cmCPackDebGenerator.cxx @@ -76,6 +76,11 @@ int cmCPackDebGenerator::PackageOnePack(std::string initialTopLevel, packageFileName.c_str()); // Tell CPackDeb.cmake the name of the component GROUP. this->SetOption("CPACK_DEB_PACKAGE_COMPONENT",packageName.c_str()); + // Tell CPackDeb.cmake the path where the component is. + std::string component_path = "/"; + component_path += packageName; + this->SetOption("CPACK_DEB_PACKAGE_COMPONENT_PART_PATH", + component_path.c_str()); if (!this->ReadListFile("CPackDeb.cmake")) { cmCPackLogger(cmCPackLog::LOG_ERROR, @@ -198,8 +203,11 @@ int cmCPackDebGenerator::PackageComponentsAllInOne() /* replace the TEMPORARY package file name */ this->SetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME", packageFileName.c_str()); - // Tell CPackDeb.cmake the name of the component GROUP. - this->SetOption("CPACK_DEB_PACKAGE_COMPONENT",compInstDirName.c_str()); + // Tell CPackDeb.cmake the path where the component is. + std::string component_path = "/"; + component_path += compInstDirName; + this->SetOption("CPACK_DEB_PACKAGE_COMPONENT_PART_PATH", + component_path.c_str()); if (!this->ReadListFile("CPackDeb.cmake")) { cmCPackLogger(cmCPackLog::LOG_ERROR, diff --git a/Source/CPack/cmCPackRPMGenerator.cxx b/Source/CPack/cmCPackRPMGenerator.cxx index 13aa6d8..66a4194 100644 --- a/Source/CPack/cmCPackRPMGenerator.cxx +++ b/Source/CPack/cmCPackRPMGenerator.cxx @@ -77,6 +77,11 @@ int cmCPackRPMGenerator::PackageOnePack(std::string initialToplevel, packageFileName.c_str()); // Tell CPackRPM.cmake the name of the component NAME. this->SetOption("CPACK_RPM_PACKAGE_COMPONENT",packageName.c_str()); + // Tell CPackRPM.cmake the path where the component is. + std::string component_path = "/"; + component_path += packageName; + this->SetOption("CPACK_RPM_PACKAGE_COMPONENT_PART_PATH", + component_path.c_str()); if (!this->ReadListFile("CPackRPM.cmake")) { cmCPackLogger(cmCPackLog::LOG_ERROR, @@ -178,8 +183,11 @@ int cmCPackRPMGenerator::PackageComponentsAllInOne() /* replace the TEMPORARY package file name */ this->SetOption("CPACK_TEMPORARY_PACKAGE_FILE_NAME", packageFileName.c_str()); - // Tell CPackRPM.cmake the name of the component GROUP. - this->SetOption("CPACK_RPM_PACKAGE_COMPONENT",compInstDirName.c_str()); + // Tell CPackRPM.cmake the path where the component is. + std::string component_path = "/"; + component_path += compInstDirName; + this->SetOption("CPACK_RPM_PACKAGE_COMPONENT_PART_PATH", + component_path.c_str()); if (!this->ReadListFile("CPackRPM.cmake")) { cmCPackLogger(cmCPackLog::LOG_ERROR, diff --git a/Source/CTest/cmCTestHandlerCommand.cxx b/Source/CTest/cmCTestHandlerCommand.cxx index 0da8aae..453e32c 100644 --- a/Source/CTest/cmCTestHandlerCommand.cxx +++ b/Source/CTest/cmCTestHandlerCommand.cxx @@ -121,7 +121,7 @@ bool cmCTestHandlerCommand } if ( this->Values[ct_SUBMIT_INDEX] ) { - if ( this->CTest->GetDartVersion() <= 1 ) + if(!this->CTest->GetDropSiteCDash() && this->CTest->GetDartVersion() <= 1) { cmCTestLog(this->CTest, ERROR_MESSAGE, "Dart before version 2.0 does not support collecting submissions." diff --git a/Source/cmAddCustomCommandCommand.h b/Source/cmAddCustomCommandCommand.h index c5252b7..1cc1e3a 100644 --- a/Source/cmAddCustomCommandCommand.h +++ b/Source/cmAddCustomCommandCommand.h @@ -68,7 +68,8 @@ public: " [COMMAND command2 [ARGS] [args2...] ...]\n" " [MAIN_DEPENDENCY depend]\n" " [DEPENDS [depends...]]\n" - " [IMPLICIT_DEPENDS <lang1> depend1 ...]\n" + " [IMPLICIT_DEPENDS <lang1> depend1\n" + " [<lang2> depend2] ...]\n" " [WORKING_DIRECTORY dir]\n" " [COMMENT comment] [VERBATIM] [APPEND])\n" "This defines a command to generate specified OUTPUT file(s). " @@ -142,6 +143,8 @@ public: "dependencies of an input file. The language given specifies the " "programming language whose corresponding dependency scanner should " "be used. Currently only C and CXX language scanners are supported. " + "The language has to be specified for every file in the " + "IMPLICIT_DEPENDS list. " "Dependencies discovered from the scanning are added to those of " "the custom command at build time. Note that the IMPLICIT_DEPENDS " "option is currently supported only for Makefile generators and " diff --git a/Source/cmCTest.cxx b/Source/cmCTest.cxx index a6d04b7..bb6f3f2 100644 --- a/Source/cmCTest.cxx +++ b/Source/cmCTest.cxx @@ -327,6 +327,7 @@ cmCTest::cmCTest() this->OutputLogFileLastTag = -1; this->SuppressUpdatingCTestConfiguration = false; this->DartVersion = 1; + this->DropSiteCDash = false; this->OutputTestOutputOnTestFailure = false; this->ComputedCompressTestOutput = false; this->ComputedCompressMemCheckOutput = false; @@ -653,6 +654,7 @@ bool cmCTest::InitializeFromCommand(cmCTestStartCommand* command) = this->GetCTestConfiguration("SourceDirectory").c_str(); std::string bld_dir = this->GetCTestConfiguration("BuildDirectory").c_str(); this->DartVersion = 1; + this->DropSiteCDash = false; for(Part p = PartStart; p != PartCount; p = Part(p+1)) { this->Parts[p].SubmitFiles.clear(); @@ -719,6 +721,7 @@ bool cmCTest::InitializeFromCommand(cmCTestStartCommand* command) return false; } } + this->DropSiteCDash = mf->IsOn("CTEST_DROP_SITE_CDASH"); if ( !this->Initialize(bld_dir.c_str(), command) ) { diff --git a/Source/cmCTest.h b/Source/cmCTest.h index f2638fe..587a6db 100644 --- a/Source/cmCTest.h +++ b/Source/cmCTest.h @@ -384,6 +384,7 @@ public: //! Get the version of dart server int GetDartVersion() { return this->DartVersion; } + int GetDropSiteCDash() { return this->DropSiteCDash; } //! Add file to be submitted void AddSubmitFile(Part part, const char* name); @@ -561,6 +562,7 @@ private: bool Quiet; int DartVersion; + bool DropSiteCDash; std::vector<cmStdString> InitialCommandLineArguments; diff --git a/Source/cmDepends.cxx b/Source/cmDepends.cxx index 166a584..74a0ccb 100644 --- a/Source/cmDepends.cxx +++ b/Source/cmDepends.cxx @@ -50,6 +50,7 @@ bool cmDepends::Write(std::ostream &makeDepends, std::vector<std::string> pairs; cmSystemTools::ExpandListArgument(srcStr, pairs); + std::map<std::string, std::set<std::string> > dependencies; for(std::vector<std::string>::iterator si = pairs.begin(); si != pairs.end();) { @@ -62,9 +63,14 @@ bool cmDepends::Write(std::ostream &makeDepends, obj = this->LocalGenerator->Convert(obj.c_str(), cmLocalGenerator::HOME_OUTPUT, cmLocalGenerator::MAKEFILE); + dependencies[obj].insert(src); + } + for(std::map<std::string, std::set<std::string> >::const_iterator + it = dependencies.begin(); it != dependencies.end(); ++it) + { // Write the dependencies for this pair. - if(!this->WriteDependencies(src.c_str(), obj.c_str(), + if(!this->WriteDependencies(it->second, it->first, makeDepends, internalDepends)) { return false; @@ -134,8 +140,9 @@ void cmDepends::Clear(const char *file) } //---------------------------------------------------------------------------- -bool cmDepends::WriteDependencies(const char*, const char*, - std::ostream&, std::ostream&) +bool cmDepends::WriteDependencies( + const std::set<std::string>&, const std::string&, + std::ostream&, std::ostream&) { // This should be implemented by the subclass. return false; @@ -174,8 +181,10 @@ bool cmDepends::CheckDependencies(std::istream& internalDepends, // kdelibs/khtml this reduces the number of calls from 184k down to 92k, // or the time for cmake -E cmake_depends from 0.3 s down to 0.21 s. dependerExists = cmSystemTools::FileExists(this->Depender); - DependencyVector tmp; - validDeps[this->Depender] = tmp; + // If we erase validDeps[this->Depender] by overwriting it with an empty + // vector, we lose dependencies for dependers that have multiple + // entries. No need to initialize the entry, std::map will do so on first + // access. currentDependencies = &validDeps[this->Depender]; continue; } diff --git a/Source/cmDepends.h b/Source/cmDepends.h index f7dc881..d787edd 100644 --- a/Source/cmDepends.h +++ b/Source/cmDepends.h @@ -76,8 +76,10 @@ protected: // Write dependencies for the target file to the given stream. // Return true for success and false for failure. - virtual bool WriteDependencies(const char *src, const char* obj, - std::ostream& makeDepends, std::ostream& internalDepends); + virtual bool WriteDependencies(const std::set<std::string>& sources, + const std::string& obj, + std::ostream& makeDepends, + std::ostream& internalDepends); // Check dependencies for the target file in the given stream. // Return false if dependencies must be regenerated and true diff --git a/Source/cmDependsC.cxx b/Source/cmDependsC.cxx index 44841a9..43b7b8a 100644 --- a/Source/cmDependsC.cxx +++ b/Source/cmDependsC.cxx @@ -98,176 +98,179 @@ cmDependsC::~cmDependsC() } //---------------------------------------------------------------------------- -bool cmDependsC::WriteDependencies(const char *src, const char *obj, - std::ostream& makeDepends, std::ostream& internalDepends) +bool cmDependsC::WriteDependencies(const std::set<std::string>& sources, + const std::string& obj, + std::ostream& makeDepends, + std::ostream& internalDepends) { // Make sure this is a scanning instance. - if(!src || src[0] == '\0') + if(sources.empty() || sources.begin()->empty()) { cmSystemTools::Error("Cannot scan dependencies without a source file."); return false; } - if(!obj || obj[0] == '\0') + if(obj.empty()) { cmSystemTools::Error("Cannot scan dependencies without an object file."); return false; } + std::set<cmStdString> dependencies; + bool haveDeps = false; + if (this->ValidDeps != 0) { std::map<std::string, DependencyVector>::const_iterator tmpIt = this->ValidDeps->find(obj); if (tmpIt!= this->ValidDeps->end()) { - // Write the dependencies to the output stream. Makefile rules - // written by the original local generator for this directory - // convert the dependencies to paths relative to the home output - // directory. We must do the same here. - internalDepends << obj << std::endl; for(DependencyVector::const_iterator i=tmpIt->second.begin(); i != tmpIt->second.end(); ++i) { - makeDepends << obj << ": " << - this->LocalGenerator->Convert(i->c_str(), - cmLocalGenerator::HOME_OUTPUT, - cmLocalGenerator::MAKEFILE) - << std::endl; - internalDepends << " " << i->c_str() << std::endl; + dependencies.insert(*i); } - makeDepends << std::endl; - return true; + haveDeps = true; } } - // Walk the dependency graph starting with the source file. - bool first = true; - UnscannedEntry root; - root.FileName = src; - this->Unscanned.push(root); - this->Encountered.clear(); - this->Encountered.insert(src); - std::set<cmStdString> dependencies; - std::set<cmStdString> scanned; + if (!haveDeps) + { + // Walk the dependency graph starting with the source file. + int srcFiles = (int)sources.size(); + this->Encountered.clear(); + + for(std::set<std::string>::const_iterator srcIt = sources.begin(); + srcIt != sources.end(); ++srcIt) + { + UnscannedEntry root; + root.FileName = *srcIt; + this->Unscanned.push(root); + this->Encountered.insert(*srcIt); + } - // Use reserve to allocate enough memory for tempPathStr - // so that during the loops no memory is allocated or freed - std::string tempPathStr; - tempPathStr.reserve(4*1024); + std::set<cmStdString> scanned; - while(!this->Unscanned.empty()) - { - // Get the next file to scan. - UnscannedEntry current = this->Unscanned.front(); - this->Unscanned.pop(); + // Use reserve to allocate enough memory for tempPathStr + // so that during the loops no memory is allocated or freed + std::string tempPathStr; + tempPathStr.reserve(4*1024); - // If not a full path, find the file in the include path. - std::string fullName; - if(first || cmSystemTools::FileIsFullPath(current.FileName.c_str())) + while(!this->Unscanned.empty()) { - if(cmSystemTools::FileExists(current.FileName.c_str(), true)) + // Get the next file to scan. + UnscannedEntry current = this->Unscanned.front(); + this->Unscanned.pop(); + + // If not a full path, find the file in the include path. + std::string fullName; + if((srcFiles>0) + || cmSystemTools::FileIsFullPath(current.FileName.c_str())) { - fullName = current.FileName; + if(cmSystemTools::FileExists(current.FileName.c_str(), true)) + { + fullName = current.FileName; + } } - } - else if(!current.QuotedLocation.empty() && - cmSystemTools::FileExists(current.QuotedLocation.c_str(), true)) - { - // The include statement producing this entry was a double-quote - // include and the included file is present in the directory of - // the source containing the include statement. - fullName = current.QuotedLocation; - } - else - { - std::map<cmStdString, cmStdString>::iterator - headerLocationIt=this->HeaderLocationCache.find(current.FileName); - if (headerLocationIt!=this->HeaderLocationCache.end()) + else if(!current.QuotedLocation.empty() && + cmSystemTools::FileExists(current.QuotedLocation.c_str(), true)) { - fullName=headerLocationIt->second; + // The include statement producing this entry was a double-quote + // include and the included file is present in the directory of + // the source containing the include statement. + fullName = current.QuotedLocation; } - else for(std::vector<std::string>::const_iterator i = - this->IncludePath.begin(); i != this->IncludePath.end(); ++i) + else { - // Construct the name of the file as if it were in the current - // include directory. Avoid using a leading "./". - - tempPathStr = ""; - if((*i) == ".") + std::map<cmStdString, cmStdString>::iterator + headerLocationIt=this->HeaderLocationCache.find(current.FileName); + if (headerLocationIt!=this->HeaderLocationCache.end()) { - tempPathStr += current.FileName; + fullName=headerLocationIt->second; } - else + else for(std::vector<std::string>::const_iterator i = + this->IncludePath.begin(); i != this->IncludePath.end(); ++i) { - tempPathStr += *i; - tempPathStr+="/"; - tempPathStr+=current.FileName; - } + // Construct the name of the file as if it were in the current + // include directory. Avoid using a leading "./". - // Look for the file in this location. - if(cmSystemTools::FileExists(tempPathStr.c_str(), true)) - { - fullName = tempPathStr; - HeaderLocationCache[current.FileName]=fullName; - break; + tempPathStr = ""; + if((*i) == ".") + { + tempPathStr += current.FileName; + } + else + { + tempPathStr += *i; + tempPathStr+="/"; + tempPathStr+=current.FileName; + } + + // Look for the file in this location. + if(cmSystemTools::FileExists(tempPathStr.c_str(), true)) + { + fullName = tempPathStr; + HeaderLocationCache[current.FileName]=fullName; + break; + } } } - } - - // Complain if the file cannot be found and matches the complain - // regex. - if(fullName.empty() && - this->IncludeRegexComplain.find(current.FileName.c_str())) - { - cmSystemTools::Error("Cannot find file \"", - current.FileName.c_str(), "\"."); - return false; - } - // Scan the file if it was found and has not been scanned already. - if(!fullName.empty() && (scanned.find(fullName) == scanned.end())) - { - // Record scanned files. - scanned.insert(fullName); + // Complain if the file cannot be found and matches the complain + // regex. + if(fullName.empty() && + this->IncludeRegexComplain.find(current.FileName.c_str())) + { + cmSystemTools::Error("Cannot find file \"", + current.FileName.c_str(), "\"."); + return false; + } - // Check whether this file is already in the cache - std::map<cmStdString, cmIncludeLines*>::iterator fileIt= - this->FileCache.find(fullName); - if (fileIt!=this->FileCache.end()) + // Scan the file if it was found and has not been scanned already. + if(!fullName.empty() && (scanned.find(fullName) == scanned.end())) { - fileIt->second->Used=true; - dependencies.insert(fullName); - for (std::vector<UnscannedEntry>::const_iterator incIt= - fileIt->second->UnscannedEntries.begin(); - incIt!=fileIt->second->UnscannedEntries.end(); ++incIt) + // Record scanned files. + scanned.insert(fullName); + + // Check whether this file is already in the cache + std::map<cmStdString, cmIncludeLines*>::iterator fileIt= + this->FileCache.find(fullName); + if (fileIt!=this->FileCache.end()) { - if (this->Encountered.find(incIt->FileName) == - this->Encountered.end()) + fileIt->second->Used=true; + dependencies.insert(fullName); + for (std::vector<UnscannedEntry>::const_iterator incIt= + fileIt->second->UnscannedEntries.begin(); + incIt!=fileIt->second->UnscannedEntries.end(); ++incIt) { - this->Encountered.insert(incIt->FileName); - this->Unscanned.push(*incIt); + if (this->Encountered.find(incIt->FileName) == + this->Encountered.end()) + { + this->Encountered.insert(incIt->FileName); + this->Unscanned.push(*incIt); + } } } - } - else - { - - // Try to scan the file. Just leave it out if we cannot find - // it. - std::ifstream fin(fullName.c_str()); - if(fin) + else { - // Add this file as a dependency. - dependencies.insert(fullName); - // Scan this file for new dependencies. Pass the directory - // containing the file to handle double-quote includes. - std::string dir = cmSystemTools::GetFilenamePath(fullName); - this->Scan(fin, dir.c_str(), fullName); + // Try to scan the file. Just leave it out if we cannot find + // it. + std::ifstream fin(fullName.c_str()); + if(fin) + { + // Add this file as a dependency. + dependencies.insert(fullName); + + // Scan this file for new dependencies. Pass the directory + // containing the file to handle double-quote includes. + std::string dir = cmSystemTools::GetFilenamePath(fullName); + this->Scan(fin, dir.c_str(), fullName); + } } } - } - first = false; + srcFiles--; + } } // Write the dependencies to the output stream. Makefile rules @@ -275,7 +278,7 @@ bool cmDependsC::WriteDependencies(const char *src, const char *obj, // convert the dependencies to paths relative to the home output // directory. We must do the same here. internalDepends << obj << std::endl; - for(std::set<cmStdString>::iterator i=dependencies.begin(); + for(std::set<cmStdString>::const_iterator i=dependencies.begin(); i != dependencies.end(); ++i) { makeDepends << obj << ": " << diff --git a/Source/cmDependsC.h b/Source/cmDependsC.h index bd9a4b7..16dfad7 100644 --- a/Source/cmDependsC.h +++ b/Source/cmDependsC.h @@ -32,11 +32,9 @@ public: virtual ~cmDependsC(); protected: - typedef std::vector<char> t_CharBuffer; - // Implement writing/checking methods required by superclass. - virtual bool WriteDependencies(const char *src, - const char *file, + virtual bool WriteDependencies(const std::set<std::string>& sources, + const std::string& obj, std::ostream& makeDepends, std::ostream& internalDepends); @@ -82,7 +80,6 @@ protected: const std::map<std::string, DependencyVector>* ValidDeps; std::set<cmStdString> Encountered; std::queue<UnscannedEntry> Unscanned; - t_CharBuffer Buffer; std::map<cmStdString, cmIncludeLines *> FileCache; std::map<cmStdString, cmStdString> HeaderLocationCache; diff --git a/Source/cmDependsFortran.cxx b/Source/cmDependsFortran.cxx index 3e66058..e41e5ea 100644 --- a/Source/cmDependsFortran.cxx +++ b/Source/cmDependsFortran.cxx @@ -170,44 +170,50 @@ cmDependsFortran::~cmDependsFortran() } //---------------------------------------------------------------------------- -bool cmDependsFortran::WriteDependencies(const char *src, const char *obj, - std::ostream&, std::ostream&) +bool cmDependsFortran::WriteDependencies( + const std::set<std::string>& sources, const std::string& obj, + std::ostream&, std::ostream&) { // Make sure this is a scanning instance. - if(!src || src[0] == '\0') + if(sources.empty() || sources.begin()->empty()) { - cmSystemTools::Error("Cannot scan dependencies without an source file."); + cmSystemTools::Error("Cannot scan dependencies without a source file."); return false; } - if(!obj || obj[0] == '\0') + if(obj.empty()) { cmSystemTools::Error("Cannot scan dependencies without an object file."); return false; } - // Get the information object for this source. - cmDependsFortranSourceInfo& info = - this->Internal->CreateObjectInfo(obj, src); + bool okay = true; + for(std::set<std::string>::const_iterator it = sources.begin(); + it != sources.end(); ++it) + { + const std::string& src = *it; + // Get the information object for this source. + cmDependsFortranSourceInfo& info = + this->Internal->CreateObjectInfo(obj.c_str(), src.c_str()); - // Make a copy of the macros defined via ADD_DEFINITIONS - std::set<std::string> ppDefines(this->PPDefinitions.begin(), - this->PPDefinitions.end()); + // Make a copy of the macros defined via ADD_DEFINITIONS + std::set<std::string> ppDefines(this->PPDefinitions.begin(), + this->PPDefinitions.end()); - // Create the parser object. The constructor takes ppMacro and info per - // reference, so we may look into the resulting objects later. - cmDependsFortranParser parser(this, ppDefines, info); + // Create the parser object. The constructor takes ppMacro and info per + // reference, so we may look into the resulting objects later. + cmDependsFortranParser parser(this, ppDefines, info); - // Push on the starting file. - cmDependsFortranParser_FilePush(&parser, src); + // Push on the starting file. + cmDependsFortranParser_FilePush(&parser, src.c_str()); - // Parse the translation unit. - if(cmDependsFortran_yyparse(parser.Scanner) != 0) - { - // Failed to parse the file. Report failure to write dependencies. - return false; + // Parse the translation unit. + if(cmDependsFortran_yyparse(parser.Scanner) != 0) + { + // Failed to parse the file. Report failure to write dependencies. + okay = false; + } } - - return true; + return okay; } //---------------------------------------------------------------------------- diff --git a/Source/cmDependsFortran.h b/Source/cmDependsFortran.h index cdfde6e..cb40796 100644 --- a/Source/cmDependsFortran.h +++ b/Source/cmDependsFortran.h @@ -66,7 +66,7 @@ protected: // Implement writing/checking methods required by superclass. virtual bool WriteDependencies( - const char *src, const char *file, + const std::set<std::string>& sources, const std::string& file, std::ostream& makeDepends, std::ostream& internalDepends); // Actually write the depenencies to the streams. diff --git a/Source/cmDependsJava.cxx b/Source/cmDependsJava.cxx index ba0e8fb..949d465 100644 --- a/Source/cmDependsJava.cxx +++ b/Source/cmDependsJava.cxx @@ -25,11 +25,11 @@ cmDependsJava::~cmDependsJava() } //---------------------------------------------------------------------------- -bool cmDependsJava::WriteDependencies(const char *src, const char *, - std::ostream&, std::ostream&) +bool cmDependsJava::WriteDependencies(const std::set<std::string>& sources, + const std::string&, std::ostream&, std::ostream&) { // Make sure this is a scanning instance. - if(!src || src[0] == '\0') + if(sources.empty() || sources.begin()->empty()) { cmSystemTools::Error("Cannot scan dependencies without an source file."); return false; diff --git a/Source/cmDependsJava.h b/Source/cmDependsJava.h index bf7e234..22af53f 100644 --- a/Source/cmDependsJava.h +++ b/Source/cmDependsJava.h @@ -29,7 +29,8 @@ public: protected: // Implement writing/checking methods required by superclass. - virtual bool WriteDependencies(const char *src, const char *file, + virtual bool WriteDependencies( + const std::set<std::string>& sources, const std::string& file, std::ostream& makeDepends, std::ostream& internalDepends); virtual bool CheckDependencies(std::istream& internalDepends, const char* internalDependsFileName, diff --git a/Source/cmDocumentation.cxx b/Source/cmDocumentation.cxx index c1360ef..debde3b 100644 --- a/Source/cmDocumentation.cxx +++ b/Source/cmDocumentation.cxx @@ -155,7 +155,7 @@ static const char *cmDocumentationStandardSeeAlso[][3] = static const char *cmDocumentationCopyright[][3] = { {0, - "Copyright 2000-2009 Kitware, Inc., Insight Software Consortium. " + "Copyright 2000-2012 Kitware, Inc., Insight Software Consortium. " "All rights reserved.", 0}, {0, "Redistribution and use in source and binary forms, with or without " diff --git a/Source/cmExtraEclipseCDT4Generator.cxx b/Source/cmExtraEclipseCDT4Generator.cxx index 7464657..97ab086 100644 --- a/Source/cmExtraEclipseCDT4Generator.cxx +++ b/Source/cmExtraEclipseCDT4Generator.cxx @@ -592,7 +592,8 @@ void cmExtraEclipseCDT4Generator::CreateLinksToSubprojects( this->GetEclipsePath(linkSourceDirectory), LinkToFolder ); - this->SrcLinkedResources.push_back(it->first); + // Don't add it to the srcLinkedResources, because listing multiple + // directories confuses the Eclipse indexer (#13596). } } } @@ -743,15 +744,16 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const /* I don't know what the pathentry kind="src" are good for, e.g. autocompletion * works also without them. Done wrong, the indexer complains, see #12417 * and #12213. + * According to #13596, this entry at least limits the directories the + * indexer is searching for files. So now the "src" entry contains only + * the linked resource to CMAKE_SOURCE_DIR. * The CDT documentation is very terse on that: * "CDT_SOURCE: Entry kind constant describing a path entry identifying a * folder containing source code to be compiled." * Also on the cdt-dev list didn't bring any information: * http://web.archiveorange.com/archive/v/B4NlJDNIpYoOS1SbxFNy - * So I'm disabling them for now, hoping that somebody will report if something - * is not workging anymore. * Alex */ -#ifdef DO_CREATE_SRC_PATH_ENTRIES + for (std::vector<std::string>::const_iterator it = this->SrcLinkedResources.begin(); it != this->SrcLinkedResources.end(); @@ -768,7 +770,7 @@ void cmExtraEclipseCDT4Generator::CreateCProjectFile() const excludeFromOut += this->EscapeForXML(*it) + "/|"; } } -#endif + excludeFromOut += "**/CMakeFiles/"; fout << "<pathentry excluding=\"" << excludeFromOut << "\" kind=\"out\" path=\"\"/>\n"; diff --git a/Source/cmFileCommand.cxx b/Source/cmFileCommand.cxx index 8de24b3..b877f3c 100644 --- a/Source/cmFileCommand.cxx +++ b/Source/cmFileCommand.cxx @@ -22,6 +22,7 @@ #endif #undef GetCurrentDirectory +#include <assert.h> #include <sys/types.h> #include <sys/stat.h> @@ -705,11 +706,8 @@ bool cmFileCommand::HandleStringsCommand(std::vector<std::string> const& args) bool cmFileCommand::HandleGlobCommand(std::vector<std::string> const& args, bool recurse) { - if ( args.size() < 2 ) - { - this->SetError("GLOB requires at least a variable name"); - return false; - } + // File commands has at least one argument + assert(args.size() > 1); std::vector<std::string>::const_iterator i = args.begin(); @@ -843,11 +841,8 @@ bool cmFileCommand::HandleGlobCommand(std::vector<std::string> const& args, bool cmFileCommand::HandleMakeDirectoryCommand( std::vector<std::string> const& args) { - if(args.size() < 2 ) - { - this->SetError("called with incorrect number of arguments"); - return false; - } + // File command has at least one argument + assert(args.size() > 1); std::vector<std::string>::const_iterator i = args.begin(); diff --git a/Source/cmGeneratorExpressionEvaluator.cxx b/Source/cmGeneratorExpressionEvaluator.cxx index ee1b60a..2e123a4 100644 --- a/Source/cmGeneratorExpressionEvaluator.cxx +++ b/Source/cmGeneratorExpressionEvaluator.cxx @@ -16,6 +16,8 @@ #include "cmGeneratorExpressionDAGChecker.h" #include "cmGeneratorExpression.h" +#include <cmsys/String.h> + //---------------------------------------------------------------------------- #if !defined(__SUNPRO_CC) || __SUNPRO_CC > 0x510 static @@ -253,7 +255,8 @@ static const struct ConfigurationTestNode : public cmGeneratorExpressionNode return parameters.front().empty() ? "1" : "0"; } - return *parameters.begin() == context->Config ? "1" : "0"; + return cmsysString_strcasecmp(parameters.begin()->c_str(), + context->Config) == 0 ? "1" : "0"; } } configurationTestNode; diff --git a/Source/cmGlobalVisualStudio7Generator.cxx b/Source/cmGlobalVisualStudio7Generator.cxx index b6eea5d..15ef738 100644 --- a/Source/cmGlobalVisualStudio7Generator.cxx +++ b/Source/cmGlobalVisualStudio7Generator.cxx @@ -268,6 +268,8 @@ void cmGlobalVisualStudio7Generator::WriteTargetsToSolution( cmLocalGenerator* root, OrderedTargetDependSet const& projectTargets) { + VisualStudioFolders.clear(); + for(OrderedTargetDependSet::const_iterator tt = projectTargets.begin(); tt != projectTargets.end(); ++tt) { diff --git a/Source/cmListCommand.cxx b/Source/cmListCommand.cxx index 7848424..df64695 100644 --- a/Source/cmListCommand.cxx +++ b/Source/cmListCommand.cxx @@ -15,13 +15,14 @@ #include <stdlib.h> // required for atoi #include <ctype.h> +#include <assert.h> //---------------------------------------------------------------------------- bool cmListCommand ::InitialPass(std::vector<std::string> const& args, cmExecutionStatus &) { - if(args.size() < 1) + if(args.size() < 2) { - this->SetError("must be called with at least one argument."); + this->SetError("must be called with at least two arguments."); return false; } @@ -243,11 +244,7 @@ bool cmListCommand::HandleGetCommand(std::vector<std::string> const& args) //---------------------------------------------------------------------------- bool cmListCommand::HandleAppendCommand(std::vector<std::string> const& args) { - if(args.size() < 2) - { - this->SetError("sub-command APPEND requires at least one argument."); - return false; - } + assert(args.size() >= 2); // Skip if nothing to append. if(args.size() < 3) @@ -424,12 +421,8 @@ bool cmListCommand bool cmListCommand ::HandleReverseCommand(std::vector<std::string> const& args) { - if(args.size() < 2) - { - this->SetError("sub-command REVERSE requires a list as an argument."); - return false; - } - else if(args.size() > 2) + assert(args.size() >= 2); + if(args.size() > 2) { this->SetError( "sub-command REVERSE only takes one argument."); @@ -463,13 +456,8 @@ bool cmListCommand bool cmListCommand ::HandleRemoveDuplicatesCommand(std::vector<std::string> const& args) { - if(args.size() < 2) - { - this->SetError( - "sub-command REMOVE_DUPLICATES requires a list as an argument."); - return false; - } - else if(args.size() > 2) + assert(args.size() >= 2); + if(args.size() > 2) { this->SetError( "sub-command REMOVE_DUPLICATES only takes one argument."); @@ -513,12 +501,8 @@ bool cmListCommand bool cmListCommand ::HandleSortCommand(std::vector<std::string> const& args) { - if(args.size() < 2) - { - this->SetError("sub-command SORT requires a list as an argument."); - return false; - } - else if(args.size() > 2) + assert(args.size() >= 2); + if(args.size() > 2) { this->SetError( "sub-command SORT only takes one argument."); diff --git a/Source/cmLocalUnixMakefileGenerator3.cxx b/Source/cmLocalUnixMakefileGenerator3.cxx index db93529..820d25a 100644 --- a/Source/cmLocalUnixMakefileGenerator3.cxx +++ b/Source/cmLocalUnixMakefileGenerator3.cxx @@ -1939,8 +1939,12 @@ void cmLocalUnixMakefileGenerator3 for(ImplicitDependFileMap::const_iterator pi = implicitPairs.begin(); pi != implicitPairs.end(); ++pi) { - cmakefileStream << " \"" << pi->second << "\" "; - cmakefileStream << "\"" << pi->first << "\"\n"; + for(cmDepends::DependencyVector::const_iterator di = pi->second.begin(); + di != pi->second.end(); ++ di) + { + cmakefileStream << " \"" << *di << "\" "; + cmakefileStream << "\"" << pi->first << "\"\n"; + } } cmakefileStream << " )\n"; @@ -2204,7 +2208,7 @@ cmLocalUnixMakefileGenerator3::AddImplicitDepends(cmTarget const& tgt, const char* obj, const char* src) { - this->ImplicitDepends[tgt.GetName()][lang][obj] = src; + this->ImplicitDepends[tgt.GetName()][lang][obj].push_back(src); } //---------------------------------------------------------------------------- diff --git a/Source/cmLocalUnixMakefileGenerator3.h b/Source/cmLocalUnixMakefileGenerator3.h index e374959..703369e 100644 --- a/Source/cmLocalUnixMakefileGenerator3.h +++ b/Source/cmLocalUnixMakefileGenerator3.h @@ -209,7 +209,8 @@ public: // File pairs for implicit dependency scanning. The key of the map // is the depender and the value is the explicit dependee. - struct ImplicitDependFileMap: public std::map<cmStdString, cmStdString> {}; + struct ImplicitDependFileMap: + public std::map<cmStdString, cmDepends::DependencyVector> {}; struct ImplicitDependLanguageMap: public std::map<cmStdString, ImplicitDependFileMap> {}; struct ImplicitDependTargetMap: diff --git a/Source/cmTarget.cxx b/Source/cmTarget.cxx index 423b350..f3eb52b 100644 --- a/Source/cmTarget.cxx +++ b/Source/cmTarget.cxx @@ -2584,7 +2584,10 @@ cmTarget::OutputInfo const* cmTarget::GetOutputInfo(const char* config) OutputInfo info; this->ComputeOutputDir(config, false, info.OutDir); this->ComputeOutputDir(config, true, info.ImpDir); - this->ComputePDBOutputDir(config, info.PdbDir); + if(!this->ComputePDBOutputDir(config, info.PdbDir)) + { + info.PdbDir = info.OutDir; + } OutputInfoMapType::value_type entry(config_upper, info); i = this->Internal->OutputInfoMap.insert(entry).first; } @@ -3940,7 +3943,7 @@ bool cmTarget::ComputeOutputDir(const char* config, } //---------------------------------------------------------------------------- -void cmTarget::ComputePDBOutputDir(const char* config, std::string& out) +bool cmTarget::ComputePDBOutputDir(const char* config, std::string& out) { // Look for a target property defining the target output directory // based on the target type. @@ -3980,8 +3983,7 @@ void cmTarget::ComputePDBOutputDir(const char* config, std::string& out) } if(out.empty()) { - // Default to the current output directory. - out = "."; + return false; } // Convert the output path to a full path in case it is @@ -3996,6 +3998,7 @@ void cmTarget::ComputePDBOutputDir(const char* config, std::string& out) this->Makefile->GetLocalGenerator()->GetGlobalGenerator()-> AppendDirectoryForConfig("/", config, "", out); } + return true; } //---------------------------------------------------------------------------- diff --git a/Source/cmTarget.h b/Source/cmTarget.h index 558bfab..e442d25 100644 --- a/Source/cmTarget.h +++ b/Source/cmTarget.h @@ -577,7 +577,7 @@ private: struct OutputInfo; OutputInfo const* GetOutputInfo(const char* config); bool ComputeOutputDir(const char* config, bool implib, std::string& out); - void ComputePDBOutputDir(const char* config, std::string& out); + bool ComputePDBOutputDir(const char* config, std::string& out); // Cache import information from properties for each configuration. struct ImportInfo; diff --git a/Source/kwsys/CMakeLists.txt b/Source/kwsys/CMakeLists.txt index a132357..777d76f 100644 --- a/Source/kwsys/CMakeLists.txt +++ b/Source/kwsys/CMakeLists.txt @@ -509,19 +509,28 @@ ENDIF(KWSYS_USE_FundamentalType) IF(KWSYS_USE_IOStream) # Determine whether iostreams support long long. + SET(KWSYS_PLATFORM_CXX_TEST_DEFINES + -DKWSYS_IOS_USE_ANSI=${KWSYS_IOS_USE_ANSI} + -DKWSYS_IOS_HAVE_STD=${KWSYS_IOS_HAVE_STD}) IF(KWSYS_CXX_HAS_LONG_LONG) - SET(KWSYS_PLATFORM_CXX_TEST_DEFINES - -DKWSYS_IOS_USE_ANSI=${KWSYS_IOS_USE_ANSI} - -DKWSYS_IOS_HAVE_STD=${KWSYS_IOS_HAVE_STD}) KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_HAS_ISTREAM_LONG_LONG "Checking if istream supports long long" DIRECT) KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_HAS_OSTREAM_LONG_LONG "Checking if ostream supports long long" DIRECT) - SET(KWSYS_PLATFORM_CXX_TEST_DEFINES) ELSE() SET(KWSYS_IOS_HAS_ISTREAM_LONG_LONG 0) SET(KWSYS_IOS_HAS_OSTREAM_LONG_LONG 0) ENDIF() + IF(KWSYS_CXX_HAS___INT64) + KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_HAS_ISTREAM___INT64 + "Checking if istream supports __int64" DIRECT) + KWSYS_PLATFORM_CXX_TEST(KWSYS_IOS_HAS_OSTREAM___INT64 + "Checking if ostream supports __int64" DIRECT) + ELSE() + SET(KWSYS_IOS_HAS_ISTREAM___INT64 0) + SET(KWSYS_IOS_HAS_OSTREAM___INT64 0) + ENDIF() + SET(KWSYS_PLATFORM_CXX_TEST_DEFINES) ENDIF(KWSYS_USE_IOStream) IF(KWSYS_NAMESPACE MATCHES "^kwsys$") @@ -566,9 +575,76 @@ IF(KWSYS_USE_SystemTools) ENDIF() IF(KWSYS_USE_SystemInformation) - SET_PROPERTY(SOURCE SystemInformation.cxx PROPERTY - COMPILE_DEFINITIONS KWSYS_USE_LONG_LONG=${KWSYS_USE_LONG_LONG} - KWSYS_USE___INT64=${KWSYS_USE___INT64}) + IF(NOT CYGWIN) + INCLUDE(CheckIncludeFiles) + CHECK_INCLUDE_FILES("sys/types.h;ifaddrs.h" KWSYS_SYS_HAS_IFADDRS_H) + IF(KWSYS_SYS_HAS_IFADDRS_H) + SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY + COMPILE_DEFINITIONS KWSYS_SYS_HAS_IFADDRS_H=1) + ENDIF() + ENDIF() + IF(WIN32) + INCLUDE(CheckSymbolExists) + SET(CMAKE_REQUIRED_LIBRARIES Psapi) + CHECK_SYMBOL_EXISTS(GetProcessMemoryInfo "windows.h;psapi.h" KWSYS_SYS_HAS_PSAPI) + UNSET(CMAKE_REQUIRED_LIBRARIES) + IF(KWSYS_SYS_HAS_PSAPI) + SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY + COMPILE_DEFINITIONS KWSYS_SYS_HAS_PSAPI=1) + IF(MSVC70 OR MSVC71) + # Suppress LNK4089: all references to 'PSAPI.DLL' discarded by /OPT:REF + SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /IGNORE:4089") + ENDIF() + ENDIF() + ENDIF() + IF(KWSYS_LFS_AVAILABLE AND NOT KWSYS_LFS_DISABLE) + SET(KWSYS_PLATFORM_CXX_TEST_DEFINES -DKWSYS_HAS_LFS=1) + ENDIF() + KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_RLIMIT64 + "Checking whether CXX compiler has rlimit64" DIRECT) + SET(KWSYS_PLATFORM_CXX_TEST_DEFINES) + IF(KWSYS_CXX_HAS_RLIMIT64) + SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY + COMPILE_DEFINITIONS KWSYS_CXX_HAS_RLIMIT64=1) + ENDIF() + KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_ATOL + "Checking whether CXX compiler has atol" DIRECT) + IF(KWSYS_CXX_HAS_ATOL) + SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY + COMPILE_DEFINITIONS KWSYS_CXX_HAS_ATOL=1) + ENDIF() + KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_ATOLL + "Checking whether CXX compiler has atoll" DIRECT) + IF(KWSYS_CXX_HAS_ATOLL) + SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY + COMPILE_DEFINITIONS KWSYS_CXX_HAS_ATOLL=1) + ENDIF() + KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS__ATOI64 + "Checking whether CXX compiler has _atoi64" DIRECT) + IF(KWSYS_CXX_HAS__ATOI64) + SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY + COMPILE_DEFINITIONS KWSYS_CXX_HAS__ATOI64=1) + ENDIF() + IF(KWSYS_USE___INT64) + SET_PROPERTY(SOURCE SystemInformation.cxx testSystemInformation.cxx APPEND PROPERTY + COMPILE_DEFINITIONS KWSYS_USE___INT64=1) + ENDIF() + IF(KWSYS_USE_LONG_LONG) + SET_PROPERTY(SOURCE SystemInformation.cxx testSystemInformation.cxx APPEND PROPERTY + COMPILE_DEFINITIONS KWSYS_USE_LONG_LONG=1) + ENDIF() + IF(KWSYS_IOS_HAS_OSTREAM_LONG_LONG) + SET_PROPERTY(SOURCE SystemInformation.cxx testSystemInformation.cxx APPEND PROPERTY + COMPILE_DEFINITIONS KWSYS_IOS_HAS_OSTREAM_LONG_LONG=1) + ENDIF() + IF(KWSYS_IOS_HAS_OSTREAM___INT64) + SET_PROPERTY(SOURCE SystemInformation.cxx testSystemInformation.cxx APPEND PROPERTY + COMPILE_DEFINITIONS KWSYS_IOS_HAS_OSTREAM___INT64=1) + ENDIF() + IF(KWSYS_BUILD_SHARED) + SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY + COMPILE_DEFINITIONS KWSYS_BUILD_SHARED=1) + ENDIF() ENDIF() #----------------------------------------------------------------------------- @@ -802,9 +878,12 @@ IF(KWSYS_C_SRCS OR KWSYS_CXX_SRCS) TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} ${CMAKE_DL_LIBS}) ENDIF(UNIX) ENDIF(KWSYS_USE_DynamicLoader) - + IF(KWSYS_USE_SystemInformation AND WIN32) TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} ws2_32) + IF(KWSYS_SYS_HAS_PSAPI) + TARGET_LINK_LIBRARIES(${KWSYS_NAMESPACE} Psapi) + ENDIF() ENDIF(KWSYS_USE_SystemInformation AND WIN32) # Apply user-defined target properties to the library. @@ -842,6 +921,16 @@ ENDIF(KWSYS_ENABLE_C AND KWSYS_C_SRCS) # line to configure the namespace in the C and C++ source files. ADD_DEFINITIONS("-DKWSYS_NAMESPACE=${KWSYS_NAMESPACE}") +# Disable deprecation warnings for standard C functions. +IF(MSVC OR (WIN32 AND "${CMAKE_C_COMPILER_ID}" MATCHES "^(Intel)$")) + ADD_DEFINITIONS( + -D_CRT_NONSTDC_NO_DEPRECATE + -D_CRT_SECURE_NO_DEPRECATE + -D_CRT_SECURE_NO_WARNINGS + -D_SCL_SECURE_NO_DEPRECATE + ) +ENDIF() + IF(KWSYS_USE_String) # Activate code in "String.c". See the comment in the source. SET_SOURCE_FILES_PROPERTIES(String.c PROPERTIES diff --git a/Source/kwsys/CTestConfig.cmake b/Source/kwsys/CTestConfig.cmake index 9ab6ed8..d977b47 100644 --- a/Source/kwsys/CTestConfig.cmake +++ b/Source/kwsys/CTestConfig.cmake @@ -1,6 +1,6 @@ #============================================================================= # KWSys - Kitware System Library -# Copyright 2000-2009 Kitware, Inc., Insight Software Consortium +# Copyright 2000-2012 Kitware, Inc., Insight Software Consortium # # Distributed under the OSI-approved BSD License (the "License"); # see accompanying file Copyright.txt for details. @@ -9,10 +9,9 @@ # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # See the License for more information. #============================================================================= -set (CTEST_PROJECT_NAME "kwsys") -set (CTEST_NIGHTLY_START_TIME "21:00:00 EDT") -set (CTEST_DART_SERVER_VERSION "2") +set(CTEST_PROJECT_NAME "KWSys") +set(CTEST_NIGHTLY_START_TIME "21:00:00 EDT") set(CTEST_DROP_METHOD "http") -set(CTEST_DROP_SITE "www.cdash.org") -set(CTEST_DROP_LOCATION "/CDash/submit.php?project=PublicDashboard") +set(CTEST_DROP_SITE "open.cdash.org") +set(CTEST_DROP_LOCATION "/submit.php?project=PublicDashboard") set(CTEST_DROP_SITE_CDASH TRUE) diff --git a/Source/kwsys/Configure.h.in b/Source/kwsys/Configure.h.in index 15986cf..70cf844 100644 --- a/Source/kwsys/Configure.h.in +++ b/Source/kwsys/Configure.h.in @@ -37,20 +37,6 @@ /* Whether kwsys namespace is "kwsys". */ #define @KWSYS_NAMESPACE@_NAME_IS_KWSYS @KWSYS_NAME_IS_KWSYS@ -/* If we are building a kwsys .c or .cxx file, suppress the Microsoft - deprecation warnings. */ -#if defined(KWSYS_NAMESPACE) -# ifndef _CRT_NONSTDC_NO_DEPRECATE -# define _CRT_NONSTDC_NO_DEPRECATE -# endif -# ifndef _CRT_SECURE_NO_DEPRECATE -# define _CRT_SECURE_NO_DEPRECATE -# endif -# ifndef _SCL_SECURE_NO_DEPRECATE -# define _SCL_SECURE_NO_DEPRECATE -# endif -#endif - /* Whether Large File Support is requested. */ #define @KWSYS_NAMESPACE@_LFS_REQUESTED @KWSYS_LFS_REQUESTED@ diff --git a/Source/kwsys/ProcessUNIX.c b/Source/kwsys/ProcessUNIX.c index 9c66a44..1992211 100644 --- a/Source/kwsys/ProcessUNIX.c +++ b/Source/kwsys/ProcessUNIX.c @@ -2732,6 +2732,7 @@ static void kwsysProcessesSignalHandler(int signum kwsysProcess* cp = kwsysProcesses.Processes[i]; kwsysProcess_ssize_t status= read(cp->PipeReadEnds[KWSYSPE_PIPE_SIGNAL], &buf, 1); + (void)status; status=write(cp->SignalPipe, &buf, 1); (void)status; } diff --git a/Source/kwsys/SystemInformation.cxx b/Source/kwsys/SystemInformation.cxx index e1ee873..6b63b94 100644 --- a/Source/kwsys/SystemInformation.cxx +++ b/Source/kwsys/SystemInformation.cxx @@ -9,7 +9,12 @@ implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License for more information. ============================================================================*/ -#ifdef _WIN32 + +#if defined(_WIN32) +# define NOMINMAX // use our min,max +# if !defined(_WIN32_WINNT) && !(defined(_MSC_VER) && _MSC_VER < 1300) +# define _WIN32_WINNT 0x0501 +# endif # include <winsock.h> // WSADATA, include before sys/types.h #endif @@ -33,6 +38,7 @@ #include KWSYS_HEADER(Process.h) #include KWSYS_HEADER(ios/iostream) #include KWSYS_HEADER(ios/sstream) +#include KWSYS_HEADER(ios/fstream) // Work-around CMake dependency scanning limitation. This must // duplicate the above list of headers. @@ -45,66 +51,142 @@ # include "kwsys_stl_iosfwd.in" # include "kwsys_ios_sstream.h.in" # include "kwsys_ios_iostream.h.in" +# include "kwsys_ios_fstream.h.in" #endif -#ifndef WIN32 +#if defined(_WIN32) +# include <windows.h> +# include <errno.h> +# if defined(KWSYS_SYS_HAS_PSAPI) +# include <psapi.h> +# endif +# if !defined(siginfo_t) +typedef int siginfo_t; +# endif +#else +# include <sys/types.h> +# include <sys/time.h> # include <sys/utsname.h> // int uname(struct utsname *buf); +# include <sys/resource.h> // getrlimit +# include <unistd.h> +# include <signal.h> +# include <fcntl.h> +# include <errno.h> // extern int errno; #endif -#ifdef _WIN32 -# include <windows.h> +#ifdef __FreeBSD__ +# include <sys/sysctl.h> +# include <fenv.h> +# include <sys/socket.h> +# include <netdb.h> +# include <netinet/in.h> +# if defined(KWSYS_SYS_HAS_IFADDRS_H) +# include <ifaddrs.h> +# define KWSYS_SYSTEMINFORMATION_IMPLEMENT_FQDN +# endif #endif #ifdef __APPLE__ -#include <sys/sysctl.h> -#include <mach/vm_statistics.h> -#include <mach/host_info.h> -#include <mach/mach.h> -#include <mach/mach_types.h> +# include <sys/sysctl.h> +# include <mach/vm_statistics.h> +# include <mach/host_info.h> +# include <mach/mach.h> +# include <mach/mach_types.h> +# include <fenv.h> +# include <sys/socket.h> +# include <netdb.h> +# include <netinet/in.h> +# if defined(KWSYS_SYS_HAS_IFADDRS_H) +# include <ifaddrs.h> +# define KWSYS_SYSTEMINFORMATION_IMPLEMENT_FQDN +# endif +# if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__-0 >= 1050 +# include <execinfo.h> +# define KWSYS_SYSTEMINFORMATION_HAVE_BACKTRACE +# endif #endif #ifdef __linux -# include <sys/types.h> -# include <unistd.h> -# include <fcntl.h> -# include <ctype.h> // int isdigit(int c); -# include <errno.h> // extern int errno; -# include <sys/time.h> +# include <fenv.h> +# include <sys/socket.h> +# include <netdb.h> +# include <netinet/in.h> +# if defined(KWSYS_SYS_HAS_IFADDRS_H) +# include <ifaddrs.h> +# if !defined(__LSB_VERSION__) /* LSB has no getifaddrs */ +# define KWSYS_SYSTEMINFORMATION_IMPLEMENT_FQDN +# endif +# endif +# if defined(__GNUG__) +# include <execinfo.h> +# if !(defined(__LSB_VERSION__) && __LSB_VERSION__ < 41) +# define KWSYS_SYSTEMINFORMATION_HAVE_BACKTRACE +# endif +# endif +# if defined(KWSYS_CXX_HAS_RLIMIT64) +typedef struct rlimit64 ResourceLimitType; +# define GetResourceLimit getrlimit64 +# else +typedef struct rlimit ResourceLimitType; +# define GetResourceLimit getrlimit +# endif #elif defined( __hpux ) # include <sys/param.h> # include <sys/pstat.h> #endif #ifdef __HAIKU__ -#include <OS.h> +# include <OS.h> #endif #include <memory.h> #include <stdlib.h> #include <stdio.h> #include <string.h> +#include <ctype.h> // int isdigit(int c); + +#if defined(KWSYS_USE_LONG_LONG) +# if defined(KWSYS_IOS_HAS_OSTREAM_LONG_LONG) +# define iostreamLongLong(x) (x) +# else +# define iostreamLongLong(x) ((long)x) +# endif +#elif defined(KWSYS_USE___INT64) +# if defined(KWSYS_IOS_HAS_OSTREAM___INT64) +# define iostreamLongLong(x) (x) +# else +# define iostreamLongLong(x) ((long)x) +# endif +#else +# error "No Long Long" +#endif +#if defined(KWSYS_CXX_HAS_ATOLL) +# define atoLongLong atoll +#else +# if defined(KWSYS_CXX_HAS__ATOI64) +# define atoLongLong _atoi64 +# elif defined(KWSYS_CXX_HAS_ATOL) +# define atoLongLong atol +# else +# define atoLongLong atoi +# endif +#endif namespace KWSYS_NAMESPACE { +template<typename T> +T min(T a, T b){ return a<b ? a : b; } -// Create longlong -#if KWSYS_USE_LONG_LONG - typedef long long LongLong; -#elif KWSYS_USE___INT64 - typedef __int64 LongLong; -#else -# error "No Long Long" -#endif - +extern "C" { typedef void (*SigAction)(int,siginfo_t*,void*); } // Define SystemInformationImplementation class typedef void (*DELAY_FUNC)(unsigned int uiMS); - class SystemInformationImplementation { public: + typedef SystemInformation::LongLong LongLong; SystemInformationImplementation (); ~SystemInformationImplementation (); @@ -113,6 +195,7 @@ public: kwsys_stl::string GetTypeID(); kwsys_stl::string GetFamilyID(); kwsys_stl::string GetModelID(); + kwsys_stl::string GetModelName(); kwsys_stl::string GetSteppingCode(); const char * GetExtendedProcessorName(); const char * GetProcessorSerialNumber(); @@ -122,9 +205,10 @@ public: int GetProcessorAPICID(); int GetProcessorCacheXSize(long int); bool DoesCPUSupportFeature(long int); - + const char * GetOSName(); const char * GetHostname(); + int GetFullyQualifiedDomainName(kwsys_stl::string &fqdn); const char * GetOSRelease(); const char * GetOSVersion(); const char * GetOSPlatform(); @@ -140,7 +224,23 @@ public: size_t GetTotalVirtualMemory(); size_t GetAvailableVirtualMemory(); size_t GetTotalPhysicalMemory(); - size_t GetAvailablePhysicalMemory(); + size_t GetAvailablePhysicalMemory(); + + LongLong GetProcessId(); + + // Retrieve memory information in kib + LongLong GetHostMemoryTotal(); + LongLong GetHostMemoryAvailable(const char *envVarName); + LongLong GetHostMemoryUsed(); + + LongLong GetProcMemoryAvailable( + const char *hostLimitEnvVarName, + const char *procLimitEnvVarName); + LongLong GetProcMemoryUsed(); + + // enable/disable stack trace signal handler. + static + void SetStackTraceOnError(int enable); /** Run the different checks */ void RunCPUCheck(); @@ -159,6 +259,7 @@ public: kwsys_stl::string ProcessorName; kwsys_stl::string Vendor; kwsys_stl::string SerialNumber; + kwsys_stl::string ModelName; } ID; typedef struct tagCPUPowerManagement @@ -249,7 +350,7 @@ protected: // For Mac bool ParseSysCtl(); - void CallSwVers(); + int CallSwVers(const char *arg, kwsys_stl::string &ver); void TrimNewline(kwsys_stl::string&); kwsys_stl::string ExtractValueFromSysCtl(const char* word); kwsys_stl::string SysCtlBuffer; @@ -281,7 +382,7 @@ protected: kwsys_stl::string Hostname; kwsys_stl::string OSRelease; kwsys_stl::string OSVersion; - kwsys_stl::string OSPlatform; + kwsys_stl::string OSPlatform; }; @@ -320,6 +421,11 @@ kwsys_stl::string SystemInformation::GetModelID() return this->Implementation->GetModelID(); } +kwsys_stl::string SystemInformation::GetModelName() +{ + return this->Implementation->GetModelName(); +} + kwsys_stl::string SystemInformation::GetSteppingCode() { return this->Implementation->GetSteppingCode(); @@ -365,6 +471,37 @@ bool SystemInformation::DoesCPUSupportFeature(long int i) return this->Implementation->DoesCPUSupportFeature(i); } +kwsys_stl::string SystemInformation::GetCPUDescription() +{ + kwsys_ios::ostringstream oss; + oss + << this->GetNumberOfPhysicalCPU() + << " core "; + if (this->GetModelName().empty()) + { + oss + << this->GetProcessorClockFrequency() + << " MHz " + << this->GetVendorString() + << " " + << this->GetExtendedProcessorName(); + } + else + { + oss << this->GetModelName(); + } + + // remove extra spaces + kwsys_stl::string tmp=oss.str(); + size_t pos; + while( (pos=tmp.find(" "))!=kwsys_stl::string::npos) + { + tmp.replace(pos,2," "); + } + + return tmp; +} + const char * SystemInformation::GetOSName() { return this->Implementation->GetOSName(); @@ -375,6 +512,13 @@ const char * SystemInformation::GetHostname() return this->Implementation->GetHostname(); } +kwsys_stl::string SystemInformation::GetFullyQualifiedDomainName() +{ + kwsys_stl::string fqdn; + this->Implementation->GetFullyQualifiedDomainName(fqdn); + return fqdn; +} + const char * SystemInformation::GetOSRelease() { return this->Implementation->GetOSRelease(); @@ -390,6 +534,46 @@ const char * SystemInformation::GetOSPlatform() return this->Implementation->GetOSPlatform(); } +int SystemInformation::GetOSIsWindows() +{ +#if defined(_WIN32) + return 1; +#else + return 0; +#endif +} + +int SystemInformation::GetOSIsLinux() +{ +#if defined(__linux) + return 1; +#else + return 0; +#endif +} + +int SystemInformation::GetOSIsApple() +{ +#if defined(__APPLE__) + return 1; +#else + return 0; +#endif +} + +kwsys_stl::string SystemInformation::GetOSDescription() +{ + kwsys_ios::ostringstream oss; + oss + << this->GetOSName() + << " " + << this->GetOSRelease() + << " " + << this->GetOSVersion(); + + return oss.str(); +} + bool SystemInformation::Is64Bits() { return this->Implementation->Is64Bits(); @@ -431,6 +615,66 @@ size_t SystemInformation::GetAvailablePhysicalMemory() return this->Implementation->GetAvailablePhysicalMemory(); } +kwsys_stl::string SystemInformation::GetMemoryDescription( + const char *hostLimitEnvVarName, + const char *procLimitEnvVarName) +{ + kwsys_ios::ostringstream oss; + oss + << "Host Total: " + << iostreamLongLong(this->GetHostMemoryTotal()) + << " KiB, Host Available: " + << iostreamLongLong(this->GetHostMemoryAvailable(hostLimitEnvVarName)) + << " KiB, Process Available: " + << iostreamLongLong( + this->GetProcMemoryAvailable(hostLimitEnvVarName,procLimitEnvVarName)) + << " KiB"; + return oss.str(); +} + +// host memory info in units of KiB. +SystemInformation::LongLong SystemInformation::GetHostMemoryTotal() +{ + return this->Implementation->GetHostMemoryTotal(); +} + +SystemInformation::LongLong +SystemInformation::GetHostMemoryAvailable(const char *hostLimitEnvVarName) +{ + return this->Implementation->GetHostMemoryAvailable(hostLimitEnvVarName); +} + +SystemInformation::LongLong SystemInformation::GetHostMemoryUsed() +{ + return this->Implementation->GetHostMemoryUsed(); +} + +// process memory info in units of KiB. +SystemInformation::LongLong +SystemInformation::GetProcMemoryAvailable( + const char *hostLimitEnvVarName, + const char *procLimitEnvVarName) +{ + return this->Implementation->GetProcMemoryAvailable( + hostLimitEnvVarName, + procLimitEnvVarName); +} + +SystemInformation::LongLong SystemInformation::GetProcMemoryUsed() +{ + return this->Implementation->GetProcMemoryUsed(); +} + +SystemInformation::LongLong SystemInformation::GetProcessId() +{ + return this->Implementation->GetProcessId(); +} + +void SystemInformation::SetStackTraceOnError(int enable) +{ + SystemInformationImplementation::SetStackTraceOnError(enable); +} + /** Run the different checks */ void SystemInformation::RunCPUCheck() { @@ -501,22 +745,365 @@ void SystemInformation::RunMemoryCheck() #define HT_CANNOT_DETECT 4 // EDX[28] Bit 28 is set if HT is supported -#define HT_BIT 0x10000000 +#define HT_BIT 0x10000000 // EAX[11:8] Bit 8-11 contains family processor ID. #define FAMILY_ID 0x0F00 -#define PENTIUM4_ID 0x0F00 +#define PENTIUM4_ID 0x0F00 // EAX[23:20] Bit 20-23 contains extended family processor ID -#define EXT_FAMILY_ID 0x0F00000 +#define EXT_FAMILY_ID 0x0F00000 // EBX[23:16] Bit 16-23 in ebx contains the number of logical -#define NUM_LOGICAL_BITS 0x00FF0000 -// processors per physical processor when execute cpuid with +#define NUM_LOGICAL_BITS 0x00FF0000 +// processors per physical processor when execute cpuid with // eax set to 1 -// EBX[31:24] Bits 24-31 (8 bits) return the 8-bit unique -#define INITIAL_APIC_ID_BITS 0xFF000000 +// EBX[31:24] Bits 24-31 (8 bits) return the 8-bit unique +#define INITIAL_APIC_ID_BITS 0xFF000000 // initial APIC ID for the processor this code is running on. // Default value = 0xff if HT is not supported +// Hide implementation details in an anonymous namespace. +namespace { +// ***************************************************************************** +#if defined(__linux) || defined(__APPLE__) +int LoadLines( + FILE *file, + kwsys_stl::vector<kwsys_stl::string> &lines) +{ + // Load each line in the given file into a the vector. + int nRead=0; + const int bufSize=1024; + char buf[bufSize]={'\0'}; + while (!feof(file) && !ferror(file)) + { + errno=0; + if (fgets(buf,bufSize,file) == 0) + { + if (ferror(file) && (errno==EINTR)) + { + clearerr(file); + } + continue; + } + lines.push_back(buf); + ++nRead; + } + if (ferror(file)) + { + return 0; + } + return nRead; +} + +# if defined(__linux) +// ***************************************************************************** +int LoadLines( + const char *fileName, + kwsys_stl::vector<kwsys_stl::string> &lines) +{ + FILE *file=fopen(fileName,"r"); + if (file==0) + { + return 0; + } + int nRead=LoadLines(file,lines); + fclose(file); + return nRead; +} +# endif + +// **************************************************************************** +template<typename T> +int NameValue( + kwsys_stl::vector<kwsys_stl::string> &lines, + kwsys_stl::string name, T &value) +{ + size_t nLines=lines.size(); + for (size_t i=0; i<nLines; ++i) + { + size_t at=lines[i].find(name); + if (at==kwsys_stl::string::npos) + { + continue; + } + kwsys_ios::istringstream is(lines[i].substr(at+name.size())); + is >> value; + return 0; + } + return -1; +} +#endif + +#if defined(__linux) +// **************************************************************************** +template<typename T> +int GetFieldsFromFile( + const char *fileName, + const char **fieldNames, + T *values) +{ + kwsys_stl::vector<kwsys_stl::string> fields; + if (!LoadLines(fileName,fields)) + { + return -1; + } + int i=0; + while (fieldNames[i]!=NULL) + { + int ierr=NameValue(fields,fieldNames[i],values[i]); + if (ierr) + { + return -(i+2); + } + i+=1; + } + return 0; +} + +// **************************************************************************** +template<typename T> +int GetFieldFromFile( + const char *fileName, + const char *fieldName, + T &value) +{ + const char *fieldNames[2]={fieldName,NULL}; + T values[1]={T(0)}; + int ierr=GetFieldsFromFile(fileName,fieldNames,values); + if (ierr) + { + return ierr; + } + value=values[0]; + return 0; +} +#endif + +// **************************************************************************** +#if defined(__APPLE__) +template<typename T> +int GetFieldsFromCommand( + const char *command, + const char **fieldNames, + T *values) +{ + FILE *file=popen(command,"r"); + if (file==0) + { + return -1; + } + kwsys_stl::vector<kwsys_stl::string> fields; + int nl=LoadLines(file,fields); + pclose(file); + if (nl==0) + { + return -1; + } + int i=0; + while (fieldNames[i]!=NULL) + { + int ierr=NameValue(fields,fieldNames[i],values[i]); + if (ierr) + { + return -(i+2); + } + i+=1; + } + return 0; +} +#endif + +// **************************************************************************** +#if !defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) +void StacktraceSignalHandler( + int sigNo, + siginfo_t *sigInfo, + void * /*sigContext*/) +{ +#if defined(__linux) || defined(__APPLE__) + kwsys_ios::ostringstream oss; + oss + << "=========================================================" << kwsys_ios::endl + << "Process id " << getpid() << " "; + switch (sigNo) + { + case SIGFPE: + oss << "Caught SIGFPE "; + switch (sigInfo->si_code) + { +# if defined(FPE_INTDIV) + case FPE_INTDIV: + oss << "integer division by zero"; + break; +# endif + +# if defined(FPE_INTOVF) + case FPE_INTOVF: + oss << "integer overflow"; + break; +# endif + + case FPE_FLTDIV: + oss << "floating point divide by zero"; + break; + + case FPE_FLTOVF: + oss << "floating point overflow"; + break; + + case FPE_FLTUND: + oss << "floating point underflow"; + break; + + case FPE_FLTRES: + oss << "floating point inexact result"; + break; + + case FPE_FLTINV: + oss << "floating point invalid operation"; + break; + +#if defined(FPE_FLTSUB) + case FPE_FLTSUB: + oss << "floating point subscript out of range"; + break; +#endif + + default: + oss << "code " << sigInfo->si_code; + break; + } + break; + + case SIGSEGV: + oss << "Caught SIGSEGV "; + switch (sigInfo->si_code) + { + case SEGV_MAPERR: + oss << "address not mapped to object"; + break; + + case SEGV_ACCERR: + oss << "invalid permission for mapped object"; + break; + + default: + oss << "code " << sigInfo->si_code; + break; + } + break; + + case SIGINT: + oss << "Caught SIGTERM"; + break; + + case SIGTERM: + oss << "Caught SIGTERM"; + break; + + case SIGBUS: + oss << "Caught SIGBUS type "; + switch (sigInfo->si_code) + { + case BUS_ADRALN: + oss << "invalid address alignment"; + break; + +# if defined(BUS_ADRERR) + case BUS_ADRERR: + oss << "non-exestent physical address"; + break; +# endif + +# if defined(BUS_OBJERR) + case BUS_OBJERR: + oss << "object specific hardware error"; + break; +# endif + + default: + oss << "code " << sigInfo->si_code; + break; + } + break; + + case SIGILL: + oss << "Caught SIGILL "; + switch (sigInfo->si_code) + { + case ILL_ILLOPC: + oss << "illegal opcode"; + break; + +# if defined(ILL_ILLOPN) + case ILL_ILLOPN: + oss << "illegal operand"; + break; +# endif + +# if defined(ILL_ILLADR) + case ILL_ILLADR: + oss << "illegal addressing mode."; + break; +# endif + + case ILL_ILLTRP: + oss << "illegal trap"; + + case ILL_PRVOPC: + oss << "privileged opcode"; + break; + +# if defined(ILL_PRVREG) + case ILL_PRVREG: + oss << "privileged register"; + break; +# endif + +# if defined(ILL_COPROC) + case ILL_COPROC: + oss << "co-processor error"; + break; +# endif + +# if defined(ILL_BADSTK) + case ILL_BADSTK: + oss << "internal stack error"; + break; +# endif + + default: + oss << "code " << sigInfo->si_code; + break; + } + break; + + default: + oss << "Caught " << sigNo << " code " << sigInfo->si_code; + break; + } + oss << kwsys_ios::endl; +#if defined(KWSYS_SYSTEMINFORMATION_HAVE_BACKTRACE) + oss << "Program Stack:" << kwsys_ios::endl; + void *stackSymbols[128]; + int n=backtrace(stackSymbols,128); + char **stackText=backtrace_symbols(stackSymbols,n); + for (int i=0; i<n; ++i) + { + oss << " " << stackText[i] << kwsys_ios::endl; + } +#endif + oss + << "=========================================================" << kwsys_ios::endl; + kwsys_ios::cerr << oss.str() << kwsys_ios::endl; + abort(); +#else + // avoid warning C4100 + (void)sigNo; + (void)sigInfo; +#endif +} +#endif +} // anonymous namespace SystemInformationImplementation::SystemInformationImplementation() { @@ -573,13 +1160,13 @@ void SystemInformationImplementation::RunCPUCheck() if (supportsCPUID) { // Retrieve cache information. - if (!RetrieveCPUCacheDetails()) + if (!RetrieveCPUCacheDetails()) { RetrieveClassicalCPUCacheDetails(); } // Retrieve the extended CPU details. - if (!RetrieveExtendedCPUIdentity()) + if (!RetrieveExtendedCPUIdentity()) { RetrieveClassicalCPUIdentity(); } @@ -641,9 +1228,145 @@ const char * SystemInformationImplementation::GetOSName() /** Get the hostname */ const char* SystemInformationImplementation::GetHostname() { + if (this->Hostname.empty()) + { + this->Hostname="localhost"; +#if defined(_WIN32) + WORD wVersionRequested; + WSADATA wsaData; + char name[255]; + wVersionRequested = MAKEWORD(2,0); + if ( WSAStartup( wVersionRequested, &wsaData ) == 0 ) + { + gethostname(name,sizeof(name)); + WSACleanup( ); + } + this->Hostname = name; +#else + struct utsname unameInfo; + int errorFlag = uname(&unameInfo); + if(errorFlag == 0) + { + this->Hostname = unameInfo.nodename; + } +#endif + } return this->Hostname.c_str(); } +/** Get the FQDN */ +int SystemInformationImplementation::GetFullyQualifiedDomainName( + kwsys_stl::string &fqdn) +{ + // in the event of absolute failure return localhost. + fqdn="localhost"; + +#if defined(_WIN32) + int ierr; + // TODO - a more robust implementation for windows, see comments + // in unix implementation. + WSADATA wsaData; + WORD ver=MAKEWORD(2,0); + ierr=WSAStartup(ver,&wsaData); + if (ierr) + { + return -1; + } + + char base[256]={'\0'}; + ierr=gethostname(base,256); + if (ierr) + { + WSACleanup(); + return -2; + } + fqdn=base; + + HOSTENT *hent=gethostbyname(base); + if (hent) + { + fqdn=hent->h_name; + } + + WSACleanup(); + return 0; + +#elif defined(KWSYS_SYSTEMINFORMATION_IMPLEMENT_FQDN) + // gethostname typical returns an alias for loopback interface + // we want the fully qualified domain name. Because there are + // any number of interfaces on this system we look for the + // first of these that contains the name returned by gethostname + // and is longer. failing that we return gethostname and indicate + // with a failure code. Return of a failure code is not necessarilly + // an indication of an error. for instance gethostname may return + // the fully qualified domain name, or there may not be one if the + // system lives on a private network such as in the case of a cluster + // node. + + int ierr=0; + char base[NI_MAXHOST]; + ierr=gethostname(base,NI_MAXHOST); + if (ierr) + { + return -1; + } + size_t baseSize=strlen(base); + fqdn=base; + + struct ifaddrs *ifas; + struct ifaddrs *ifa; + ierr=getifaddrs(&ifas); + if (ierr) + { + return -2; + } + + for (ifa=ifas; ifa!=NULL; ifa=ifa->ifa_next) + { + int fam=ifa->ifa_addr->sa_family; + if ((fam==AF_INET) || (fam==AF_INET6)) + { + char host[NI_MAXHOST]={'\0'}; + + int addrlen + = (fam==AF_INET?sizeof(struct sockaddr_in):sizeof(struct sockaddr_in6)); + + ierr=getnameinfo( + ifa->ifa_addr, + addrlen, + host, + NI_MAXHOST, + NULL, + 0, + NI_NAMEREQD); + if (ierr) + { + // don't report the failure now since we may succeed on another + // interface. If all attempts fail then return the failure code. + ierr=-3; + continue; + } + + kwsys_stl::string candidate=host; + if ((candidate.find(base)!=kwsys_stl::string::npos) && baseSize<candidate.size()) + { + // success, stop now. + ierr=0; + fqdn=candidate; + break; + } + } + } + freeifaddrs(ifas); + + return ierr; +#else + /* TODO: Implement on more platforms. */ + fqdn=this->GetHostname(); + return -1; +#endif +} + /** Get the OS release */ const char* SystemInformationImplementation::GetOSRelease() { @@ -721,9 +1444,15 @@ kwsys_stl::string SystemInformationImplementation::GetModelID() return str.str(); } +// Return the model name of CPU present */ +kwsys_stl::string SystemInformationImplementation::GetModelName() +{ + return this->ChipID.ModelName; +} + /** Return the stepping code of the CPU present. */ kwsys_stl::string SystemInformationImplementation::GetSteppingCode() -{ +{ kwsys_ios::ostringstream str; str << this->ChipID.Revision; return str.str(); @@ -734,8 +1463,8 @@ const char * SystemInformationImplementation::GetExtendedProcessorName() { return this->ChipID.ProcessorName.c_str(); } - -/** Return the serial number of the processor + +/** Return the serial number of the processor * in hexadecimal: xxxx-xxxx-xxxx-xxxx-xxxx-xxxx. */ const char * SystemInformationImplementation::GetProcessorSerialNumber() { @@ -870,7 +1599,7 @@ void SystemInformationImplementation::Delay(unsigned int uiMS) QueryPerformanceCounter (&StartCounter); do { - // Get the ending position of the counter. + // Get the ending position of the counter. QueryPerformanceCounter (&EndCounter); } while (EndCounter.QuadPart - StartCounter.QuadPart < x); #endif @@ -893,7 +1622,7 @@ bool SystemInformationImplementation::DoesCPUSupportCPUID() push ecx push edx #endif - ; <<CPUID>> + ; <<CPUID>> mov eax, 0 CPUID_INSTRUCTION @@ -905,7 +1634,7 @@ bool SystemInformationImplementation::DoesCPUSupportCPUID() #endif } } - __except(1) + __except(1) { // Stop the class from trying to use CPUID again! return false; @@ -939,7 +1668,7 @@ bool SystemInformationImplementation::RetrieveCPUFeatures() push ecx push edx #endif - ; <<CPUID>> + ; <<CPUID>> ; eax = 1 --> eax: CPU ID - bits 31..16 - unused, bits 15..12 - type, bits 11..8 - family, bits 7..4 - model, bits 3..0 - mask revision ; ebx: 31..24 - default APIC ID, 23..16 - logical processsor ID, 15..8 - CFLUSH chunk size , 7..0 - brand ID ; edx: CPU feature flags @@ -956,7 +1685,7 @@ bool SystemInformationImplementation::RetrieveCPUFeatures() #endif } } - __except(1) + __except(1) { return false; } @@ -977,39 +1706,39 @@ bool SystemInformationImplementation::RetrieveCPUFeatures() // Retrieve extended SSE capabilities if SSE is available. if (this->Features.HasSSE) { - + // Attempt to __try some SSE FP instructions. - __try + __try { // Perform: orps xmm0, xmm0 - _asm + _asm { _emit 0x0f _emit 0x56 - _emit 0xc0 + _emit 0xc0 } // SSE FP capable processor. this->Features.HasSSEFP = true; - } - __except(1) + } + __except(1) { // bad instruction - processor or OS cannot handle SSE FP. this->Features.HasSSEFP = false; } - } - else + } + else { // Set the advanced SSE capabilities to not available. this->Features.HasSSEFP = false; } // Retrieve Intel specific extended features. - if (this->ChipManufacturer == Intel) + if (this->ChipManufacturer == Intel) { this->Features.ExtendedFeatures.SupportsHyperthreading = ((localCPUFeatures & 0x10000000) != 0); // Intel specific: Hyperthreading --> Bit 28 this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical = (this->Features.ExtendedFeatures.SupportsHyperthreading) ? ((localCPUAdvanced & 0x00FF0000) >> 16) : 1; - + if ((this->Features.ExtendedFeatures.SupportsHyperthreading) && (this->Features.HasAPIC)) { // Retrieve APIC information if there is one present. @@ -1054,9 +1783,9 @@ bool SystemInformationImplementation::RetrieveCPUIdentity() int localCPUSignature; // Use assembly to detect CPUID information... - __try + __try { - _asm + _asm { #ifdef CPUID_AWARE_COMPILER ; we must push/pop the registers <<CPUID>> writes to, as the @@ -1078,7 +1807,7 @@ bool SystemInformationImplementation::RetrieveCPUIdentity() mov localCPUVendor[1 * TYPE int], edx mov localCPUVendor[2 * TYPE int], ecx - ; <<CPUID>> + ; <<CPUID>> ; eax = 1 --> eax: CPU ID - bits 31..16 - unused, bits 15..12 - type, bits 11..8 - family, bits 7..4 - model, bits 3..0 - mask revision ; ebx: 31..24 - default APIC ID, 23..16 - logical processsor ID, 15..8 - CFLUSH chunk size , 7..0 - brand ID ; edx: CPU feature flags @@ -1094,7 +1823,7 @@ bool SystemInformationImplementation::RetrieveCPUIdentity() #endif } } - __except(1) + __except(1) { return false; } @@ -1133,12 +1862,12 @@ bool SystemInformationImplementation::RetrieveCPUCacheDetails() int L2Cache[4] = { 0, 0, 0, 0 }; // Check to see if what we are about to do is supported... - if (RetrieveCPUExtendedLevelSupport (0x80000005)) + if (RetrieveCPUExtendedLevelSupport (0x80000005)) { // Use assembly to retrieve the L1 cache information ... - __try + __try { - _asm + _asm { #ifdef CPUID_AWARE_COMPILER ; we must push/pop the registers <<CPUID>> writes to, as the @@ -1169,27 +1898,27 @@ bool SystemInformationImplementation::RetrieveCPUCacheDetails() #endif } } - __except(1) + __except(1) { return false; } // Save the L1 data cache size (in KB) from ecx: bits 31..24 as well as data cache size from edx: bits 31..24. this->Features.L1CacheSize = ((L1Cache[2] & 0xFF000000) >> 24); this->Features.L1CacheSize += ((L1Cache[3] & 0xFF000000) >> 24); - } - else + } + else { // Store -1 to indicate the cache could not be queried. this->Features.L1CacheSize = -1; } // Check to see if what we are about to do is supported... - if (RetrieveCPUExtendedLevelSupport (0x80000006)) + if (RetrieveCPUExtendedLevelSupport (0x80000006)) { // Use assembly to retrieve the L2 cache information ... - __try + __try { - _asm + _asm { #ifdef CPUID_AWARE_COMPILER ; we must push/pop the registers <<CPUID>> writes to, as the @@ -1220,19 +1949,19 @@ bool SystemInformationImplementation::RetrieveCPUCacheDetails() #endif } } - __except(1) + __except(1) { return false; } // Save the L2 unified cache size (in KB) from ecx: bits 31..16. this->Features.L2CacheSize = ((L2Cache[2] & 0xFFFF0000) >> 16); - } + } else { // Store -1 to indicate the cache could not be queried. this->Features.L2CacheSize = -1; } - + // Define L3 as being not present as we cannot test for it. this->Features.L3CacheSize = -1; @@ -1294,10 +2023,10 @@ bool SystemInformationImplementation::RetrieveClassicalCPUCacheDetails() int bob = ((TLBCacheData[0] & 0x00FF0000) >> 16); (void)bob; // Process the returned TLB and cache information. - for (int nCounter = 0; nCounter < TLBCACHE_INFO_UNITS; nCounter ++) + for (int nCounter = 0; nCounter < TLBCACHE_INFO_UNITS; nCounter ++) { // First of all - decide which unit we are dealing with. - switch (nCounter) + switch (nCounter) { // eax: bits 8..15 : bits 16..23 : bits 24..31 case 0: TLBCacheUnit = ((TLBCacheData[0] & 0x0000FF00) >> 8); break; @@ -1327,7 +2056,7 @@ bool SystemInformationImplementation::RetrieveClassicalCPUCacheDetails() } // Now process the resulting unit to see what it means.... - switch (TLBCacheUnit) + switch (TLBCacheUnit) { case 0x00: break; case 0x01: STORE_TLBCACHE_INFO (TLBCode, 4); break; @@ -1383,7 +2112,7 @@ bool SystemInformationImplementation::RetrieveClassicalCPUCacheDetails() case 0x90: STORE_TLBCACHE_INFO (TLBCode, 262144); break; // <-- FIXME: IA-64 Only case 0x96: STORE_TLBCACHE_INFO (TLBCode, 262144); break; // <-- FIXME: IA-64 Only case 0x9b: STORE_TLBCACHE_INFO (TLBCode, 262144); break; // <-- FIXME: IA-64 Only - + // Default case - an error has occured. default: return false; } @@ -1394,47 +2123,47 @@ bool SystemInformationImplementation::RetrieveClassicalCPUCacheDetails() } while ((TLBCacheData[0] & 0x000000FF) > TLBPassCounter); // Ok - we now have the maximum TLB, L1, L2, and L3 sizes... - if ((L1Code == -1) && (L1Data == -1) && (L1Trace == -1)) + if ((L1Code == -1) && (L1Data == -1) && (L1Trace == -1)) { this->Features.L1CacheSize = -1; } - else if ((L1Code == -1) && (L1Data == -1) && (L1Trace != -1)) + else if ((L1Code == -1) && (L1Data == -1) && (L1Trace != -1)) { this->Features.L1CacheSize = L1Trace; } - else if ((L1Code != -1) && (L1Data == -1)) + else if ((L1Code != -1) && (L1Data == -1)) { this->Features.L1CacheSize = L1Code; } - else if ((L1Code == -1) && (L1Data != -1)) + else if ((L1Code == -1) && (L1Data != -1)) { this->Features.L1CacheSize = L1Data; } - else if ((L1Code != -1) && (L1Data != -1)) + else if ((L1Code != -1) && (L1Data != -1)) { this->Features.L1CacheSize = L1Code + L1Data; } - else + else { this->Features.L1CacheSize = -1; } // Ok - we now have the maximum TLB, L1, L2, and L3 sizes... - if (L2Unified == -1) + if (L2Unified == -1) { this->Features.L2CacheSize = -1; } - else + else { this->Features.L2CacheSize = L2Unified; } // Ok - we now have the maximum TLB, L1, L2, and L3 sizes... - if (L3Unified == -1) + if (L3Unified == -1) { this->Features.L3CacheSize = -1; } - else + else { this->Features.L3CacheSize = L3Unified; } @@ -1526,19 +2255,19 @@ bool SystemInformationImplementation::RetrieveClassicalCPUClockSpeed() // Attempt to get a starting tick count. QueryPerformanceCounter (&liStart); - __try + __try { - _asm + _asm { mov eax, 0x80000000 mov ebx, CLASSICAL_CPU_FREQ_LOOP - Timer_Loop: + Timer_Loop: bsf ecx,eax dec ebx jnz Timer_Loop - } + } } - __except(1) + __except(1) { return false; } @@ -1551,22 +2280,22 @@ bool SystemInformationImplementation::RetrieveClassicalCPUClockSpeed() dDifference = (((double) liEnd.QuadPart - (double) liStart.QuadPart) / (double) liCountsPerSecond.QuadPart); // Calculate the clock speed. - if (this->ChipID.Family == 3) + if (this->ChipID.Family == 3) { // 80386 processors.... Loop time is 115 cycles! dFrequency = (((CLASSICAL_CPU_FREQ_LOOP * 115) / dDifference) / 1000000); - } - else if (this->ChipID.Family == 4) + } + else if (this->ChipID.Family == 4) { // 80486 processors.... Loop time is 47 cycles! dFrequency = (((CLASSICAL_CPU_FREQ_LOOP * 47) / dDifference) / 1000000); - } - else if (this->ChipID.Family == 5) + } + else if (this->ChipID.Family == 5) { // Pentium processors.... Loop time is 43 cycles! dFrequency = (((CLASSICAL_CPU_FREQ_LOOP * 43) / dDifference) / 1000000); } - + // Save the clock speed. this->Features.CPUSpeed = (int) dFrequency; @@ -1583,7 +2312,7 @@ bool SystemInformationImplementation::RetrieveCPUExtendedLevelSupport(int CPULev { int MaxCPUExtendedLevel = 0; - // The extended CPUID is supported by various vendors starting with the following CPU models: + // The extended CPUID is supported by various vendors starting with the following CPU models: // // Manufacturer & Chip Name | Family Model Revision // @@ -1596,27 +2325,27 @@ bool SystemInformationImplementation::RetrieveCPUExtendedLevelSupport(int CPULev // // We check to see if a supported processor is present... - if (this->ChipManufacturer == AMD) + if (this->ChipManufacturer == AMD) { if (this->ChipID.Family < 5) return false; if ((this->ChipID.Family == 5) && (this->ChipID.Model < 6)) return false; - } - else if (this->ChipManufacturer == Cyrix) + } + else if (this->ChipManufacturer == Cyrix) { if (this->ChipID.Family < 5) return false; if ((this->ChipID.Family == 5) && (this->ChipID.Model < 4)) return false; if ((this->ChipID.Family == 6) && (this->ChipID.Model < 5)) return false; - } - else if (this->ChipManufacturer == IDT) + } + else if (this->ChipManufacturer == IDT) { if (this->ChipID.Family < 5) return false; if ((this->ChipID.Family == 5) && (this->ChipID.Model < 8)) return false; - } - else if (this->ChipManufacturer == Transmeta) + } + else if (this->ChipManufacturer == Transmeta) { if (this->ChipID.Family < 5) return false; - } - else if (this->ChipManufacturer == Intel) + } + else if (this->ChipManufacturer == Intel) { if (this->ChipID.Family < 0xf) { @@ -1638,7 +2367,7 @@ bool SystemInformationImplementation::RetrieveCPUExtendedLevelSupport(int CPULev push ecx push edx #endif - ; <<CPUID>> + ; <<CPUID>> ; eax = 0x80000000 --> eax: maximum supported extended level mov eax,0x80000000 CPUID_INSTRUCTION @@ -1652,7 +2381,7 @@ bool SystemInformationImplementation::RetrieveCPUExtendedLevelSupport(int CPULev #endif } } - __except(1) + __except(1) { return false; } @@ -1677,7 +2406,7 @@ bool SystemInformationImplementation::RetrieveExtendedCPUFeatures() { // Check that we are not using an Intel processor as it does not support this. - if (this->ChipManufacturer == Intel) + if (this->ChipManufacturer == Intel) { return false; } @@ -1692,9 +2421,9 @@ bool SystemInformationImplementation::RetrieveExtendedCPUFeatures() int localCPUExtendedFeatures = 0; // Use assembly to detect CPUID information... - __try + __try { - _asm + _asm { #ifdef CPUID_AWARE_COMPILER ; we must push/pop the registers <<CPUID>> writes to, as the @@ -1705,7 +2434,7 @@ bool SystemInformationImplementation::RetrieveExtendedCPUFeatures() push ecx push edx #endif - ; <<CPUID>> + ; <<CPUID>> ; eax = 0x80000001 --> eax: CPU ID - bits 31..16 - unused, bits 15..12 - type, bits 11..8 - family, bits 7..4 - model, bits 3..0 - mask revision ; ebx: 31..24 - default APIC ID, 23..16 - logical processsor ID, 15..8 - CFLUSH chunk size , 7..0 - brand ID ; edx: CPU feature flags @@ -1721,7 +2450,7 @@ bool SystemInformationImplementation::RetrieveExtendedCPUFeatures() #endif } } - __except(1) + __except(1) { return false; } @@ -1731,15 +2460,15 @@ bool SystemInformationImplementation::RetrieveExtendedCPUFeatures() this->Features.ExtendedFeatures.Has3DNowPlus = ((localCPUExtendedFeatures & 0x40000000) != 0); // 3DNow+ Present -- > Bit 30. this->Features.ExtendedFeatures.HasSSEMMX = ((localCPUExtendedFeatures & 0x00400000) != 0); // SSE MMX Present --> Bit 22. this->Features.ExtendedFeatures.SupportsMP = ((localCPUExtendedFeatures & 0x00080000) != 0); // MP Capable -- > Bit 19. - + // Retrieve AMD specific extended features. - if (this->ChipManufacturer == AMD) + if (this->ChipManufacturer == AMD) { this->Features.ExtendedFeatures.HasMMXPlus = ((localCPUExtendedFeatures & 0x00400000) != 0); // AMD specific: MMX-SSE --> Bit 22 } // Retrieve Cyrix specific extended features. - if (this->ChipManufacturer == Cyrix) + if (this->ChipManufacturer == Cyrix) { this->Features.ExtendedFeatures.HasMMXPlus = ((localCPUExtendedFeatures & 0x01000000) != 0); // Cyrix specific: Extended MMX --> Bit 24 } @@ -1794,7 +2523,7 @@ bool SystemInformationImplementation::RetrieveProcessorSerialNumber() #endif } } - __except(1) + __except(1) { return false; } @@ -1851,12 +2580,12 @@ bool SystemInformationImplementation::RetrieveCPUPowerManagement() push ecx push edx #endif - ; <<CPUID>> + ; <<CPUID>> ; eax = 0x80000007 --> edx: get processor power management mov eax,0x80000007 CPUID_INSTRUCTION mov localCPUPowerManagement, edx - + #ifdef CPUID_AWARE_COMPILER pop edx pop ecx @@ -1865,7 +2594,7 @@ bool SystemInformationImplementation::RetrieveCPUPowerManagement() #endif } } - __except(1) + __except(1) { return false; } @@ -1918,7 +2647,7 @@ bool SystemInformationImplementation::RetrieveExtendedCPUIdentity() push ecx push edx #endif - ; <<CPUID>> + ; <<CPUID>> ; eax = 0x80000002 --> eax, ebx, ecx, edx: get processor name string (part 1) mov eax,0x80000002 CPUID_INSTRUCTION @@ -1927,7 +2656,7 @@ bool SystemInformationImplementation::RetrieveExtendedCPUIdentity() mov CPUExtendedIdentity[2 * TYPE int], ecx mov CPUExtendedIdentity[3 * TYPE int], edx - ; <<CPUID>> + ; <<CPUID>> ; eax = 0x80000003 --> eax, ebx, ecx, edx: get processor name string (part 2) mov eax,0x80000003 CPUID_INSTRUCTION @@ -1936,7 +2665,7 @@ bool SystemInformationImplementation::RetrieveExtendedCPUIdentity() mov CPUExtendedIdentity[6 * TYPE int], ecx mov CPUExtendedIdentity[7 * TYPE int], edx - ; <<CPUID>> + ; <<CPUID>> ; eax = 0x80000004 --> eax, ebx, ecx, edx: get processor name string (part 3) mov eax,0x80000004 CPUID_INSTRUCTION @@ -1953,7 +2682,7 @@ bool SystemInformationImplementation::RetrieveExtendedCPUIdentity() #endif } } - __except(1) + __except(1) { return false; } @@ -1974,6 +2703,7 @@ bool SystemInformationImplementation::RetrieveExtendedCPUIdentity() memcpy (&(nbuf[44]), &(CPUExtendedIdentity[11]), sizeof (int)); nbuf[48] = '\0'; this->ChipID.ProcessorName = nbuf; + this->ChipID.ModelName = nbuf; // Because some manufacturers have leading white space - we have to post-process the name. SystemInformationStripLeadingSpace(this->ChipID.ProcessorName); @@ -1988,13 +2718,13 @@ bool SystemInformationImplementation::RetrieveExtendedCPUIdentity() bool SystemInformationImplementation::RetrieveClassicalCPUIdentity() { // Start by decided which manufacturer we are using.... - switch (this->ChipManufacturer) + switch (this->ChipManufacturer) { case Intel: // Check the family / model / revision to determine the CPU ID. switch (this->ChipID.Family) { case 3: - this->ChipID.ProcessorName = "Newer i80386 family"; + this->ChipID.ProcessorName = "Newer i80386 family"; break; case 4: switch (this->ChipID.Model) { @@ -2011,7 +2741,7 @@ bool SystemInformationImplementation::RetrieveClassicalCPUIdentity() } break; case 5: - switch (this->ChipID.Model) + switch (this->ChipID.Model) { case 0: this->ChipID.ProcessorName = "P5 A-Step"; break; case 1: this->ChipID.ProcessorName = "P5"; break; @@ -2024,7 +2754,7 @@ bool SystemInformationImplementation::RetrieveClassicalCPUIdentity() } break; case 6: - switch (this->ChipID.Model) + switch (this->ChipID.Model) { case 0: this->ChipID.ProcessorName = "P6 A-Step"; break; case 1: this->ChipID.ProcessorName = "P6"; break; @@ -2044,10 +2774,10 @@ bool SystemInformationImplementation::RetrieveClassicalCPUIdentity() break; case 0xf: // Check the extended family bits... - switch (this->ChipID.ExtendedFamily) + switch (this->ChipID.ExtendedFamily) { case 0: - switch (this->ChipID.Model) + switch (this->ChipID.Model) { case 0: this->ChipID.ProcessorName = "Pentium IV (0.18 micron)"; break; case 1: this->ChipID.ProcessorName = "Pentium IV (0.18 micron)"; break; @@ -2070,10 +2800,10 @@ bool SystemInformationImplementation::RetrieveClassicalCPUIdentity() case AMD: // Check the family / model / revision to determine the CPU ID. - switch (this->ChipID.Family) + switch (this->ChipID.Family) { case 4: - switch (this->ChipID.Model) + switch (this->ChipID.Model) { case 3: this->ChipID.ProcessorName = "80486DX2"; break; case 7: this->ChipID.ProcessorName = "80486DX2 WriteBack"; break; @@ -2085,7 +2815,7 @@ bool SystemInformationImplementation::RetrieveClassicalCPUIdentity() } break; case 5: - switch (this->ChipID.Model) + switch (this->ChipID.Model) { case 0: this->ChipID.ProcessorName = "SSA5 (PR75, PR90 = PR100)"; break; case 1: this->ChipID.ProcessorName = "5k86 (PR120 = PR133)"; break; @@ -2100,7 +2830,7 @@ bool SystemInformationImplementation::RetrieveClassicalCPUIdentity() } break; case 6: - switch (this->ChipID.Model) + switch (this->ChipID.Model) { case 1: this->ChipID.ProcessorName = "Athlon- (0.25 micron)"; break; case 2: this->ChipID.ProcessorName = "Athlon- (0.18 micron)"; break; @@ -2108,9 +2838,9 @@ bool SystemInformationImplementation::RetrieveClassicalCPUIdentity() case 4: this->ChipID.ProcessorName = "Athlon- (Thunderbird core)"; break; case 6: this->ChipID.ProcessorName = "Athlon- (Palomino core)"; break; case 7: this->ChipID.ProcessorName = "Duron- (Morgan core)"; break; - case 8: + case 8: if (this->Features.ExtendedFeatures.SupportsMP) - this->ChipID.ProcessorName = "Athlon - MP (Thoroughbred core)"; + this->ChipID.ProcessorName = "Athlon - MP (Thoroughbred core)"; else this->ChipID.ProcessorName = "Athlon - XP (Thoroughbred core)"; break; default: this->ChipID.ProcessorName = "Unknown K7 family"; return false; @@ -2123,10 +2853,10 @@ bool SystemInformationImplementation::RetrieveClassicalCPUIdentity() break; case Transmeta: - switch (this->ChipID.Family) - { + switch (this->ChipID.Family) + { case 5: - switch (this->ChipID.Model) + switch (this->ChipID.Model) { case 4: this->ChipID.ProcessorName = "Crusoe TM3x00 and TM5x00"; break; default: this->ChipID.ProcessorName = "Unknown Crusoe family"; return false; @@ -2139,10 +2869,10 @@ bool SystemInformationImplementation::RetrieveClassicalCPUIdentity() break; case Rise: - switch (this->ChipID.Family) - { + switch (this->ChipID.Family) + { case 5: - switch (this->ChipID.Model) + switch (this->ChipID.Model) { case 0: this->ChipID.ProcessorName = "mP6 (0.25 micron)"; break; case 2: this->ChipID.ProcessorName = "mP6 (0.18 micron)"; break; @@ -2156,10 +2886,10 @@ bool SystemInformationImplementation::RetrieveClassicalCPUIdentity() break; case UMC: - switch (this->ChipID.Family) - { + switch (this->ChipID.Family) + { case 4: - switch (this->ChipID.Model) + switch (this->ChipID.Model) { case 1: this->ChipID.ProcessorName = "U5D"; break; case 2: this->ChipID.ProcessorName = "U5S"; break; @@ -2173,10 +2903,10 @@ bool SystemInformationImplementation::RetrieveClassicalCPUIdentity() break; case IDT: - switch (this->ChipID.Family) - { + switch (this->ChipID.Family) + { case 5: - switch (this->ChipID.Model) + switch (this->ChipID.Model) { case 4: this->ChipID.ProcessorName = "C6"; break; case 8: this->ChipID.ProcessorName = "C2"; break; @@ -2185,7 +2915,7 @@ bool SystemInformationImplementation::RetrieveClassicalCPUIdentity() } break; case 6: - switch (this->ChipID.Model) + switch (this->ChipID.Model) { case 6: this->ChipID.ProcessorName = "VIA Cyrix III - Samuel"; break; default: this->ChipID.ProcessorName = "Unknown IDT\\Centaur family"; return false; @@ -2198,10 +2928,10 @@ bool SystemInformationImplementation::RetrieveClassicalCPUIdentity() break; case Cyrix: - switch (this->ChipID.Family) - { + switch (this->ChipID.Family) + { case 4: - switch (this->ChipID.Model) + switch (this->ChipID.Model) { case 4: this->ChipID.ProcessorName = "MediaGX GX = GXm"; break; case 9: this->ChipID.ProcessorName = "5x86"; break; @@ -2209,7 +2939,7 @@ bool SystemInformationImplementation::RetrieveClassicalCPUIdentity() } break; case 5: - switch (this->ChipID.Model) + switch (this->ChipID.Model) { case 2: this->ChipID.ProcessorName = "Cx6x86"; break; case 4: this->ChipID.ProcessorName = "MediaGX GXm"; break; @@ -2217,7 +2947,7 @@ bool SystemInformationImplementation::RetrieveClassicalCPUIdentity() } break; case 6: - switch (this->ChipID.Model) + switch (this->ChipID.Model) { case 0: this->ChipID.ProcessorName = "6x86MX"; break; case 5: this->ChipID.ProcessorName = "Cyrix M2 Core"; break; @@ -2234,10 +2964,10 @@ bool SystemInformationImplementation::RetrieveClassicalCPUIdentity() break; case NexGen: - switch (this->ChipID.Family) - { + switch (this->ChipID.Family) + { case 5: - switch (this->ChipID.Model) + switch (this->ChipID.Model) { case 0: this->ChipID.ProcessorName = "Nx586 or Nx586FPU"; break; default: this->ChipID.ProcessorName = "Unknown NexGen family"; return false; @@ -2287,12 +3017,12 @@ int SystemInformationImplementation::RetreiveInformationFromCpuInfoFile() kwsys_stl::string buffer; FILE *fd = fopen("/proc/cpuinfo", "r" ); - if ( !fd ) + if ( !fd ) { kwsys_ios::cout << "Problem opening /proc/cpuinfo" << kwsys_ios::endl; return 0; } - + size_t fileSize = 0; while(!feof(fd)) { @@ -2336,13 +3066,13 @@ int SystemInformationImplementation::RetreiveInformationFromCpuInfoFile() #else // __CYGWIN__ // does not have "physical id" entries, neither "cpu cores" - // this has to be fixed for hyper-threading. + // this has to be fixed for hyper-threading. kwsys_stl::string cpucount = this->ExtractValueFromCpuInfoFile(buffer,"cpu count"); this->NumberOfPhysicalCPU= this->NumberOfLogicalCPU = atoi(cpucount.c_str()); #endif - // gotta have one, and if this is 0 then we get a / by 0n + // gotta have one, and if this is 0 then we get a / by 0n // beter to have a bad answer than a crash if(this->NumberOfPhysicalCPU <= 0) { @@ -2358,15 +3088,18 @@ int SystemInformationImplementation::RetreiveInformationFromCpuInfoFile() // Chip family this->ChipID.Family = atoi(this->ExtractValueFromCpuInfoFile(buffer,"cpu family").c_str()); - + // Chip Vendor this->ChipID.Vendor = this->ExtractValueFromCpuInfoFile(buffer,"vendor_id"); this->FindManufacturer(); - + // Chip Model this->ChipID.Model = atoi(this->ExtractValueFromCpuInfoFile(buffer,"model").c_str()); this->RetrieveClassicalCPUIdentity(); + // Chip Model Name + this->ChipID.ModelName = this->ExtractValueFromCpuInfoFile(buffer,"model name").c_str(); + // L1 Cache size kwsys_stl::string cacheSize = this->ExtractValueFromCpuInfoFile(buffer,"cache size"); pos = cacheSize.find(" KB"); @@ -2378,6 +3111,333 @@ int SystemInformationImplementation::RetreiveInformationFromCpuInfoFile() return 1; } +/** +Get total system RAM in units of KiB. +*/ +SystemInformation::LongLong +SystemInformationImplementation::GetHostMemoryTotal() +{ +#if defined(_WIN32) +# if defined(_MSC_VER) && _MSC_VER < 1300 + MEMORYSTATUS stat; + stat.dwLength = sizeof(stat); + GlobalMemoryStatus(&stat); + return stat.dwTotalPhys/1024; +# else + MEMORYSTATUSEX statex; + statex.dwLength=sizeof(statex); + GlobalMemoryStatusEx(&statex); + return statex.ullTotalPhys/1024; +# endif +#elif defined(__linux) + SystemInformation::LongLong memTotal=0; + int ierr=GetFieldFromFile("/proc/meminfo","MemTotal:",memTotal); + if (ierr) + { + return -1; + } + return memTotal; +#elif defined(__APPLE__) + uint64_t mem; + size_t len = sizeof(mem); + int ierr=sysctlbyname("hw.memsize", &mem, &len, NULL, 0); + if (ierr) + { + return -1; + } + return mem/1024; +#else + return 0; +#endif +} + +/** +Get total system RAM in units of KiB. This may differ from the +host total if a host-wide resource limit is applied. +*/ +SystemInformation::LongLong +SystemInformationImplementation::GetHostMemoryAvailable(const char *hostLimitEnvVarName) +{ + SystemInformation::LongLong memTotal=this->GetHostMemoryTotal(); + + // the following mechanism is provided for systems that + // apply resource limits across groups of processes. + // this is of use on certain SMP systems (eg. SGI UV) + // where the host has a large amount of ram but a given user's + // access to it is severly restricted. The system will + // apply a limit across a set of processes. Units are in KiB. + if (hostLimitEnvVarName) + { + const char *hostLimitEnvVarValue=getenv(hostLimitEnvVarName); + if (hostLimitEnvVarValue) + { + SystemInformation::LongLong hostLimit=atoLongLong(hostLimitEnvVarValue); + if (hostLimit>0) + { + memTotal=min(hostLimit,memTotal); + } + } + } + + return memTotal; +} + +/** +Get total system RAM in units of KiB. This may differ from the +host total if a per-process resource limit is applied. +*/ +SystemInformation::LongLong +SystemInformationImplementation::GetProcMemoryAvailable( + const char *hostLimitEnvVarName, + const char *procLimitEnvVarName) +{ + SystemInformation::LongLong memAvail + = this->GetHostMemoryAvailable(hostLimitEnvVarName); + + // the following mechanism is provide for systems where rlimits + // are not employed. Units are in KiB. + if (procLimitEnvVarName) + { + const char *procLimitEnvVarValue=getenv(procLimitEnvVarName); + if (procLimitEnvVarValue) + { + SystemInformation::LongLong procLimit=atoLongLong(procLimitEnvVarValue); + if (procLimit>0) + { + memAvail=min(procLimit,memAvail); + } + } + } + +#if defined(__linux) + int ierr; + ResourceLimitType rlim; + ierr=GetResourceLimit(RLIMIT_DATA,&rlim); + if ((ierr==0) && (rlim.rlim_cur != RLIM_INFINITY)) + { + memAvail=min((SystemInformation::LongLong)rlim.rlim_cur/1024,memAvail); + } + + ierr=GetResourceLimit(RLIMIT_AS,&rlim); + if ((ierr==0) && (rlim.rlim_cur != RLIM_INFINITY)) + { + memAvail=min((SystemInformation::LongLong)rlim.rlim_cur/1024,memAvail); + } +#elif defined(__APPLE__) + struct rlimit rlim; + int ierr; + ierr=getrlimit(RLIMIT_DATA,&rlim); + if ((ierr==0) && (rlim.rlim_cur != RLIM_INFINITY)) + { + memAvail=min((SystemInformation::LongLong)rlim.rlim_cur/1024,memAvail); + } + + ierr=getrlimit(RLIMIT_RSS,&rlim); + if ((ierr==0) && (rlim.rlim_cur != RLIM_INFINITY)) + { + memAvail=min((SystemInformation::LongLong)rlim.rlim_cur/1024,memAvail); + } +#endif + + return memAvail; +} + +/** +Get RAM used by all processes in the host, in units of KiB. +*/ +SystemInformation::LongLong +SystemInformationImplementation::GetHostMemoryUsed() +{ +#if defined(_WIN32) +# if defined(_MSC_VER) && _MSC_VER < 1300 + MEMORYSTATUS stat; + stat.dwLength = sizeof(stat); + GlobalMemoryStatus(&stat); + return (stat.dwTotalPhys - stat.dwAvailPhys)/1024; +# else + MEMORYSTATUSEX statex; + statex.dwLength=sizeof(statex); + GlobalMemoryStatusEx(&statex); + return (statex.ullTotalPhys - statex.ullAvailPhys)/1024; +# endif +#elif defined(__linux) + const char *names[3]={"MemTotal:","MemFree:",NULL}; + SystemInformation::LongLong values[2]={SystemInformation::LongLong(0)}; + int ierr=GetFieldsFromFile("/proc/meminfo",names,values); + if (ierr) + { + return ierr; + } + SystemInformation::LongLong &memTotal=values[0]; + SystemInformation::LongLong &memFree=values[1]; + return memTotal - memFree; +#elif defined(__APPLE__) + SystemInformation::LongLong psz=getpagesize(); + if (psz<1) + { + return -1; + } + const char *names[4]={"Pages active:","Pages inactive:","Pages wired down:",NULL}; + SystemInformation::LongLong values[3]={SystemInformation::LongLong(0)}; + int ierr=GetFieldsFromCommand("vm_stat", names, values); + if (ierr) + { + return -1; + } + SystemInformation::LongLong &vmActive=values[0]; + SystemInformation::LongLong &vmInactive=values[1]; + SystemInformation::LongLong &vmWired=values[2]; + return ((vmActive+vmInactive+vmWired)*psz)/1024; +#else + return 0; +#endif +} + +/** +Get system RAM used by the process associated with the given +process id in units of KiB. +*/ +SystemInformation::LongLong +SystemInformationImplementation::GetProcMemoryUsed() +{ +#if defined(_WIN32) && defined(KWSYS_SYS_HAS_PSAPI) + long pid=GetCurrentProcessId(); + HANDLE hProc; + hProc=OpenProcess( + PROCESS_QUERY_INFORMATION|PROCESS_VM_READ, + false, + pid); + if (hProc==0) + { + return -1; + } + PROCESS_MEMORY_COUNTERS pmc; + int ok=GetProcessMemoryInfo(hProc,&pmc,sizeof(pmc)); + CloseHandle(hProc); + if (!ok) + { + return -2; + } + return pmc.WorkingSetSize/1024; +#elif defined(__linux) + SystemInformation::LongLong memUsed=0; + int ierr=GetFieldFromFile("/proc/self/status","VmRSS:",memUsed); + if (ierr) + { + return -1; + } + return memUsed; +#elif defined(__APPLE__) + SystemInformation::LongLong memUsed=0; + pid_t pid=getpid(); + kwsys_ios::ostringstream oss; + oss << "ps -o rss= -p " << pid; + FILE *file=popen(oss.str().c_str(),"r"); + if (file==0) + { + return -1; + } + oss.str(""); + while (!feof(file) && !ferror(file)) + { + char buf[256]={'\0'}; + errno=0; + size_t nRead=fread(buf,1,256,file); + if (ferror(file) && (errno==EINTR)) + { + clearerr(file); + } + if (nRead) oss << buf; + } + int ierr=ferror(file); + pclose(file); + if (ierr) + { + return -2; + } + kwsys_ios::istringstream iss(oss.str()); + iss >> memUsed; + return memUsed; +#else + return 0; +#endif +} + +/** +Get the process id of the running process. +*/ +SystemInformation::LongLong +SystemInformationImplementation::GetProcessId() +{ +#if defined(_WIN32) + return GetCurrentProcessId(); +#elif defined(__linux) || defined(__APPLE__) + return getpid(); +#else + return -1; +#endif +} + +/** +when set print stack trace in response to common signals. +*/ +void SystemInformationImplementation::SetStackTraceOnError(int enable) +{ +#if !defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN__) + static int saOrigValid=0; + static struct sigaction saSEGVOrig; + static struct sigaction saTERMOrig; + static struct sigaction saINTOrig; + static struct sigaction saILLOrig; + static struct sigaction saBUSOrig; + static struct sigaction saFPEOrig; + + if (enable && !saOrigValid) + { + // save the current actions + sigaction(SIGSEGV,0,&saSEGVOrig); + sigaction(SIGTERM,0,&saTERMOrig); + sigaction(SIGINT,0,&saINTOrig); + sigaction(SIGILL,0,&saILLOrig); + sigaction(SIGBUS,0,&saBUSOrig); + sigaction(SIGFPE,0,&saFPEOrig); + + // enable read, disable write + saOrigValid=1; + + // install ours + struct sigaction sa; + sa.sa_sigaction=(SigAction)StacktraceSignalHandler; + sa.sa_flags=SA_SIGINFO|SA_RESTART; + sigemptyset(&sa.sa_mask); + + sigaction(SIGSEGV,&sa,0); + sigaction(SIGTERM,&sa,0); + sigaction(SIGINT,&sa,0); + sigaction(SIGILL,&sa,0); + sigaction(SIGBUS,&sa,0); + sigaction(SIGFPE,&sa,0); + } + else + if (!enable && saOrigValid) + { + // restore previous actions + sigaction(SIGSEGV,&saSEGVOrig,0); + sigaction(SIGTERM,&saTERMOrig,0); + sigaction(SIGINT,&saINTOrig,0); + sigaction(SIGILL,&saILLOrig,0); + sigaction(SIGBUS,&saBUSOrig,0); + sigaction(SIGFPE,&saFPEOrig,0); + + // enable write, disable read + saOrigValid=0; + } +#else + // avoid warning C4100 + (void)enable; +#endif +} + /** Query for the memory status */ int SystemInformationImplementation::QueryMemory() { @@ -2388,13 +3448,13 @@ int SystemInformationImplementation::QueryMemory() #ifdef __CYGWIN__ return 0; #elif defined(_WIN32) -#if _MSC_VER < 1300 +# if defined(_MSC_VER) && _MSC_VER < 1300 MEMORYSTATUS ms; unsigned long tv, tp, av, ap; ms.dwLength = sizeof(ms); GlobalMemoryStatus(&ms); - #define MEM_VAL(value) dw##value -#else +# define MEM_VAL(value) dw##value +# else MEMORYSTATUSEX ms; DWORDLONG tv, tp, av, ap; ms.dwLength = sizeof(ms); @@ -2402,8 +3462,8 @@ int SystemInformationImplementation::QueryMemory() { return 0; } -#define MEM_VAL(value) ull##value -#endif +# define MEM_VAL(value) ull##value +# endif tv = ms.MEM_VAL(TotalVirtual); tp = ms.MEM_VAL(TotalPhys); av = ms.MEM_VAL(AvailVirtual); @@ -2418,12 +3478,12 @@ int SystemInformationImplementation::QueryMemory() unsigned long tp=0; unsigned long av=0; unsigned long ap=0; - + char buffer[1024]; // for reading lines - + int linuxMajor = 0; int linuxMinor = 0; - + // Find the Linux kernel version first struct utsname unameInfo; int errorFlag = uname(&unameInfo); @@ -2432,31 +3492,31 @@ int SystemInformationImplementation::QueryMemory() kwsys_ios::cout << "Problem calling uname(): " << strerror(errno) << kwsys_ios::endl; return 0; } - + if( unameInfo.release!=0 && strlen(unameInfo.release)>=3 ) { // release looks like "2.6.3-15mdk-i686-up-4GB" char majorChar=unameInfo.release[0]; char minorChar=unameInfo.release[2]; - + if( isdigit(majorChar) ) { linuxMajor=majorChar-'0'; } - + if( isdigit(minorChar) ) { linuxMinor=minorChar-'0'; } } - + FILE *fd = fopen("/proc/meminfo", "r" ); - if ( !fd ) + if ( !fd ) { kwsys_ios::cout << "Problem opening /proc/meminfo" << kwsys_ios::endl; return 0; } - + if( linuxMajor>=3 || ( (linuxMajor>=2) && (linuxMinor>=6) ) ) { // new /proc/meminfo format since kernel 2.6.x @@ -2499,7 +3559,7 @@ int SystemInformationImplementation::QueryMemory() else { // /proc/meminfo format for kernel older than 2.6.x - + unsigned long temp; unsigned long cachedMem; unsigned long buffersMem; @@ -2537,7 +3597,7 @@ int SystemInformationImplementation::QueryMemory() unsigned long ap=0; struct pst_static pst; struct pst_dynamic pdy; - + unsigned long ps = 0; if (pstat_getstatic(&pst, sizeof(pst), (size_t) 1, 0) != -1) { @@ -2559,35 +3619,34 @@ int SystemInformationImplementation::QueryMemory() #else return 0; #endif - - } /** */ -size_t SystemInformationImplementation::GetTotalVirtualMemory() -{ - return this->TotalVirtualMemory; +size_t SystemInformationImplementation::GetTotalVirtualMemory() +{ + return this->TotalVirtualMemory; } /** */ -size_t SystemInformationImplementation::GetAvailableVirtualMemory() -{ - return this->AvailableVirtualMemory; +size_t SystemInformationImplementation::GetAvailableVirtualMemory() +{ + return this->AvailableVirtualMemory; } -size_t SystemInformationImplementation::GetTotalPhysicalMemory() -{ - return this->TotalPhysicalMemory; +size_t SystemInformationImplementation::GetTotalPhysicalMemory() +{ + return this->TotalPhysicalMemory; } /** */ -size_t SystemInformationImplementation::GetAvailablePhysicalMemory() -{ - return this->AvailablePhysicalMemory; +size_t SystemInformationImplementation::GetAvailablePhysicalMemory() +{ + return this->AvailablePhysicalMemory; } /** Get Cycle differences */ -LongLong SystemInformationImplementation::GetCyclesDifference (DELAY_FUNC DelayFunction, +SystemInformation::LongLong +SystemInformationImplementation::GetCyclesDifference (DELAY_FUNC DelayFunction, unsigned int uiParameter) { #if USE_ASM_INSTRUCTIONS @@ -2619,7 +3678,7 @@ LongLong SystemInformationImplementation::GetCyclesDifference (DELAY_FUNC DelayF mov eax1, esi ; eax2 = esi } } - __except(1) + __except(1) { return -1; } @@ -2642,7 +3701,7 @@ void SystemInformationImplementation::DelayOverhead(unsigned int uiMS) __int64 x; // Get the frequency of the high performance counter. - if(!QueryPerformanceFrequency (&Frequency)) + if(!QueryPerformanceFrequency (&Frequency)) { return; } @@ -2650,9 +3709,9 @@ void SystemInformationImplementation::DelayOverhead(unsigned int uiMS) // Get the starting position of the counter. QueryPerformanceCounter (&StartCounter); - + do { - // Get the ending position of the counter. + // Get the ending position of the counter. QueryPerformanceCounter (&EndCounter); } while (EndCounter.QuadPart - StartCounter.QuadPart == x); #endif @@ -2706,7 +3765,7 @@ unsigned int SystemInformationImplementation::IsHyperThreadingSupported() mov VendorId, ebx mov VendorId + 4, edx mov VendorId + 8, ecx - + mov eax, 1 // call cpuid with eax = 1 cpuid mov Regeax, eax // eax contains family processor type @@ -2743,7 +3802,7 @@ unsigned char SystemInformationImplementation::GetAPICId() unsigned int Regebx = 0; #if USE_ASM_INSTRUCTIONS - if (!this->IsHyperThreadingSupported()) + if (!this->IsHyperThreadingSupported()) { return static_cast<unsigned char>(-1); // HT not supported } // Logical processor = 1 @@ -2773,7 +3832,7 @@ int SystemInformationImplementation::CPUCount() // Number of physical processors in a non-Intel system // or in a 32-bit Intel system with Hyper-Threading technology disabled - this->NumberOfPhysicalCPU = (unsigned char) info.dwNumberOfProcessors; + this->NumberOfPhysicalCPU = (unsigned char) info.dwNumberOfProcessors; if (this->IsHyperThreadingSupported()) { @@ -2789,7 +3848,7 @@ int SystemInformationImplementation::CPUCount() DWORD_PTR dwSystemAffinity; DWORD dwAffinityMask; - // Calculate the appropriate shifts and mask based on the + // Calculate the appropriate shifts and mask based on the // number of logical processors. unsigned int i = 1; unsigned char PHY_ID_MASK = 0xFF; @@ -2801,7 +3860,7 @@ int SystemInformationImplementation::CPUCount() PHY_ID_MASK <<= 1; // PHY_ID_SHIFT++; } - + hCurrentProcessHandle = GetCurrentProcess(); GetProcessAffinityMask(hCurrentProcessHandle, &dwProcessAffinity, &dwSystemAffinity); @@ -2829,8 +3888,8 @@ int SystemInformationImplementation::CPUCount() APIC_ID = GetAPICId(); LOG_ID = APIC_ID & ~PHY_ID_MASK; - - if (LOG_ID != 0) + + if (LOG_ID != 0) { HT_Enabled = 1; } @@ -2840,7 +3899,7 @@ int SystemInformationImplementation::CPUCount() } // Reset the processor affinity SetProcessAffinityMask(hCurrentProcessHandle, dwProcessAffinity); - + if (this->NumberOfLogicalCPU == 1) // Normal P4 : HT is disabled in hardware { StatusFlag = HT_DISABLED; @@ -2853,7 +3912,7 @@ int SystemInformationImplementation::CPUCount() this->NumberOfPhysicalCPU /= (this->NumberOfLogicalCPU); StatusFlag = HT_ENABLED; } - else + else { StatusFlag = HT_SUPPORTED_NOT_ENABLED; } @@ -2891,6 +3950,7 @@ unsigned int SystemInformationImplementation::GetNumberOfPhysicalCPU() bool SystemInformationImplementation::ParseSysCtl() { #if defined(__APPLE__) + char retBuf[128]; int err = 0; uint64_t value = 0; size_t len = sizeof(value); @@ -2901,9 +3961,10 @@ bool SystemInformationImplementation::ParseSysCtl() this->AvailablePhysicalMemory = 0; vm_statistics_data_t vmstat; mach_msg_type_number_t count = HOST_VM_INFO_COUNT; - if ( host_statistics(mach_host_self(), HOST_VM_INFO, + if ( host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t) &vmstat, &count) == KERN_SUCCESS ) { + len = sizeof(value); err = sysctlbyname("hw.pagesize", &value, &len, NULL, 0); int64_t available_memory = vmstat.free_count * value; this->AvailablePhysicalMemory = static_cast< size_t >( available_memory / 1048576 ); @@ -2914,7 +3975,7 @@ bool SystemInformationImplementation::ParseSysCtl() int mib[2] = { CTL_VM, VM_SWAPUSAGE }; size_t miblen = sizeof(mib) / sizeof(mib[0]); struct xsw_usage swap; - len = sizeof(struct xsw_usage); + len = sizeof(swap); err = sysctl(mib, miblen, &swap, &len, NULL, 0); if (err == 0) { @@ -2929,8 +3990,9 @@ bool SystemInformationImplementation::ParseSysCtl() // CPU Info len = sizeof(this->NumberOfPhysicalCPU); sysctlbyname("hw.physicalcpu", &this->NumberOfPhysicalCPU, &len, NULL, 0); + len = sizeof(this->NumberOfLogicalCPU); sysctlbyname("hw.logicalcpu", &this->NumberOfLogicalCPU, &len, NULL, 0); - this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical = + this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical = this->LogicalCPUPerPhysicalCPU(); len = sizeof(value); @@ -2947,16 +4009,16 @@ bool SystemInformationImplementation::ParseSysCtl() if (err != 0) // Go back to names we know but are less descriptive { this->ChipID.Family = 0; - char retBuf[32]; - ::memset(retBuf, 0, 32); + ::memset(retBuf, 0, 128); len = 32; - err = sysctlbyname("hw.machine", &retBuf, &len, NULL, 0); + err = sysctlbyname("hw.machine", &retBuf, &len, NULL, 0); kwsys_stl::string machineBuf(retBuf); if (machineBuf.find_first_of("Power") != kwsys_stl::string::npos) { this->ChipID.Vendor = "IBM"; - len = 4; + len = sizeof(this->ChipID.Family); err = sysctlbyname("hw.cputype", &this->ChipID.Family, &len, NULL, 0); + len = sizeof(this->ChipID.Model); err = sysctlbyname("hw.cpusubtype", &this->ChipID.Model, &len, NULL, 0); this->FindManufacturer(); } @@ -2964,35 +4026,40 @@ bool SystemInformationImplementation::ParseSysCtl() else // Should be an Intel Chip. { len = sizeof(this->ChipID.Family); - err = + err = sysctlbyname("machdep.cpu.family", &this->ChipID.Family, &len, NULL, 0); - - char retBuf[128]; + ::memset(retBuf, 0, 128); len = 128; err = sysctlbyname("machdep.cpu.vendor", retBuf, &len, NULL, 0); // Chip Vendor this->ChipID.Vendor = retBuf; this->FindManufacturer(); - - ::memset(retBuf, 0, 128); - err = - sysctlbyname("machdep.cpu.brand_string", - retBuf, &len, NULL, 0); - this->ChipID.ProcessorName = retBuf; // Chip Model len = sizeof(value); err = sysctlbyname("machdep.cpu.model", &value, &len, NULL, 0); this->ChipID.Model = static_cast< int >( value ); } + + // brand string + ::memset(retBuf, 0, sizeof(retBuf)); + len = sizeof(retBuf); + err = sysctlbyname("machdep.cpu.brand_string", retBuf, &len, NULL, 0); + if (!err) + { + this->ChipID.ProcessorName = retBuf; + this->ChipID.ModelName = retBuf; + } + // Cache size len = sizeof(value); err = sysctlbyname("hw.l1icachesize", &value, &len, NULL, 0); this->Features.L1CacheSize = static_cast< int >( value ); + len = sizeof(value); err = sysctlbyname("hw.l2cachesize", &value, &len, NULL, 0); this->Features.L2CacheSize = static_cast< int >( value ); - + return true; #else return false; @@ -3019,7 +4086,7 @@ kwsys_stl::string SystemInformationImplementation::ExtractValueFromSysCtl(const /** Run a given process */ kwsys_stl::string SystemInformationImplementation::RunProcess(kwsys_stl::vector<const char*> args) -{ +{ kwsys_stl::string buffer = ""; // Run the application @@ -3085,7 +4152,7 @@ kwsys_stl::string SystemInformationImplementation::ParseValueFromKStat(const cha args.clear(); args.push_back("kstat"); args.push_back("-p"); - + kwsys_stl::string command = arguments; size_t start = command.npos; size_t pos = command.find(' ',0); @@ -3105,7 +4172,7 @@ kwsys_stl::string SystemInformationImplementation::ParseValueFromKStat(const cha b0 = command.find('"',b1+1); b1 = command.find('"',b0+1); } - + if(!inQuotes) { kwsys_stl::string arg = command.substr(start+1,pos-start-1); @@ -3117,7 +4184,7 @@ kwsys_stl::string SystemInformationImplementation::ParseValueFromKStat(const cha arg.erase(quotes,1); quotes = arg.find('"'); } - args.push_back(arg.c_str()); + args.push_back(arg.c_str()); start = pos; } pos = command.find(' ',pos+1); @@ -3154,7 +4221,7 @@ bool SystemInformationImplementation::QuerySolarisInfo() this->NumberOfPhysicalCPU = static_cast<unsigned int>( atoi(this->ParseValueFromKStat("-n syste_misc -s ncpus").c_str())); this->NumberOfLogicalCPU = this->NumberOfPhysicalCPU; - + if(this->NumberOfPhysicalCPU!=0) { this->NumberOfLogicalCPU /= this->NumberOfPhysicalCPU; @@ -3163,19 +4230,19 @@ bool SystemInformationImplementation::QuerySolarisInfo() this->CPUSpeedInMHz = static_cast<float>(atoi(this->ParseValueFromKStat("-s clock_MHz").c_str())); // Chip family - this->ChipID.Family = 0; - + this->ChipID.Family = 0; + // Chip Vendor this->ChipID.Vendor = "Sun"; this->FindManufacturer(); - + // Chip Model this->ChipID.ProcessorName = this->ParseValueFromKStat("-s cpu_type"); this->ChipID.Model = 0; // Cache size - this->Features.L1CacheSize = 0; - this->Features.L2CacheSize = 0; + this->Features.L1CacheSize = 0; + this->Features.L2CacheSize = 0; char* tail; unsigned long totalMemory = @@ -3200,16 +4267,16 @@ bool SystemInformationImplementation::QueryHaikuInfo() system_info info; get_system_info(&info); - + this->NumberOfPhysicalCPU = info.cpu_count; this->CPUSpeedInMHz = info.cpu_clock_speed / 1000000.0F; // Physical Memory this->TotalPhysicalMemory = (info.max_pages * B_PAGE_SIZE) / (1024 * 1024) ; - this->AvailablePhysicalMemory = this->TotalPhysicalMemory - + this->AvailablePhysicalMemory = this->TotalPhysicalMemory - ((info.used_pages * B_PAGE_SIZE) / (1024 * 1024)); - + // NOTE: get_system_info_etc is currently a private call so just set to 0 // until it becomes public this->TotalVirtualMemory = 0; @@ -3237,8 +4304,8 @@ bool SystemInformationImplementation::QueryHaikuInfo() this->ChipID.Type = cpu_info.eax_1.type; // Chip family - this->ChipID.Family = cpu_info.eax_1.family; - + this->ChipID.Family = cpu_info.eax_1.family; + // Chip Model this->ChipID.Model = cpu_info.eax_1.model; @@ -3365,16 +4432,16 @@ bool SystemInformationImplementation::QueryOSInformation() ZeroMemory (&osvi, sizeof (OSVERSIONINFOEX)); osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFOEX); bOsVersionInfoEx = GetVersionEx ((OSVERSIONINFO *) &osvi); - if (!bOsVersionInfoEx) + if (!bOsVersionInfoEx) { osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); - if (!GetVersionEx ((OSVERSIONINFO *) &osvi)) + if (!GetVersionEx ((OSVERSIONINFO *) &osvi)) { return false; } } - switch (osvi.dwPlatformId) + switch (osvi.dwPlatformId) { case VER_PLATFORM_WIN32_NT: // Test for the product. @@ -3417,40 +4484,40 @@ bool SystemInformationImplementation::QueryOSInformation() { this->OSRelease += " Personal"; } - else + else { this->OSRelease += " Professional"; } } #endif - } + } else if (osvi.wProductType == VER_NT_SERVER) { // Check for .NET Server instead of Windows XP. - if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1) + if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1) { this->OSRelease = ".NET"; } // Continue with the type detection. - if (osvi.wSuiteMask & VER_SUITE_DATACENTER) + if (osvi.wSuiteMask & VER_SUITE_DATACENTER) { this->OSRelease += " DataCenter Server"; } - else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE) + else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE) { this->OSRelease += " Advanced Server"; } - else + else { this->OSRelease += " Server"; } } sprintf (operatingSystem, "%s (Build %ld)", osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF); - this->OSVersion = operatingSystem; + this->OSVersion = operatingSystem; } - else + else #endif // VER_NT_WORKSTATION { HKEY hKey; @@ -3473,7 +4540,7 @@ bool SystemInformationImplementation::QueryOSInformation() { this->OSRelease += " Standard Server"; } - else + else { this->OSRelease += " Server"; } @@ -3485,7 +4552,7 @@ bool SystemInformationImplementation::QueryOSInformation() { this->OSRelease += " Enterprise Server"; } - else + else { this->OSRelease += " Advanced Server"; } @@ -3493,7 +4560,7 @@ bool SystemInformationImplementation::QueryOSInformation() } // Display version, service pack (if any), and build number. - if (osvi.dwMajorVersion <= 4) + if (osvi.dwMajorVersion <= 4) { // NB: NT 4.0 and earlier. sprintf (operatingSystem, "version %ld.%ld %s (Build %ld)", @@ -3502,30 +4569,30 @@ bool SystemInformationImplementation::QueryOSInformation() osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF); this->OSVersion = operatingSystem; - } - else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1) + } + else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1) { // Windows XP and .NET server. typedef BOOL (CALLBACK* LPFNPROC) (HANDLE, BOOL *); - HINSTANCE hKernelDLL; + HINSTANCE hKernelDLL; LPFNPROC DLLProc; - + // Load the Kernel32 DLL. hKernelDLL = LoadLibrary ("kernel32"); - if (hKernelDLL != NULL) { + if (hKernelDLL != NULL) { // Only XP and .NET Server support IsWOW64Process so... Load dynamically! - DLLProc = (LPFNPROC) GetProcAddress (hKernelDLL, "IsWow64Process"); - + DLLProc = (LPFNPROC) GetProcAddress (hKernelDLL, "IsWow64Process"); + // If the function address is valid, call the function. if (DLLProc != NULL) (DLLProc) (GetCurrentProcess (), &bIsWindows64Bit); else bIsWindows64Bit = false; - + // Free the DLL module. - FreeLibrary (hKernelDLL); - } - } - else - { + FreeLibrary (hKernelDLL); + } + } + else + { // Windows 2000 and everything else. sprintf (operatingSystem,"%s (Build %ld)", osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF); this->OSVersion = operatingSystem; @@ -3534,32 +4601,32 @@ bool SystemInformationImplementation::QueryOSInformation() case VER_PLATFORM_WIN32_WINDOWS: // Test for the product. - if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0) + if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0) { this->OSRelease = "95"; - if(osvi.szCSDVersion[1] == 'C') + if(osvi.szCSDVersion[1] == 'C') { this->OSRelease += "OSR 2.5"; } - else if(osvi.szCSDVersion[1] == 'B') + else if(osvi.szCSDVersion[1] == 'B') { this->OSRelease += "OSR 2"; } - } + } - if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10) + if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10) { this->OSRelease = "98"; - if (osvi.szCSDVersion[1] == 'A' ) + if (osvi.szCSDVersion[1] == 'A' ) { this->OSRelease += "SE"; } - } + } - if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90) + if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90) { this->OSRelease = "Me"; - } + } break; case VER_PLATFORM_WIN32s: @@ -3583,7 +4650,7 @@ bool SystemInformationImplementation::QueryOSInformation() WSACleanup( ); } this->Hostname = name; - + const char* arch = getenv("PROCESSOR_ARCHITECTURE"); if(arch) { @@ -3604,51 +4671,41 @@ bool SystemInformationImplementation::QueryOSInformation() } #ifdef __APPLE__ - this->CallSwVers(); + this->OSName="Unknown Apple OS"; + this->OSRelease="Unknown product version"; + this->OSVersion="Unknown build version"; + + this->CallSwVers("-productName",this->OSName); + this->CallSwVers("-productVersion",this->OSRelease); + this->CallSwVers("-buildVersion",this->OSVersion); #endif #endif return true; - } - -void SystemInformationImplementation::CallSwVers() +int SystemInformationImplementation::CallSwVers( + const char *arg, + kwsys_stl::string &ver) { #ifdef __APPLE__ - kwsys_stl::string output; kwsys_stl::vector<const char*> args; - args.clear(); - - args.push_back("sw_vers"); - args.push_back("-productName"); - args.push_back(0); - output = this->RunProcess(args); - this->TrimNewline(output); - this->OSName = output; - args.clear(); - args.push_back("sw_vers"); - args.push_back("-productVersion"); + args.push_back(arg); args.push_back(0); - output = this->RunProcess(args); - this->TrimNewline(output); - this->OSRelease = output; - args.clear(); - - args.push_back("sw_vers"); - args.push_back("-buildVersion"); - args.push_back(0); - output = this->RunProcess(args); - this->TrimNewline(output); - this->OSVersion = output; + ver = this->RunProcess(args); + this->TrimNewline(ver); +#else + // avoid C4100 + (void)arg; + (void)ver; #endif + return 0; } - void SystemInformationImplementation::TrimNewline(kwsys_stl::string& output) -{ +{ // remove \r kwsys_stl::string::size_type pos=0; while((pos = output.find("\r", pos)) != kwsys_stl::string::npos) diff --git a/Source/kwsys/SystemInformation.hxx.in b/Source/kwsys/SystemInformation.hxx.in index b6ebe6a..8f4cb4e 100644 --- a/Source/kwsys/SystemInformation.hxx.in +++ b/Source/kwsys/SystemInformation.hxx.in @@ -24,14 +24,22 @@ namespace @KWSYS_NAMESPACE@ { - -// forward declare the implementation class +// forward declare the implementation class class SystemInformationImplementation; - -class @KWSYS_NAMESPACE@_EXPORT SystemInformation -{ +class @KWSYS_NAMESPACE@_EXPORT SystemInformation +{ +#if @KWSYS_USE_LONG_LONG@ + typedef long long LongLong; +#elif @KWSYS_USE___INT64@ + typedef __int64 LongLong; +#else +# error "No Long Long" +#endif + friend class SystemInformationImplementation; + SystemInformationImplementation* Implementation; public: + SystemInformation (); ~SystemInformation (); @@ -40,6 +48,7 @@ public: kwsys_stl::string GetTypeID(); kwsys_stl::string GetFamilyID(); kwsys_stl::string GetModelID(); + kwsys_stl::string GetModelName(); kwsys_stl::string GetSteppingCode(); const char * GetExtendedProcessorName(); const char * GetProcessorSerialNumber(); @@ -49,13 +58,27 @@ public: int GetProcessorAPICID(); int GetProcessorCacheXSize(long int); bool DoesCPUSupportFeature(long int); - - const char * GetOSName(); + + // returns an informative general description of the cpu + // on this system. + kwsys_stl::string GetCPUDescription(); + const char * GetHostname(); + kwsys_stl::string GetFullyQualifiedDomainName(); + + const char * GetOSName(); const char * GetOSRelease(); const char * GetOSVersion(); const char * GetOSPlatform(); + int GetOSIsWindows(); + int GetOSIsLinux(); + int GetOSIsApple(); + + // returns an informative general description of the os + // on this system. + kwsys_stl::string GetOSDescription(); + bool Is64Bits(); unsigned int GetNumberOfLogicalCPU(); // per physical cpu @@ -63,20 +86,62 @@ public: bool DoesCPUSupportCPUID(); + // Retrieve id of the current running process + LongLong GetProcessId(); + // Retrieve memory information in megabyte. size_t GetTotalVirtualMemory(); size_t GetAvailableVirtualMemory(); size_t GetTotalPhysicalMemory(); - size_t GetAvailablePhysicalMemory(); + size_t GetAvailablePhysicalMemory(); + + // returns an informative general description if the installed and + // available ram on this system. See the GetHostMmeoryTotal, and + // Get{Host,Proc}MemoryAvailable methods for more information. + kwsys_stl::string GetMemoryDescription( + const char *hostLimitEnvVarName=NULL, + const char *procLimitEnvVarName=NULL); + + // Retrieve amount of physical memory installed on the system in KiB + // units. + LongLong GetHostMemoryTotal(); + + // Get total system RAM in units of KiB available colectivley to all + // processes in a process group. An example of a process group + // are the processes comprising an mpi program which is running in + // parallel. The amount of memory reported may differ from the host + // total if a host wide resource limit is applied. Such reource limits + // are reported to us via an applicaiton specified environment variable. + LongLong GetHostMemoryAvailable(const char *hostLimitEnvVarName=NULL); + + // Get total system RAM in units of KiB available to this process. + // This may differ from the host available if a per-process resource + // limit is applied. per-process memory limits are applied on unix + // system via rlimit api. Resource limits that are not imposed via + // rlimit api may be reported to us via an application specified + // environment variable. + LongLong GetProcMemoryAvailable( + const char *hostLimitEnvVarName=NULL, + const char *procLimitEnvVarName=NULL); + + // Get the system RAM used by all processes on the host, in units of KiB. + LongLong GetHostMemoryUsed(); + + // Get system RAM used by this process id in units of KiB. + LongLong GetProcMemoryUsed(); + + // enable/disable stack trace signal handler. In order to + // produce an informative stack trace the application should + // be dynamically linked and compiled with debug symbols. + static + void SetStackTraceOnError(int enable); /** Run the different checks */ void RunCPUCheck(); void RunOSCheck(); void RunMemoryCheck(); -private: - SystemInformationImplementation* Implementation; - }; + } // namespace @KWSYS_NAMESPACE@ /* Undefine temporary macros. */ diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index 66850e9..085d988 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -1665,7 +1665,7 @@ kwsys_stl::string SystemTools::EscapeChars( kwsys_stl::string n; if (str) { - if (!chars_to_escape | !*chars_to_escape) + if (!chars_to_escape || !*chars_to_escape) { n.append(str); } diff --git a/Source/kwsys/kwsysPlatformTestsCXX.cxx b/Source/kwsys/kwsysPlatformTestsCXX.cxx index 7b73d06..ae58703 100644 --- a/Source/kwsys/kwsysPlatformTestsCXX.cxx +++ b/Source/kwsys/kwsysPlatformTestsCXX.cxx @@ -358,6 +358,30 @@ int main() } #endif +#ifdef TEST_KWSYS_IOS_HAS_ISTREAM___INT64 +int test_istream(kwsys_ios::istream& is, __int64& x) +{ + return (is >> x)? 1:0; +} +int main() +{ + __int64 x = 0; + return test_istream(kwsys_ios::cin, x); +} +#endif + +#ifdef TEST_KWSYS_IOS_HAS_OSTREAM___INT64 +int test_ostream(kwsys_ios::ostream& os, __int64 x) +{ + return (os << x)? 1:0; +} +int main() +{ + __int64 x = 0; + return test_ostream(kwsys_ios::cout, x); +} +#endif + #ifdef TEST_KWSYS_CHAR_IS_SIGNED /* Return 0 for char signed and 1 for char unsigned. */ int main() @@ -428,6 +452,48 @@ int main() } #endif +#ifdef TEST_KWSYS_CXX_HAS_RLIMIT64 +# if defined(KWSYS_HAS_LFS) +# define _LARGEFILE_SOURCE +# define _LARGEFILE64_SOURCE +# define _LARGE_FILES +# define _FILE_OFFSET_BITS 64 +# endif +# include <sys/resource.h> +int main() +{ + struct rlimit64 rlim; + return getrlimit64(0,&rlim); +} +#endif + +#ifdef TEST_KWSYS_CXX_HAS_ATOLL +#include <stdlib.h> +int main() +{ + const char *str="1024"; + return static_cast<int>(atoll(str)); +} +#endif + +#ifdef TEST_KWSYS_CXX_HAS_ATOL +#include <stdlib.h> +int main() +{ + const char *str="1024"; + return static_cast<int>(atol(str)); +} +#endif + +#ifdef TEST_KWSYS_CXX_HAS__ATOI64 +#include <stdlib.h> +int main() +{ + const char *str="1024"; + return static_cast<int>(_atoi64(str)); +} +#endif + #ifdef TEST_KWSYS_CXX_TYPE_INFO /* Collect fundamental type information and save it to a CMake script. */ diff --git a/Source/kwsys/testSystemInformation.cxx b/Source/kwsys/testSystemInformation.cxx index b3afc9d..41fcf38 100644 --- a/Source/kwsys/testSystemInformation.cxx +++ b/Source/kwsys/testSystemInformation.cxx @@ -13,8 +13,6 @@ #include KWSYS_HEADER(SystemInformation.hxx) #include KWSYS_HEADER(ios/iostream) - - // Work-around CMake dependency scanning limitation. This must // duplicate the above list of headers. #if 0 @@ -22,12 +20,31 @@ # include "kwsys_ios_iostream.h.in" #endif -#define printMethod(inof, m) kwsys_ios::cout << #m << ": " \ +#if defined(KWSYS_USE_LONG_LONG) +# if defined(KWSYS_IOS_HAS_OSTREAM_LONG_LONG) +# define iostreamLongLong(x) (x) +# else +# define iostreamLongLong(x) ((long)x) +# endif +#elif defined(KWSYS_USE___INT64) +# if defined(KWSYS_IOS_HAS_OSTREAM___INT64) +# define iostreamLongLong(x) (x) +# else +# define iostreamLongLong(x) ((long)x) +# endif +#else +# error "No Long Long" +#endif + +#define printMethod(info, m) kwsys_ios::cout << #m << ": " \ << info.m() << "\n" -#define printMethod2(inof, m, unit) kwsys_ios::cout << #m << ": " \ +#define printMethod2(info, m, unit) kwsys_ios::cout << #m << ": " \ << info.m() << " " << unit << "\n" +#define printMethod3(info, m, unit) kwsys_ios::cout << #m << ": " \ +<< iostreamLongLong(info.m) << " " << unit << "\n" + int testSystemInformation(int, char*[]) { kwsys::SystemInformation info; @@ -35,7 +52,11 @@ int testSystemInformation(int, char*[]) info.RunOSCheck(); info.RunMemoryCheck(); printMethod(info, GetOSName); + printMethod(info, GetOSIsLinux); + printMethod(info, GetOSIsApple); + printMethod(info, GetOSIsWindows); printMethod(info, GetHostname); + printMethod(info, GetFullyQualifiedDomainName); printMethod(info, GetOSRelease); printMethod(info, GetOSVersion); printMethod(info, GetOSPlatform); @@ -58,6 +79,11 @@ int testSystemInformation(int, char*[]) printMethod2(info, GetAvailableVirtualMemory, "MB"); printMethod2(info, GetTotalPhysicalMemory, "MB"); printMethod2(info, GetAvailablePhysicalMemory, "MB"); + printMethod3(info, GetHostMemoryTotal(), "KiB"); + printMethod3(info, GetHostMemoryAvailable("KWSHL"), "KiB"); + printMethod3(info, GetProcMemoryAvailable("KWSHL","KWSPL"), "KiB"); + printMethod3(info, GetHostMemoryUsed(), "KiB"); + printMethod3(info, GetProcMemoryUsed(), "KiB"); //int GetProcessorCacheXSize(long int); // bool DoesCPUSupportFeature(long int); |