hwinfo

repository·main·Indexed 20 days ago

https://github.com/lfreist/hwinfo

A modern C++ library providing an API to retrieve hardware information for CPU, RAM, GPU, Disks, and other system components across Linux, macOS, and Windows.

Tokens
1.4K
Snippets
6
Records
7
Agent score
22%

What's inside hwinfo

  1. Supported hardware components and platform availability

    main

    The library provides information for various hardware components. Note that some features are marked with ❌ and are currently in development.

    ComponentInfoLinuxAppleWindows
    CPUVendor, Model, Physical/Logical Cores, Cache Size✔️✔️✔️
    Frequency✔️✔️
    GPUVendor, Model✔️✔️
    Memory Size✔️
    Memory (RAM)Vendor, Model, Name, Serial, Total/Free Size✔️
    MainboardVendor, Model, Version, Serial-Number✔️✔️✔️
    Bios
    DiskVendor, Model, Serial, Size, Free Size, Volumes✔️✔️✔️
    OSName, Short Name, Version, Kernel, Arch, Endianess✔️✔️✔️
    BatteryVendor, Model, Serial, Technology, Capacity, Charging✔️
  2. Build hwinfo from source

    main

    To build hwinfo from source, you need git, cmake, and a C++ compiler (gcc, clang, or MSVC). This process builds both static and dynamic libraries. Static library CMake targets are named <target>_static (e.g., hwinfo_static).

    git clone https://github.com/lfreist/hwinfo
    mkdir build
    cmake -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_CONFIGURATION_TYPES=Release
    cmake --build build --config Release
  3. Include hwinfo in a CMake project via installed version

    main

    If you have installed hwinfo to your system, follow these steps to integrate it into your project:

    1. Install hwinfo:
    git clone https://github.com/lfreist/hwinfo && cd hwinfo
    mkdir build
    cmake -B build && cmake --build build
    cmake --install build
    1. Configure CMakeLists.txt: Use find_package to locate the library:
    find_package(hwinfo REQUIRED)
    1. Link the library: Link against the lfreist-hwinfo::hwinfo target:
    add_executable(your_executable your_executable.cpp)
    target_link_libraries(your_executable PUBLIC lfreist-hwinfo::hwinfo)
    1. Include the header in your C++ code:
    #include <hwinfo/hwinfo.h>
    find_package(hwinfo REQUIRED)
    
    add_executable(your_executable your_executable.cpp)
    target_link_libraries(your_executable PUBLIC lfreist-hwinfo::hwinfo)
  4. Include hwinfo in a CMake project as a git submodule

    main

    To include hwinfo directly as a submodule within your project:

    1. Add the submodule:
    mkdir third_party
    cd third_party
    git clone https://github.com/lfreist/hwinfo
    1. Configure your root CMakeLists.txt: Use add_subdirectory to include the submodule. You can define HWINFO_* options before this call to change default values.
    # <project-root>/CMakeLists.txt
    add_subdirectory(third_party/hwinfo)
    1. Link the library:
    add_executable(your_executable your_executable.cpp)
    target_link_libraries(your_executable PUBLIC lfreist-hwinfo::hwinfo)
    1. Include the header in your C++ code:
    #include "hwinfo/hwinfo.h"
    # <project-root>/CMakeLists.txt
    add_subdirectory(third_party/hwinfo)
    
    add_executable(your_executable your_executable.cpp)
    target_link_libraries(your_executable PUBLIC lfreist-hwinfo::hwinfo)
  5. Configure hwinfo build options via CMake

    main

    You can control which hardware components are included in the library by setting the following CMake options. By default, most are set to ON.

    # Example of disabling specific components
    set(HWINFO_OS OFF CACHE BOOL "")
    set(HWINFO_CPU ON CACHE BOOL "")
    set(HWINFO_GPU_OPENCL ON CACHE BOOL "")
  6. Reference: hwinfo CMake build options

    main

    The following CMake options control component detection during the build process:

    HWINFO_OS             - Enable OS detection (default: ON)
    HWINFO_MAINBOARD      - Enable mainboard detection (default: ON)
    HWINFO_CPU            - Enable CPU detection (default: ON)
    HWINFO_DISK           - Enable disk detection (default: ON)
    HWINFO_RAM            - Enable RAM detection (default: ON)
    HWINFO_GPU            - Enable GPU detection (default: ON)
    HWINFO_GPU_OPENCL    - Enable usage of OpenCL in GPU information (default: OFF)
    HWINFO_BATTERY        - Enable battery detection (default: ON)
  7. Reference: hwinfo CMake targets

    main

    You can link against the full library or specific component targets to reduce dependencies.

    # Link everything
    target_link_libraries(your_target PRIVATE hwinfo::hwinfo)
    
    # Link specific components
    target_link_libraries(
      your_target
      PRIVATE hwinfo::cpu
              hwinfo::gpu
              hwinfo::ram
              hwinfo::mainboard
              hwinfo::disk
              hwinfo::os
              hwinfo::battery)