diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..d1638636 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100755 index 00000000..8139052d --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,49 @@ +# set minimum cmake version +cmake_minimum_required(VERSION 3.10 FATAL_ERROR) + +# project name and language +project(recipe-05 LANGUAGES CXX) + +# define executable +add_executable(processor-info "") + +# and its source file +target_sources(processor-info + PRIVATE + processor-info.cpp + ) + +# and its include directories +target_include_directories(processor-info + PRIVATE + ${PROJECT_BINARY_DIR} + ) + +foreach(key + IN ITEMS + NUMBER_OF_LOGICAL_CORES + NUMBER_OF_PHYSICAL_CORES + TOTAL_VIRTUAL_MEMORY + AVAILABLE_VIRTUAL_MEMORY + TOTAL_PHYSICAL_MEMORY + AVAILABLE_PHYSICAL_MEMORY + IS_64BIT + HAS_FPU + HAS_MMX + HAS_MMX_PLUS + HAS_SSE + HAS_SSE2 + HAS_SSE_FP + HAS_SSE_MMX + HAS_AMD_3DNOW + HAS_AMD_3DNOW_PLUS + HAS_IA64 + OS_NAME + OS_RELEASE + OS_VERSION + OS_PLATFORM + ) + cmake_host_system_information(RESULT _${key} QUERY ${key}) +endforeach() + +configure_file(config.h.in config.h @ONLY) diff --git a/config.h.in b/config.h.in new file mode 100755 index 00000000..45bb0b96 --- /dev/null +++ b/config.h.in @@ -0,0 +1,23 @@ +#pragma once + +#define NUMBER_OF_LOGICAL_CORES @_NUMBER_OF_LOGICAL_CORES@ +#define NUMBER_OF_PHYSICAL_CORES @_NUMBER_OF_PHYSICAL_CORES@ +#define TOTAL_VIRTUAL_MEMORY @_TOTAL_VIRTUAL_MEMORY@ +#define AVAILABLE_VIRTUAL_MEMORY @_AVAILABLE_VIRTUAL_MEMORY@ +#define TOTAL_PHYSICAL_MEMORY @_TOTAL_PHYSICAL_MEMORY@ +#define AVAILABLE_PHYSICAL_MEMORY @_AVAILABLE_PHYSICAL_MEMORY@ +#define IS_64BIT @_IS_64BIT@ +#define HAS_FPU @_HAS_FPU@ +#define HAS_MMX @_HAS_MMX@ +#define HAS_MMX_PLUS @_HAS_MMX_PLUS@ +#define HAS_SSE @_HAS_SSE@ +#define HAS_SSE2 @_HAS_SSE2@ +#define HAS_SSE_FP @_HAS_SSE_FP@ +#define HAS_SSE_MMX @_HAS_SSE_MMX@ +#define HAS_AMD_3DNOW @_HAS_AMD_3DNOW@ +#define HAS_AMD_3DNOW_PLUS @_HAS_AMD_3DNOW_PLUS@ +#define HAS_IA64 @_HAS_IA64@ +#define OS_NAME "@_OS_NAME@" +#define OS_RELEASE "@_OS_RELEASE@" +#define OS_VERSION "@_OS_VERSION@" +#define OS_PLATFORM "@_OS_PLATFORM@" diff --git a/processor-info.cpp b/processor-info.cpp new file mode 100755 index 00000000..28edb765 --- /dev/null +++ b/processor-info.cpp @@ -0,0 +1,41 @@ +#include "config.h" + +#include +#include + +int main() { + std::cout << "Number of logical cores: " << NUMBER_OF_LOGICAL_CORES << std::endl; + std::cout << "Number of physical cores: " << NUMBER_OF_PHYSICAL_CORES << std::endl; + + std::cout << "Total virtual memory in megabytes: " << TOTAL_VIRTUAL_MEMORY + << std::endl; + std::cout << "Available virtual memory in megabytes: " << AVAILABLE_VIRTUAL_MEMORY + << std::endl; + std::cout << "Total physical memory in megabytes: " << TOTAL_PHYSICAL_MEMORY + << std::endl; + std::cout << "Available physical memory in megabytes: " + << AVAILABLE_PHYSICAL_MEMORY << std::endl; + + std::cout << "Processor is 64Bit: " << IS_64BIT << std::endl; + std::cout << "Processor has floating point unit: " << HAS_FPU << std::endl; + std::cout << "Processor supports MMX instructions: " << HAS_MMX << std::endl; + std::cout << "Processor supports Ext. MMX instructions: " << HAS_MMX_PLUS + << std::endl; + std::cout << "Processor supports SSE instructions: " << HAS_SSE << std::endl; + std::cout << "Processor supports SSE2 instructions: " << HAS_SSE2 << std::endl; + std::cout << "Processor supports SSE FP instructions: " << HAS_SSE_FP << std::endl; + std::cout << "Processor supports SSE MMX instructions: " << HAS_SSE_MMX + << std::endl; + std::cout << "Processor supports 3DNow instructions: " << HAS_AMD_3DNOW + << std::endl; + std::cout << "Processor supports 3DNow+ instructions: " << HAS_AMD_3DNOW_PLUS + << std::endl; + std::cout << "IA64 processor emulating x86 : " << HAS_IA64 << std::endl; + + std::cout << "OS name: " << OS_NAME << std::endl; + std::cout << "OS sub-type: " << OS_RELEASE << std::endl; + std::cout << "OS build ID: " << OS_VERSION << std::endl; + std::cout << "OS platform: " << OS_PLATFORM << std::endl; + + return EXIT_SUCCESS; +}