2024-06-30 11:42:24 +00:00
# libcpuid
libcpuid provides CPU identification. Supported CPU architectures are:
- x86:
- 32-bit CPUs (IA-32, also known as i386, i486, i586 and i686)
2024-06-30 11:50:35 +00:00
- 64-bit CPUs (x86_64, also known as x64, AMD64, and Intel 64)
- ARM (since v0.7.0):
2024-06-30 11:42:24 +00:00
- 64-bit CPUs (ARM64, also known as AArch64)
2015-11-03 23:28:44 +00:00
2020-05-09 15:34:07 +00:00
For details about the programming API, you might want to
2016-05-22 20:35:30 +00:00
take a look at the project's website on sourceforge
2024-07-01 07:46:13 +00:00
(https://libcpuid.sourceforge.net). There you'd find a short
[tutorial ](https://libcpuid.sourceforge.net/documentation.html ), as well
as the full [API reference ](https://anrieff.github.io/libcpuid ).
2015-11-03 23:28:44 +00:00
2024-06-30 11:42:24 +00:00
## Getting started
2015-11-03 23:28:44 +00:00
2024-06-30 11:42:24 +00:00
You have two ways to get libcpuid:
- build it from sources
- download a pre-compiled binary
2015-11-03 23:28:44 +00:00
2024-06-30 11:42:24 +00:00
### Sources
2015-11-03 23:28:44 +00:00
2024-06-30 11:42:24 +00:00
#### Prerequisites
2018-04-16 07:45:15 +00:00
Using libcpuid requires no dependencies on any of the supported OSes.
2024-06-30 11:42:24 +00:00
Building it requires build tool commands to be available,
which is a matter of installing a few common packages
with related names (e.g. automake, autoconf, libtool, cmake).
2018-04-16 07:45:15 +00:00
It also requires a POSIX-compatible shell. On NetBSD, you may need
to install one (credits to @brucelilly ):
1. Install a POSIX-compatible shell such as ksh93
2024-06-30 11:42:24 +00:00
```shell
pkg_add ast-ksh || pkgin in ast-ksh
```
2. Export `CONFIG_SHELL` with correct path if required:
```shell
export CONFIG_SHELL=/usr/pkg/bin/ksh93
2022-09-15 16:37:08 +00:00
```
2024-06-30 11:42:24 +00:00
#### Configuring after checkout
2016-04-19 10:38:41 +00:00
2024-06-30 11:42:24 +00:00
Two build systems are supported, use the one you prefer.
2015-11-03 23:28:44 +00:00
2024-06-30 11:42:24 +00:00
##### By using autotools
2015-11-03 23:28:44 +00:00
2024-06-30 11:42:24 +00:00
Under POSIX systems, where you download the sources, there's no
configure script to run. This is because it isn't a good practice to keep
such scripts in a source control system. To create it, you need to run the
following commands once, after you checkout the libcpuid sources
from GitHub:
```shell
libtoolize
autoreconf --install
```
2015-11-03 23:28:44 +00:00
2024-06-30 11:42:24 +00:00
You need to have `autoconf` , `automake` and `libtool` installed.
After that you can run `./configure` and `make` - this will build
the library.
`make dist` will create a tarball (with "configure" inside) with the
sources.
##### By using CMake
2024-07-10 18:56:38 +00:00
CMake options for libcpuid (use `cmake -LH` to list all options):
- `LIBCPUID_ENABLE_DOCS` : enable building documentation by using Doxyen (**ON** by default)
- `LIBCPUID_ENABLE_TESTS` : enable tests targets, like `test-fast` , `test-old` and `fix-tests` (**OFF** by default)
- `LIBCPUID_BUILD_DEPRECATED` : build support of deprecated attributes (**ON** by default to guarantee backward compatibility)
- `LIBCPUID_BUILD_DRIVERS` : enable building kernel drivers (**ON** by default)
- `LIBCPUID_DRIVER_DEBUG` : enable debug mode flr kernel drivers (**OFF** by default)
- `LIBCPUID_DRIVER_ARM_LINUX_DKMS` : use DKMS for CPUID Linux kernel module for ARM (**ON** by default), switch off to build the kernel module in the `build` directory
2024-06-30 11:42:24 +00:00
Basic example to build and install libcpuid by using CMake:
```shell
2024-07-10 18:56:38 +00:00
cmake -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DLIBCPUID_ENABLE_TESTS=ON
2024-06-30 11:42:24 +00:00
cmake --build build
cmake --install build # may need administrative privileges, install under /usr/local by default
```
2020-05-27 18:49:45 +00:00
2024-06-30 11:42:24 +00:00
### Downloads
2020-05-27 18:49:45 +00:00
You can find latest versioned archives [here ](https://github.com/anrieff/libcpuid/releases/latest ), with binaries for macOS and Windows.
#### Binary packages
Also, libcpuid is available for following systems in official repositories:
2023-11-21 07:45:34 +00:00
* [Arch Linux ](https://archlinux.org/packages/extra/x86_64/libcpuid/ ): `pacman -S libcpuid`
2022-08-28 08:40:42 +00:00
* [Debian (since version 11 "Bullseye") ](https://packages.debian.org/source/bullseye/libcpuid ): `apt install cpuidtool libcpuid-dev`
2020-05-27 18:49:45 +00:00
* [Fedora (since version 25) ](https://src.fedoraproject.org/rpms/libcpuid ): `dnf install libcpuid libcpuid-devel`
* [FreeBSD (since version 11) ](https://www.freshports.org/sysutils/libcpuid ): `pkg install libcpuid`
2022-08-28 08:40:42 +00:00
* [OpenMandriva Lx (since version 4.0 "Nitrogen") ](https://github.com/OpenMandrivaAssociation/libcpuid ): `dnf install libcpuid-tools libcpuid-devel`
* [openSUSE Leap (since version 15.1) ](https://software.opensuse.org/package/libcpuid ): `zypper install libcpuid-tools libcpuid-devel`
2020-05-27 18:49:45 +00:00
* [Solus ](https://packages.getsol.us/shannon/libc/libcpuid/ ): `eopkg install libcpuid libcpuid-devel`
2022-08-28 08:40:42 +00:00
* [Ubuntu (since version 20.04 "Focal Fossa") ](https://packages.ubuntu.com/source/focal/libcpuid ) : `apt install cpuidtool libcpuid-dev`
2020-05-27 18:49:45 +00:00
2022-10-27 19:17:32 +00:00
Below, the full lists of repositories:
2022-10-27 19:15:31 +00:00
[![Packaging status ](https://repology.org/badge/vertical-allrepos/libcpuid.svg?exclude_unsupported=1 )](https://repology.org/project/libcpuid/versions)
2020-05-27 18:49:45 +00:00
#### Build tool
* Vcpkg: `vcpkg install cpuid`
2024-06-30 11:42:24 +00:00
## Contributing
Refer to the [dedicated page ](CONTRIBUTING.md ).
## Users
So far, I'm aware of the following projects which utilize libcpuid (listed alphabetically):
* CPU-X (https://github.com/TheTumultuousUnicornOfDarkness/CPU-X)
* fre:ac (https://www.freac.org/)
* I-Nex (https://github.com/i-nex/I-Nex)
* Multiprecision Computing Toolbox for MATLAB (https://www.advanpix.com/)
* ucbench (http://anrieff.net/ucbench)
We'd love to hear from you if you are also using libcpuid and want your project listed above.