1 /*============================================================================
2 CMake - Cross Platform Makefile Generator
3 Copyright 2013 Kitware, Inc., Insight Software Consortium
5 Distributed under the OSI-approved BSD License (the "License");
6 see accompanying file Copyright.txt for details.
8 This software is distributed WITHOUT ANY WARRANTY; without even the
9 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License for more information.
11 ============================================================================*/
12 #include "cmCMakeHostSystemInformationCommand.h"
14 #include <cmsys/ios/sstream>
16 // cmCMakeHostSystemInformation
17 bool cmCMakeHostSystemInformationCommand
18 ::InitialPass(std::vector<std::string> const &args, cmExecutionStatus &)
20 size_t current_index = 0;
22 if(args.size() < (current_index + 2) || args[current_index] != "RESULT")
24 this->SetError("missing RESULT specification.");
28 std::string variable = args[current_index + 1];
31 if(args.size() < (current_index + 2) || args[current_index] != "QUERY")
33 this->SetError("missing QUERY specification");
37 cmsys::SystemInformation info;
40 info.RunMemoryCheck();
42 std::string result_list;
43 for(size_t i = current_index + 1; i < args.size(); ++i)
45 std::string key = args[i];
46 if(i != current_index + 1)
51 if(!this->GetValue(info, key, value)) return false;
56 this->Makefile->AddDefinition(variable.c_str(), result_list.c_str());
61 bool cmCMakeHostSystemInformationCommand
62 ::GetValue(cmsys::SystemInformation &info,
63 std::string const& key, std::string &value)
65 if(key == "NUMBER_OF_LOGICAL_CORES")
67 value = this->ValueToString(info.GetNumberOfLogicalCPU());
69 else if(key == "NUMBER_OF_PHYSICAL_CORES")
71 value = this->ValueToString(info.GetNumberOfPhysicalCPU());
73 else if(key == "HOSTNAME")
75 value = this->ValueToString(info.GetHostname());
77 else if(key == "FQDN")
79 value = this->ValueToString(info.GetFullyQualifiedDomainName());
81 else if(key == "TOTAL_VIRTUAL_MEMORY")
83 value = this->ValueToString(info.GetTotalVirtualMemory());
85 else if(key == "AVAILABLE_VIRTUAL_MEMORY")
87 value = this->ValueToString(info.GetAvailableVirtualMemory());
89 else if(key == "TOTAL_PHYSICAL_MEMORY")
91 value = this->ValueToString(info.GetTotalPhysicalMemory());
93 else if(key == "AVAILABLE_PHYSICAL_MEMORY")
95 value = this->ValueToString(info.GetAvailablePhysicalMemory());
99 std::string e = "does not recognize <key> " + key;
100 this->SetError(e.c_str());
107 std::string cmCMakeHostSystemInformationCommand
108 ::ValueToString(size_t value) const
110 cmsys_ios::stringstream tmp;
115 std::string cmCMakeHostSystemInformationCommand
116 ::ValueToString(const char *value) const
118 std::string safe_string = value ? value : "";
122 std::string cmCMakeHostSystemInformationCommand
123 ::ValueToString(std::string const& value) const