2013-06-15 09:38:23 +04:00
|
|
|
/*============================================================================
|
|
|
|
CMake - Cross Platform Makefile Generator
|
|
|
|
Copyright 2013 Kitware, Inc., Insight Software Consortium
|
|
|
|
|
|
|
|
Distributed under the OSI-approved BSD License (the "License");
|
|
|
|
see accompanying file Copyright.txt for details.
|
|
|
|
|
|
|
|
This software is distributed WITHOUT ANY WARRANTY; without even the
|
|
|
|
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
See the License for more information.
|
|
|
|
============================================================================*/
|
|
|
|
#include "cmCMakeHostSystemInformationCommand.h"
|
|
|
|
|
|
|
|
// cmCMakeHostSystemInformation
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmCMakeHostSystemInformationCommand::InitialPass(
|
|
|
|
std::vector<std::string> const& args, cmExecutionStatus&)
|
2013-06-15 09:38:23 +04:00
|
|
|
{
|
|
|
|
size_t current_index = 0;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args.size() < (current_index + 2) || args[current_index] != "RESULT") {
|
2013-06-15 09:38:23 +04:00
|
|
|
this->SetError("missing RESULT specification.");
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-06-15 09:38:23 +04:00
|
|
|
|
|
|
|
std::string variable = args[current_index + 1];
|
|
|
|
current_index += 2;
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (args.size() < (current_index + 2) || args[current_index] != "QUERY") {
|
2013-06-15 09:38:23 +04:00
|
|
|
this->SetError("missing QUERY specification");
|
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-06-15 09:38:23 +04:00
|
|
|
|
|
|
|
cmsys::SystemInformation info;
|
|
|
|
info.RunCPUCheck();
|
|
|
|
info.RunOSCheck();
|
|
|
|
info.RunMemoryCheck();
|
|
|
|
|
|
|
|
std::string result_list;
|
2016-05-16 17:34:04 +03:00
|
|
|
for (size_t i = current_index + 1; i < args.size(); ++i) {
|
2013-06-15 09:38:23 +04:00
|
|
|
std::string key = args[i];
|
2016-05-16 17:34:04 +03:00
|
|
|
if (i != current_index + 1) {
|
2013-06-15 09:38:23 +04:00
|
|
|
result_list += ";";
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-06-15 09:38:23 +04:00
|
|
|
std::string value;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!this->GetValue(info, key, value))
|
|
|
|
return false;
|
2013-06-15 09:38:23 +04:00
|
|
|
|
|
|
|
result_list += value;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-06-15 09:38:23 +04:00
|
|
|
|
2014-03-11 03:04:11 +04:00
|
|
|
this->Makefile->AddDefinition(variable, result_list.c_str());
|
2013-06-15 09:38:23 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
bool cmCMakeHostSystemInformationCommand::GetValue(
|
|
|
|
cmsys::SystemInformation& info, std::string const& key, std::string& value)
|
2013-06-15 09:38:23 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
if (key == "NUMBER_OF_LOGICAL_CORES") {
|
2013-06-15 09:38:23 +04:00
|
|
|
value = this->ValueToString(info.GetNumberOfLogicalCPU());
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (key == "NUMBER_OF_PHYSICAL_CORES") {
|
2013-06-15 09:38:23 +04:00
|
|
|
value = this->ValueToString(info.GetNumberOfPhysicalCPU());
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (key == "HOSTNAME") {
|
2013-06-15 09:38:23 +04:00
|
|
|
value = this->ValueToString(info.GetHostname());
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (key == "FQDN") {
|
2013-06-15 09:38:23 +04:00
|
|
|
value = this->ValueToString(info.GetFullyQualifiedDomainName());
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (key == "TOTAL_VIRTUAL_MEMORY") {
|
2013-06-15 09:38:23 +04:00
|
|
|
value = this->ValueToString(info.GetTotalVirtualMemory());
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (key == "AVAILABLE_VIRTUAL_MEMORY") {
|
2013-06-15 09:38:23 +04:00
|
|
|
value = this->ValueToString(info.GetAvailableVirtualMemory());
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (key == "TOTAL_PHYSICAL_MEMORY") {
|
2013-06-15 09:38:23 +04:00
|
|
|
value = this->ValueToString(info.GetTotalPhysicalMemory());
|
2016-05-16 17:34:04 +03:00
|
|
|
} else if (key == "AVAILABLE_PHYSICAL_MEMORY") {
|
2013-06-15 09:38:23 +04:00
|
|
|
value = this->ValueToString(info.GetAvailablePhysicalMemory());
|
2016-05-16 17:34:04 +03:00
|
|
|
} else {
|
2013-06-15 09:38:23 +04:00
|
|
|
std::string e = "does not recognize <key> " + key;
|
2014-03-11 03:04:11 +04:00
|
|
|
this->SetError(e);
|
2013-06-15 09:38:23 +04:00
|
|
|
return false;
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2013-06-15 09:38:23 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmCMakeHostSystemInformationCommand::ValueToString(
|
|
|
|
size_t value) const
|
2013-06-15 09:38:23 +04:00
|
|
|
{
|
2016-06-14 23:37:36 +03:00
|
|
|
std::ostringstream tmp;
|
2013-06-15 09:38:23 +04:00
|
|
|
tmp << value;
|
|
|
|
return tmp.str();
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmCMakeHostSystemInformationCommand::ValueToString(
|
|
|
|
const char* value) const
|
2013-06-15 09:38:23 +04:00
|
|
|
{
|
|
|
|
std::string safe_string = value ? value : "";
|
|
|
|
return safe_string;
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string cmCMakeHostSystemInformationCommand::ValueToString(
|
|
|
|
std::string const& value) const
|
2013-06-15 09:38:23 +04:00
|
|
|
{
|
|
|
|
return value;
|
|
|
|
}
|