mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-16 22:37:30 +08:00
cmCommand refactor: cmCMakeHostSystemInformationCommand
This commit is contained in:
@@ -3,7 +3,9 @@
|
|||||||
#include "cmCMakeHostSystemInformationCommand.h"
|
#include "cmCMakeHostSystemInformationCommand.h"
|
||||||
|
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include "cmExecutionStatus.h"
|
||||||
#include "cmMakefile.h"
|
#include "cmMakefile.h"
|
||||||
#include "cmsys/SystemInformation.hxx"
|
#include "cmsys/SystemInformation.hxx"
|
||||||
|
|
||||||
@@ -16,16 +18,22 @@
|
|||||||
# define HAVE_VS_SETUP_HELPER
|
# define HAVE_VS_SETUP_HELPER
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class cmExecutionStatus;
|
namespace {
|
||||||
|
bool GetValue(cmExecutionStatus& status, cmsys::SystemInformation& info,
|
||||||
|
std::string const& key, std::string& value);
|
||||||
|
std::string ValueToString(size_t value);
|
||||||
|
std::string ValueToString(const char* value);
|
||||||
|
std::string ValueToString(std::string const& value);
|
||||||
|
}
|
||||||
|
|
||||||
// cmCMakeHostSystemInformation
|
// cmCMakeHostSystemInformation
|
||||||
bool cmCMakeHostSystemInformationCommand::InitialPass(
|
bool cmCMakeHostSystemInformationCommand(std::vector<std::string> const& args,
|
||||||
std::vector<std::string> const& args, cmExecutionStatus&)
|
cmExecutionStatus& status)
|
||||||
{
|
{
|
||||||
size_t current_index = 0;
|
size_t current_index = 0;
|
||||||
|
|
||||||
if (args.size() < (current_index + 2) || args[current_index] != "RESULT") {
|
if (args.size() < (current_index + 2) || args[current_index] != "RESULT") {
|
||||||
this->SetError("missing RESULT specification.");
|
status.SetError("missing RESULT specification.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -33,7 +41,7 @@ bool cmCMakeHostSystemInformationCommand::InitialPass(
|
|||||||
current_index += 2;
|
current_index += 2;
|
||||||
|
|
||||||
if (args.size() < (current_index + 2) || args[current_index] != "QUERY") {
|
if (args.size() < (current_index + 2) || args[current_index] != "QUERY") {
|
||||||
this->SetError("missing QUERY specification");
|
status.SetError("missing QUERY specification");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,89 +57,91 @@ bool cmCMakeHostSystemInformationCommand::InitialPass(
|
|||||||
result_list += ";";
|
result_list += ";";
|
||||||
}
|
}
|
||||||
std::string value;
|
std::string value;
|
||||||
if (!this->GetValue(info, key, value)) {
|
if (!GetValue(status, info, key, value)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
result_list += value;
|
result_list += value;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->Makefile->AddDefinition(variable, result_list);
|
status.GetMakefile().AddDefinition(variable, result_list);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cmCMakeHostSystemInformationCommand::GetValue(
|
namespace {
|
||||||
cmsys::SystemInformation& info, std::string const& key, std::string& value)
|
|
||||||
|
bool GetValue(cmExecutionStatus& status, cmsys::SystemInformation& info,
|
||||||
|
std::string const& key, std::string& value)
|
||||||
{
|
{
|
||||||
if (key == "NUMBER_OF_LOGICAL_CORES") {
|
if (key == "NUMBER_OF_LOGICAL_CORES") {
|
||||||
value = this->ValueToString(info.GetNumberOfLogicalCPU());
|
value = ValueToString(info.GetNumberOfLogicalCPU());
|
||||||
} else if (key == "NUMBER_OF_PHYSICAL_CORES") {
|
} else if (key == "NUMBER_OF_PHYSICAL_CORES") {
|
||||||
value = this->ValueToString(info.GetNumberOfPhysicalCPU());
|
value = ValueToString(info.GetNumberOfPhysicalCPU());
|
||||||
} else if (key == "HOSTNAME") {
|
} else if (key == "HOSTNAME") {
|
||||||
value = this->ValueToString(info.GetHostname());
|
value = ValueToString(info.GetHostname());
|
||||||
} else if (key == "FQDN") {
|
} else if (key == "FQDN") {
|
||||||
value = this->ValueToString(info.GetFullyQualifiedDomainName());
|
value = ValueToString(info.GetFullyQualifiedDomainName());
|
||||||
} else if (key == "TOTAL_VIRTUAL_MEMORY") {
|
} else if (key == "TOTAL_VIRTUAL_MEMORY") {
|
||||||
value = this->ValueToString(info.GetTotalVirtualMemory());
|
value = ValueToString(info.GetTotalVirtualMemory());
|
||||||
} else if (key == "AVAILABLE_VIRTUAL_MEMORY") {
|
} else if (key == "AVAILABLE_VIRTUAL_MEMORY") {
|
||||||
value = this->ValueToString(info.GetAvailableVirtualMemory());
|
value = ValueToString(info.GetAvailableVirtualMemory());
|
||||||
} else if (key == "TOTAL_PHYSICAL_MEMORY") {
|
} else if (key == "TOTAL_PHYSICAL_MEMORY") {
|
||||||
value = this->ValueToString(info.GetTotalPhysicalMemory());
|
value = ValueToString(info.GetTotalPhysicalMemory());
|
||||||
} else if (key == "AVAILABLE_PHYSICAL_MEMORY") {
|
} else if (key == "AVAILABLE_PHYSICAL_MEMORY") {
|
||||||
value = this->ValueToString(info.GetAvailablePhysicalMemory());
|
value = ValueToString(info.GetAvailablePhysicalMemory());
|
||||||
} else if (key == "IS_64BIT") {
|
} else if (key == "IS_64BIT") {
|
||||||
value = this->ValueToString(info.Is64Bits());
|
value = ValueToString(info.Is64Bits());
|
||||||
} else if (key == "HAS_FPU") {
|
} else if (key == "HAS_FPU") {
|
||||||
value = this->ValueToString(
|
value = ValueToString(
|
||||||
info.DoesCPUSupportFeature(cmsys::SystemInformation::CPU_FEATURE_FPU));
|
info.DoesCPUSupportFeature(cmsys::SystemInformation::CPU_FEATURE_FPU));
|
||||||
} else if (key == "HAS_MMX") {
|
} else if (key == "HAS_MMX") {
|
||||||
value = this->ValueToString(
|
value = ValueToString(
|
||||||
info.DoesCPUSupportFeature(cmsys::SystemInformation::CPU_FEATURE_MMX));
|
info.DoesCPUSupportFeature(cmsys::SystemInformation::CPU_FEATURE_MMX));
|
||||||
} else if (key == "HAS_MMX_PLUS") {
|
} else if (key == "HAS_MMX_PLUS") {
|
||||||
value = this->ValueToString(info.DoesCPUSupportFeature(
|
value = ValueToString(info.DoesCPUSupportFeature(
|
||||||
cmsys::SystemInformation::CPU_FEATURE_MMX_PLUS));
|
cmsys::SystemInformation::CPU_FEATURE_MMX_PLUS));
|
||||||
} else if (key == "HAS_SSE") {
|
} else if (key == "HAS_SSE") {
|
||||||
value = this->ValueToString(
|
value = ValueToString(
|
||||||
info.DoesCPUSupportFeature(cmsys::SystemInformation::CPU_FEATURE_SSE));
|
info.DoesCPUSupportFeature(cmsys::SystemInformation::CPU_FEATURE_SSE));
|
||||||
} else if (key == "HAS_SSE2") {
|
} else if (key == "HAS_SSE2") {
|
||||||
value = this->ValueToString(
|
value = ValueToString(
|
||||||
info.DoesCPUSupportFeature(cmsys::SystemInformation::CPU_FEATURE_SSE2));
|
info.DoesCPUSupportFeature(cmsys::SystemInformation::CPU_FEATURE_SSE2));
|
||||||
} else if (key == "HAS_SSE_FP") {
|
} else if (key == "HAS_SSE_FP") {
|
||||||
value = this->ValueToString(info.DoesCPUSupportFeature(
|
value = ValueToString(info.DoesCPUSupportFeature(
|
||||||
cmsys::SystemInformation::CPU_FEATURE_SSE_FP));
|
cmsys::SystemInformation::CPU_FEATURE_SSE_FP));
|
||||||
} else if (key == "HAS_SSE_MMX") {
|
} else if (key == "HAS_SSE_MMX") {
|
||||||
value = this->ValueToString(info.DoesCPUSupportFeature(
|
value = ValueToString(info.DoesCPUSupportFeature(
|
||||||
cmsys::SystemInformation::CPU_FEATURE_SSE_MMX));
|
cmsys::SystemInformation::CPU_FEATURE_SSE_MMX));
|
||||||
} else if (key == "HAS_AMD_3DNOW") {
|
} else if (key == "HAS_AMD_3DNOW") {
|
||||||
value = this->ValueToString(info.DoesCPUSupportFeature(
|
value = ValueToString(info.DoesCPUSupportFeature(
|
||||||
cmsys::SystemInformation::CPU_FEATURE_AMD_3DNOW));
|
cmsys::SystemInformation::CPU_FEATURE_AMD_3DNOW));
|
||||||
} else if (key == "HAS_AMD_3DNOW_PLUS") {
|
} else if (key == "HAS_AMD_3DNOW_PLUS") {
|
||||||
value = this->ValueToString(info.DoesCPUSupportFeature(
|
value = ValueToString(info.DoesCPUSupportFeature(
|
||||||
cmsys::SystemInformation::CPU_FEATURE_AMD_3DNOW_PLUS));
|
cmsys::SystemInformation::CPU_FEATURE_AMD_3DNOW_PLUS));
|
||||||
} else if (key == "HAS_IA64") {
|
} else if (key == "HAS_IA64") {
|
||||||
value = this->ValueToString(
|
value = ValueToString(
|
||||||
info.DoesCPUSupportFeature(cmsys::SystemInformation::CPU_FEATURE_IA64));
|
info.DoesCPUSupportFeature(cmsys::SystemInformation::CPU_FEATURE_IA64));
|
||||||
} else if (key == "HAS_SERIAL_NUMBER") {
|
} else if (key == "HAS_SERIAL_NUMBER") {
|
||||||
value = this->ValueToString(info.DoesCPUSupportFeature(
|
value = ValueToString(info.DoesCPUSupportFeature(
|
||||||
cmsys::SystemInformation::CPU_FEATURE_SERIALNUMBER));
|
cmsys::SystemInformation::CPU_FEATURE_SERIALNUMBER));
|
||||||
} else if (key == "PROCESSOR_NAME") {
|
} else if (key == "PROCESSOR_NAME") {
|
||||||
value = this->ValueToString(info.GetExtendedProcessorName());
|
value = ValueToString(info.GetExtendedProcessorName());
|
||||||
} else if (key == "PROCESSOR_DESCRIPTION") {
|
} else if (key == "PROCESSOR_DESCRIPTION") {
|
||||||
value = info.GetCPUDescription();
|
value = info.GetCPUDescription();
|
||||||
} else if (key == "PROCESSOR_SERIAL_NUMBER") {
|
} else if (key == "PROCESSOR_SERIAL_NUMBER") {
|
||||||
value = this->ValueToString(info.GetProcessorSerialNumber());
|
value = ValueToString(info.GetProcessorSerialNumber());
|
||||||
} else if (key == "OS_NAME") {
|
} else if (key == "OS_NAME") {
|
||||||
value = this->ValueToString(info.GetOSName());
|
value = ValueToString(info.GetOSName());
|
||||||
} else if (key == "OS_RELEASE") {
|
} else if (key == "OS_RELEASE") {
|
||||||
value = this->ValueToString(info.GetOSRelease());
|
value = ValueToString(info.GetOSRelease());
|
||||||
} else if (key == "OS_VERSION") {
|
} else if (key == "OS_VERSION") {
|
||||||
value = this->ValueToString(info.GetOSVersion());
|
value = ValueToString(info.GetOSVersion());
|
||||||
} else if (key == "OS_PLATFORM") {
|
} else if (key == "OS_PLATFORM") {
|
||||||
value = this->ValueToString(info.GetOSPlatform());
|
value = ValueToString(info.GetOSPlatform());
|
||||||
#ifdef HAVE_VS_SETUP_HELPER
|
#ifdef HAVE_VS_SETUP_HELPER
|
||||||
} else if (key == "VS_15_DIR") {
|
} else if (key == "VS_15_DIR") {
|
||||||
// If generating for the VS 15 IDE, use the same instance.
|
// If generating for the VS 15 IDE, use the same instance.
|
||||||
cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
|
cmGlobalGenerator* gg = status.GetMakefile().GetGlobalGenerator();
|
||||||
if (cmHasLiteralPrefix(gg->GetName(), "Visual Studio 15 ")) {
|
if (cmHasLiteralPrefix(gg->GetName(), "Visual Studio 15 ")) {
|
||||||
cmGlobalVisualStudioVersionedGenerator* vs15gen =
|
cmGlobalVisualStudioVersionedGenerator* vs15gen =
|
||||||
static_cast<cmGlobalVisualStudioVersionedGenerator*>(gg);
|
static_cast<cmGlobalVisualStudioVersionedGenerator*>(gg);
|
||||||
@@ -147,7 +157,7 @@ bool cmCMakeHostSystemInformationCommand::GetValue(
|
|||||||
}
|
}
|
||||||
} else if (key == "VS_16_DIR") {
|
} else if (key == "VS_16_DIR") {
|
||||||
// If generating for the VS 16 IDE, use the same instance.
|
// If generating for the VS 16 IDE, use the same instance.
|
||||||
cmGlobalGenerator* gg = this->Makefile->GetGlobalGenerator();
|
cmGlobalGenerator* gg = status.GetMakefile().GetGlobalGenerator();
|
||||||
if (cmHasLiteralPrefix(gg->GetName(), "Visual Studio 16 ")) {
|
if (cmHasLiteralPrefix(gg->GetName(), "Visual Studio 16 ")) {
|
||||||
cmGlobalVisualStudioVersionedGenerator* vs16gen =
|
cmGlobalVisualStudioVersionedGenerator* vs16gen =
|
||||||
static_cast<cmGlobalVisualStudioVersionedGenerator*>(gg);
|
static_cast<cmGlobalVisualStudioVersionedGenerator*>(gg);
|
||||||
@@ -164,30 +174,28 @@ bool cmCMakeHostSystemInformationCommand::GetValue(
|
|||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
std::string e = "does not recognize <key> " + key;
|
std::string e = "does not recognize <key> " + key;
|
||||||
this->SetError(e);
|
status.SetError(e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string cmCMakeHostSystemInformationCommand::ValueToString(
|
std::string ValueToString(size_t value)
|
||||||
size_t value) const
|
|
||||||
{
|
{
|
||||||
std::ostringstream tmp;
|
std::ostringstream tmp;
|
||||||
tmp << value;
|
tmp << value;
|
||||||
return tmp.str();
|
return tmp.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string cmCMakeHostSystemInformationCommand::ValueToString(
|
std::string ValueToString(const char* value)
|
||||||
const char* value) const
|
|
||||||
{
|
{
|
||||||
std::string safe_string = value ? value : "";
|
std::string safe_string = value ? value : "";
|
||||||
return safe_string;
|
return safe_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string cmCMakeHostSystemInformationCommand::ValueToString(
|
std::string ValueToString(std::string const& value)
|
||||||
std::string const& value) const
|
|
||||||
{
|
{
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
@@ -5,50 +5,18 @@
|
|||||||
|
|
||||||
#include "cmConfigure.h" // IWYU pragma: keep
|
#include "cmConfigure.h" // IWYU pragma: keep
|
||||||
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "cm_memory.hxx"
|
|
||||||
|
|
||||||
#include "cmCommand.h"
|
|
||||||
|
|
||||||
class cmExecutionStatus;
|
class cmExecutionStatus;
|
||||||
namespace cmsys {
|
|
||||||
class SystemInformation;
|
|
||||||
} // namespace cmsys
|
|
||||||
|
|
||||||
/** \class cmCMakeHostSystemInformationCommand
|
/**
|
||||||
* \brief Query host system specific information
|
* \brief Query host system specific information
|
||||||
*
|
*
|
||||||
* cmCMakeHostSystemInformationCommand queries system information of
|
* cmCMakeHostSystemInformationCommand queries system information of
|
||||||
* the system on which CMake runs.
|
* the system on which CMake runs.
|
||||||
*/
|
*/
|
||||||
class cmCMakeHostSystemInformationCommand : public cmCommand
|
bool cmCMakeHostSystemInformationCommand(std::vector<std::string> const& args,
|
||||||
{
|
cmExecutionStatus& status);
|
||||||
public:
|
|
||||||
/**
|
|
||||||
* This is a virtual constructor for the command.
|
|
||||||
*/
|
|
||||||
std::unique_ptr<cmCommand> Clone() override
|
|
||||||
{
|
|
||||||
return cm::make_unique<cmCMakeHostSystemInformationCommand>();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is called when the command is first encountered in
|
|
||||||
* the CMakeLists.txt file.
|
|
||||||
*/
|
|
||||||
bool InitialPass(std::vector<std::string> const& args,
|
|
||||||
cmExecutionStatus& status) override;
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool GetValue(cmsys::SystemInformation& info, std::string const& key,
|
|
||||||
std::string& value);
|
|
||||||
|
|
||||||
std::string ValueToString(size_t value) const;
|
|
||||||
std::string ValueToString(const char* value) const;
|
|
||||||
std::string ValueToString(std::string const& value) const;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -200,9 +200,8 @@ void GetScriptingCommands(cmState* state)
|
|||||||
"match the opening WHILE command.");
|
"match the opening WHILE command.");
|
||||||
|
|
||||||
#if !defined(CMAKE_BOOTSTRAP)
|
#if !defined(CMAKE_BOOTSTRAP)
|
||||||
state->AddBuiltinCommand(
|
state->AddBuiltinCommand("cmake_host_system_information",
|
||||||
"cmake_host_system_information",
|
cmCMakeHostSystemInformationCommand);
|
||||||
cm::make_unique<cmCMakeHostSystemInformationCommand>());
|
|
||||||
state->AddBuiltinCommand("remove", cm::make_unique<cmRemoveCommand>());
|
state->AddBuiltinCommand("remove", cm::make_unique<cmRemoveCommand>());
|
||||||
state->AddBuiltinCommand("variable_watch",
|
state->AddBuiltinCommand("variable_watch",
|
||||||
cm::make_unique<cmVariableWatchCommand>());
|
cm::make_unique<cmVariableWatchCommand>());
|
||||||
|
Reference in New Issue
Block a user