Skip to content

supdrewin/cpuidpp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CPUID++

C++ wrappers for X86 cpu model detection.

Pre-Request

  • Compiler: g++ / clang++
  • OS: any Unix-like OS is Ok.
  • git
  • cmake
  • pkg-config

First Step, use git to clone this repository:

$ git clone https://github.com/supdrewin/cpuidpp.git
$ cd cpuidpp

Build

$ cmake -S . -B build
$ cmake --build build

Install

This step requests root permission, you need to use sudo or others if you aren't root.

$ cmake --install build

Usage

This is a sample code:

// We need to see output...
#include <iostream>

// All we do just include it.
#include <cpuid++/cpuid.hpp>

int main() {
  // All methods leading with `cpuid` namespace.
  // Then we call `processor_name()` to get a string
  // contains your processor's name.
  std::cout << cpuid::processor_name() << std::endl;

  // We use `check_feature(cpuid::feature)` to check a feature.
  // Then we check if the processor support PAE.
  if (cpuid::check_feature(cpuid::feature::PAE))
    std::cout << "This processor support PAE!" << std::endl;

  return 0;
}

Save it as main.cpp, then we compile and run it:

$ c++ -o sample main.cpp $(pkg-config --libs cpuid++)
$ ./sample

This is a possible output after run it:

Intel(R) Core(TM) XX-XXXXXX CPU @ X.XXGHz
This processor support PAE!

Or using CMake, with previous main.cpp.

Start your new project, we will create a structure like following:

<Project Root>
|_ CMakeLists.txt
|_ main.cpp

Minimized CMakeLists.txt:

# `pkg_check_modules()`'s `IMPORTED_TARGET` request 3.6.
cmake_minimum_required ( VERSION 3.6 )

# Replace `project_name` to your own project name.
project ( project_name CXX )

# Request the `PkgConfig` package.
find_package ( PkgConfig REQUIRED )

# Import `cpuid++` as `CPUID++` so we can call `PkgConfig::CPUID++`.
pkg_check_modules ( CPUID++ REQUIRED IMPORTED_TARGET cpuid++ )


# Add your executable, replace `target_name`.
add_executable ( target_name
  # Add your source files here.
  main.cpp
)

# Link the library using `PkgConfig::CPUID++` we previous imported.
target_link_libraries ( target_name PRIVATE PkgConfig::CPUID++ )

We have added main.cpp to CMakeLists.txt.

Everything is Ok now, then we build it.

Do this from your project root:

$ cmake -S . -B build # src dir is current dir, build dir is `build`
$ cmake --build build # use cmake to build the `build` dir

Then we run the program:

$ build/target_name # If you replace the `target_name` previous,
                    # replacing it here together.

Bugs

If you have any issues, Open issues here.

Also, Pull requests is welcome!

About

C++ wrappers for X86 cpu model detection.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published