mirror of
https://github.com/shadps4-emu/ext-hwinfo.git
synced 2026-01-31 00:55:22 +01:00
feat: make hwinfo features modular (#98)
* feat: make hwinfo features modular * fix: use the latest available C++ standard * fix!: deprecate NO_OCL in favour of HWINFO_GPU_OPENCL * doc: add docs for the modular targets/options * fix: add preprocessor feature guards * ci: test build of all features in ci * fix: detect C++ standard after enabling C++ language
This commit is contained in:
11
.github/workflows/build-linux-clang.yml
vendored
11
.github/workflows/build-linux-clang.yml
vendored
@@ -18,12 +18,5 @@ jobs:
|
||||
- name: Setup clang
|
||||
uses: egor-tensin/setup-clang@v1
|
||||
|
||||
- name: Configure CMake
|
||||
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=Release -DNO_OCL=ON
|
||||
|
||||
- name: Build
|
||||
run: cmake --build ${{github.workspace}}/build
|
||||
|
||||
- name: Run Example
|
||||
working-directory: ${{github.workspace}}/build
|
||||
run: ctest --verbose
|
||||
- name: Build and Test
|
||||
run: ./scripts/feature-tests.shell
|
||||
|
||||
15
.github/workflows/build-linux-gcc.yml
vendored
15
.github/workflows/build-linux-gcc.yml
vendored
@@ -6,9 +6,6 @@ on:
|
||||
pull_request:
|
||||
branches: [ "main" ]
|
||||
|
||||
env:
|
||||
BUILD_TYPE: Release
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
@@ -22,13 +19,5 @@ jobs:
|
||||
- name: Setup gitmodules
|
||||
run: git submodule update --init --recursive
|
||||
|
||||
- name: Configure CMake
|
||||
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DNO_OCL=ON
|
||||
|
||||
- name: Build
|
||||
run: cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}}
|
||||
|
||||
- name: Run Example
|
||||
working-directory: ${{github.workspace}}/build
|
||||
run: ctest --verbose
|
||||
|
||||
- name: Build and Test
|
||||
run: ./scripts/feature-tests.shell
|
||||
|
||||
11
.github/workflows/build-macos.yml
vendored
11
.github/workflows/build-macos.yml
vendored
@@ -15,12 +15,5 @@ jobs:
|
||||
- name: Setup gitmodules
|
||||
run: git submodule update --init --recursive
|
||||
|
||||
- name: Configure CMake
|
||||
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=Release -DNO_OCL=ON
|
||||
|
||||
- name: Build
|
||||
run: cmake --build ${{github.workspace}}/build
|
||||
|
||||
- name: Run Example
|
||||
working-directory: ${{github.workspace}}/build
|
||||
run: ctest --verbose
|
||||
- name: Build and Test
|
||||
run: ./scripts/feature-tests.shell
|
||||
|
||||
12
.github/workflows/build-windows-vs.yml
vendored
12
.github/workflows/build-windows-vs.yml
vendored
@@ -17,12 +17,6 @@ jobs:
|
||||
- name: Setup Visual Studio
|
||||
uses: egor-tensin/vs-shell@v2
|
||||
|
||||
- name: Configure CMake
|
||||
run: cmake -B ${{github.workspace}}\build -DCMAKE_BUILD_TYPE=Release -UOPENCL_SDK_BUILD_SAMPLES -DNO_OCL=ON
|
||||
|
||||
- name: Build
|
||||
run: cmake --build ${{github.workspace}}\build
|
||||
|
||||
- name: Run Example
|
||||
working-directory: ${{github.workspace}}/build
|
||||
run: ctest --verbose
|
||||
- name: Build and Test
|
||||
run: ./scripts/feature-tests.shell
|
||||
shell: bash
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
project(hwinfo VERSION 1.0.0 LANGUAGES CXX)
|
||||
include(GNUInstallDirs)
|
||||
|
||||
@@ -6,34 +7,55 @@ string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}" PROJECT
|
||||
|
||||
option(BUILD_EXAMPLES "Build example program" ${PROJECT_IS_TOP_LEVEL})
|
||||
option(BUILD_TESTING "Build test program" ${PROJECT_IS_TOP_LEVEL})
|
||||
option(NO_OCL "Disable OCL" OFF)
|
||||
|
||||
# set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
|
||||
# Components
|
||||
option(HWINFO_OS "Enable OS detection" ON)
|
||||
option(HWINFO_MAINBOARD "Enable mainboard detection" ON)
|
||||
option(HWINFO_CPU "Enable CPU detection" ON)
|
||||
option(HWINFO_DISK "Enable disk detection" ON)
|
||||
option(HWINFO_RAM "Enable RAM detection" ON)
|
||||
option(HWINFO_GPU "Enable GPU detection" ON)
|
||||
option(HWINFO_GPU_OPENCL "Enable usage of OpenCL in GPU information" OFF)
|
||||
option(HWINFO_BATTERY "Enable battery detection" ON)
|
||||
|
||||
if (NOT DEFINED NO_OCL)
|
||||
# deprecated NO_OCL
|
||||
if (DEFINED NO_OCL)
|
||||
message(WARNING "NO_OCL is deprecated, use HWINFO_GPU_OPENCL instead")
|
||||
set(HWINFO_GPU_OPENCL NOT NO_OCL)
|
||||
endif()
|
||||
|
||||
# Use the latest C++ standard available
|
||||
if("${CMAKE_CXX_STANDARD}" STREQUAL "")
|
||||
if(DEFINED CMAKE_CXX23_STANDARD_COMPILE_OPTION OR DEFINED CMAKE_CXX23_EXTENSION_COMPILE_OPTION)
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
elseif(DEFINED CMAKE_CXX20_STANDARD_COMPILE_OPTION OR DEFINED CMAKE_CXX20_EXTENSION_COMPILE_OPTION)
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
else ()
|
||||
elseif(DEFINED CMAKE_CXX17_STANDARD_COMPILE_OPTION OR DEFINED
|
||||
CMAKE_CXX17_EXTENSION_COMPILE_OPTION
|
||||
)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
elseif(DEFINED CMAKE_CXX14_STANDARD_COMPILE_OPTION OR DEFINED
|
||||
CMAKE_CXX14_EXTENSION_COMPILE_OPTION
|
||||
)
|
||||
set(CMAKE_CXX_STANDARD 14)
|
||||
else()
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
endif ()
|
||||
endif()
|
||||
endif()
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
if(HWINFO_GPU_OPENCL)
|
||||
if(NOT TARGET miss-opencl_static)
|
||||
add_subdirectory(${PROJECT_SOURCE_DIR}/external/miss-opencl)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
|
||||
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||||
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
|
||||
|
||||
if (NOT DEFINED NO_OCL)
|
||||
if (NOT TARGET miss-opencl_static)
|
||||
add_subdirectory(external/miss-opencl)
|
||||
endif ()
|
||||
|
||||
add_compile_definitions(USE_OCL)
|
||||
add_compile_definitions(NOMINMAX)
|
||||
endif ()
|
||||
|
||||
include_directories({PROJECT_SOURCE_DIR}/include)
|
||||
set(HWINFO_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||
add_subdirectory(src)
|
||||
target_include_directories(HWinfo PUBLIC ${PROJECT_SOURCE_DIR}/include/)
|
||||
|
||||
install(DIRECTORY include/hwinfo DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||
|
||||
if (NOT PROJECT_IS_TOP_LEVEL)
|
||||
return()
|
||||
|
||||
40
README.md
40
README.md
@@ -12,8 +12,7 @@
|
||||
hwinfo provides an easy-to-use and modern C++ API for retrieving hardware information of your systems components such as
|
||||
CPU, RAM, GPU, Disks, Mainboard, ...
|
||||
|
||||
hwinfo builds using C++20. However, if your compiler does not support C++20, you can fall back to C++11 by setting the
|
||||
`NO_OCL` CMake variable (add `-DNO_OCL=ON` to the CMake command).
|
||||
hwinfo automatically uses the latest C++ standard supported by your compiler. C++20 is required for GPU OpenCL support if enabled (configurable with `HWINFO_GPU_OPENCL`).
|
||||
|
||||
> **Note**
|
||||
>
|
||||
@@ -74,6 +73,37 @@ hwinfo builds using C++20. However, if your compiler does not support C++20, you
|
||||
| | Capacity | ✔️ | ✔️ | ️❌ |
|
||||
| | Charging | ✔️ | ✔️ | ❌ |
|
||||
|
||||
|
||||
All components are available via the `hwinfo::hwinfo` target, or via individual CMake targets, which you can choose and link against depending on your needs.
|
||||
|
||||
```cmake
|
||||
target_link_libraries(your_target PRIVATE hwinfo::hwinfo)
|
||||
```
|
||||
or
|
||||
|
||||
```cmake
|
||||
target_link_libraries(
|
||||
your_target
|
||||
PRIVATE hwinfo::cpu
|
||||
hwinfo::gpu
|
||||
hwinfo::ram
|
||||
hwinfo::mainboard
|
||||
hwinfo::disk
|
||||
hwinfo::os
|
||||
hwinfo::battery)
|
||||
```
|
||||
|
||||
The CMake options control which components will be built and available in the library:
|
||||
|
||||
- `HWINFO_OS` "Enable OS detection" (default to `ON`)
|
||||
- `HWINFO_MAINBOARD` "Enable mainboard detection" (default to `ON`)
|
||||
- `HWINFO_CPU` "Enable CPU detection" (default to `ON`)
|
||||
- `HWINFO_DISK` "Enable disk detection" (default to `ON`)
|
||||
- `HWINFO_RAM` "Enable RAM detection" (default to `ON`)
|
||||
- `HWINFO_GPU` "Enable GPU detection" (default to `ON`)
|
||||
- `HWINFO_GPU_OPENCL` "Enable usage of OpenCL in GPU information" (default to `OFF`)
|
||||
- `HWINFO_BATTERY` "Enable battery detection" (default to `ON`)
|
||||
|
||||
## API
|
||||
|
||||
This section describes, how you can get information about the supported components of your computer.
|
||||
@@ -231,7 +261,7 @@ Disk 4:
|
||||
|
||||
```
|
||||
|
||||
## Include `hwinfo` in your cmake project
|
||||
## Directly including `hwinfo` in your cmake project
|
||||
|
||||
1. Download `hwinfo` into your project (e.g. in `<project-root>/third_party/hwinfo`)
|
||||
```
|
||||
@@ -243,6 +273,8 @@ Disk 4:
|
||||
```cmake
|
||||
# file: <project-root>/CMakeLists.txt
|
||||
|
||||
# define the HWINFO_* options if you want to change the default values
|
||||
|
||||
add_subdirectory(third_party/hwinfo)
|
||||
```
|
||||
3. Include `hwinfo` into your `.cpp/.h` files:
|
||||
@@ -258,5 +290,5 @@ Disk 4:
|
||||
4. Link it in cmake
|
||||
```cmake
|
||||
add_executable(your_executable your_executable.cpp)
|
||||
target_link_libraries(your_executable PUBLIC hwinfo::HWinfo)
|
||||
target_link_libraries(your_executable PUBLIC hwinfo::hwinfo)
|
||||
```
|
||||
|
||||
@@ -7,4 +7,4 @@ FetchContent_Declare(
|
||||
GIT_TAG 11.0.1)
|
||||
FetchContent_MakeAvailable(fmt)
|
||||
|
||||
target_link_libraries(Example PRIVATE hwinfo::HWinfo fmt::fmt)
|
||||
target_link_libraries(Example PRIVATE hwinfo::hwinfo fmt::fmt)
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef HWINFO_BATTERY
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -46,3 +48,5 @@ class Battery {
|
||||
std::vector<Battery> getAllBatteries();
|
||||
|
||||
} // namespace hwinfo
|
||||
|
||||
#endif // HWINFO_BATTERY
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef HWINFO_CPU
|
||||
|
||||
#include <hwinfo/platform.h>
|
||||
#include <hwinfo/utils/wmi_wrapper.h>
|
||||
|
||||
@@ -74,3 +76,5 @@ class CPU {
|
||||
std::vector<CPU> getAllCPUs();
|
||||
|
||||
} // namespace hwinfo
|
||||
|
||||
#endif // HWINFO_CPU
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef HWINFO_CPU
|
||||
|
||||
#include "hwinfo/platform.h"
|
||||
|
||||
#if defined(HWINFO_X86)
|
||||
@@ -52,3 +54,5 @@ inline void cpuid(uint32_t func_id, uint32_t sub_func_id, uint32_t regs[4]) {
|
||||
} // namespace hwinfo
|
||||
|
||||
#endif // HWINFO_X86
|
||||
|
||||
#endif // HWINFO_CPU
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef HWINFO_DISK
|
||||
|
||||
#include <hwinfo/platform.h>
|
||||
|
||||
#include <cstdint>
|
||||
@@ -39,3 +41,5 @@ class Disk {
|
||||
std::vector<Disk> getAllDisks();
|
||||
|
||||
} // namespace hwinfo
|
||||
|
||||
#endif // HWINFO_DISK
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef HWINFO_GPU
|
||||
|
||||
#include <hwinfo/platform.h>
|
||||
|
||||
#include <cstdint>
|
||||
@@ -43,3 +45,5 @@ class GPU {
|
||||
|
||||
std::vector<GPU> getAllGPUs();
|
||||
} // namespace hwinfo
|
||||
|
||||
#endif // HWINFO_GPU
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef HWINFO_MAINBOARD
|
||||
|
||||
#include <hwinfo/platform.h>
|
||||
|
||||
#include <string>
|
||||
@@ -29,3 +31,5 @@ class MainBoard {
|
||||
};
|
||||
|
||||
} // namespace hwinfo
|
||||
|
||||
#endif // HWINFO_MAINBOARD
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef HWINFO_OS
|
||||
|
||||
#include <hwinfo/platform.h>
|
||||
|
||||
#include <string>
|
||||
@@ -33,3 +35,5 @@ class OS {
|
||||
};
|
||||
|
||||
} // namespace hwinfo
|
||||
|
||||
#endif // HWINFO_OS
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef HWINFO_RAM
|
||||
|
||||
#include <hwinfo/platform.h>
|
||||
|
||||
#include <cstdint>
|
||||
@@ -37,3 +39,5 @@ class Memory {
|
||||
};
|
||||
|
||||
} // namespace hwinfo
|
||||
|
||||
#endif // HWINFO_RAM
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(HWINFO_CPU) && defined(HWINFO_GPU) && defined(HWINFO_RAM) && defined(HWINFO_DISK)
|
||||
#define HWINFO_SYSTEM
|
||||
|
||||
#include <hwinfo/cpu.h>
|
||||
#include <hwinfo/disk.h>
|
||||
#include <hwinfo/gpu.h>
|
||||
@@ -29,3 +32,5 @@ class System {
|
||||
};
|
||||
|
||||
} // namespace hwinfo
|
||||
|
||||
#endif // HWINFO_SYSTEM
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <hwinfo/cpu.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace hwinfo {
|
||||
namespace filesystem {
|
||||
@@ -15,7 +16,7 @@ std::vector<std::string> getDirectoryEntries(const std::string& path);
|
||||
int64_t get_specs_by_file_path(const std::string& path);
|
||||
#endif // HWINFO_UNIX || HWINFO_APPLE
|
||||
|
||||
#ifdef HWINFO_UNIX
|
||||
#if defined(HWINFO_UNIX) && defined(HWINFO_CPU)
|
||||
Jiffies get_jiffies(int index);
|
||||
#endif // HWINFO_UNIX
|
||||
|
||||
|
||||
52
scripts/feature-tests.shell
Executable file
52
scripts/feature-tests.shell
Executable file
@@ -0,0 +1,52 @@
|
||||
#!/bin/bash -ex
|
||||
# bash or pwsh
|
||||
|
||||
# Test default (all)
|
||||
cmake -B ./build -DCMAKE_BUILD_TYPE=Release
|
||||
cmake --build ./build --parallel --config Release
|
||||
cd build
|
||||
ctest -C Release -V
|
||||
cd ..
|
||||
|
||||
# Test OS target
|
||||
rm build/CMakeCache.txt
|
||||
cmake -B ./build -DCMAKE_BUILD_TYPE=Debug -DHWINFO_OS=ON -DHWINFO_MAINBOARD=OFF -DHWINFO_CPU=OFF -DHWINFO_DISK=OFF -DHWINFO_RAM=OFF -DHWINFO_GPU=OFF -DHWINFO_GPU_OPENCL=OFF -DHWINFO_BATTERY=OFF
|
||||
cmake --build ./build --parallel --config Debug -t hwinfo_os
|
||||
|
||||
# Test mainboard target
|
||||
rm build/CMakeCache.txt
|
||||
cmake -B ./build -DCMAKE_BUILD_TYPE=Debug -DHWINFO_OS=OFF -DHWINFO_MAINBOARD=ON -DHWINFO_CPU=OFF -DHWINFO_DISK=OFF -DHWINFO_RAM=OFF -DHWINFO_GPU=OFF -DHWINFO_GPU_OPENCL=OFF -DHWINFO_BATTERY=OFF
|
||||
cmake --build ./build --parallel --config Debug -t hwinfo_mainboard
|
||||
|
||||
# Test CPU target
|
||||
rm build/CMakeCache.txt
|
||||
cmake -B ./build -DCMAKE_BUILD_TYPE=Debug -DHWINFO_OS=OFF -DHWINFO_MAINBOARD=OFF -DHWINFO_CPU=ON -DHWINFO_DISK=OFF -DHWINFO_RAM=OFF -DHWINFO_GPU=OFF -DHWINFO_GPU_OPENCL=OFF -DHWINFO_BATTERY=OFF
|
||||
cmake --build ./build --parallel --config Debug -t hwinfo_cpu
|
||||
|
||||
# Test disk target
|
||||
rm build/CMakeCache.txt
|
||||
cmake -B ./build -DCMAKE_BUILD_TYPE=Debug -DHWINFO_OS=OFF -DHWINFO_MAINBOARD=OFF -DHWINFO_CPU=OFF -DHWINFO_DISK=ON -DHWINFO_RAM=OFF -DHWINFO_GPU=OFF -DHWINFO_GPU_OPENCL=OFF -DHWINFO_BATTERY=OFF
|
||||
cmake --build ./build --parallel --config Debug -t hwinfo_disk
|
||||
|
||||
# Test RAM target
|
||||
rm build/CMakeCache.txt
|
||||
cmake -B ./build -DCMAKE_BUILD_TYPE=Debug -DHWINFO_OS=OFF -DHWINFO_MAINBOARD=OFF -DHWINFO_CPU=OFF -DHWINFO_DISK=OFF -DHWINFO_RAM=ON -DHWINFO_GPU=OFF -DHWINFO_GPU_OPENCL=OFF -DHWINFO_BATTERY=OFF
|
||||
cmake --build ./build --parallel --config Debug -t hwinfo_ram
|
||||
|
||||
# Test GPU target
|
||||
rm build/CMakeCache.txt
|
||||
cmake -B ./build -DCMAKE_BUILD_TYPE=Debug -DHWINFO_OS=OFF -DHWINFO_MAINBOARD=OFF -DHWINFO_CPU=OFF -DHWINFO_DISK=OFF -DHWINFO_RAM=OFF -DHWINFO_GPU=ON -DHWINFO_GPU_OPENCL=OFF -DHWINFO_BATTERY=OFF
|
||||
cmake --build ./build --parallel --config Debug -t hwinfo_gpu
|
||||
|
||||
# # Test GPU target with OpenCL
|
||||
# rm build/CMakeCache.txt
|
||||
# cmake -B ./build -DCMAKE_BUILD_TYPE=Debug -DHWINFO_OS=OFF -DHWINFO_MAINBOARD=OFF -DHWINFO_CPU=OFF -DHWINFO_DISK=OFF -DHWINFO_RAM=OFF -DHWINFO_GPU=ON -DHWINFO_GPU_OPENCL=ON -DHWINFO_BATTERY=OFF
|
||||
# cmake --build ./build --parallel --config Debug -t hwinfo_gpu
|
||||
|
||||
# Test battery target
|
||||
rm build/CMakeCache.txt
|
||||
cmake -B ./build -DCMAKE_BUILD_TYPE=Debug -DHWINFO_OS=OFF -DHWINFO_MAINBOARD=OFF -DHWINFO_CPU=OFF -DHWINFO_DISK=OFF -DHWINFO_RAM=OFF -DHWINFO_GPU=OFF -DHWINFO_GPU_OPENCL=OFF -DHWINFO_BATTERY=ON
|
||||
cmake --build ./build --parallel --config Debug -t hwinfo_battery
|
||||
|
||||
# Clean up
|
||||
rm build/CMakeCache.txt
|
||||
@@ -1,56 +1,277 @@
|
||||
add_library(HWinfo STATIC
|
||||
hwinfo.cpp
|
||||
# platform independent definitions
|
||||
PCIMapper.cpp
|
||||
battery.cpp
|
||||
cpu.cpp
|
||||
gpu.cpp
|
||||
ram.cpp
|
||||
os.cpp
|
||||
mainboard.cpp
|
||||
disk.cpp
|
||||
# hwinfo (all in one target)
|
||||
add_library(hwinfo hwinfo.cpp)
|
||||
add_library(hwinfo::hwinfo ALIAS hwinfo)
|
||||
|
||||
# for backward compatibility
|
||||
add_library(HWinfo ALIAS hwinfo)
|
||||
add_library(hwinfo::HWinfo ALIAS hwinfo)
|
||||
|
||||
target_include_directories(hwinfo PUBLIC ${PROJECT_SOURCE_DIR}/include/)
|
||||
|
||||
# C++ options based on CMake options
|
||||
set(HWINFO_DEFINITIONS "")
|
||||
set(OPTIONS_LIST
|
||||
HWINFO_OS
|
||||
HWINFO_MAINBOARD
|
||||
HWINFO_CPU
|
||||
HWINFO_DISK
|
||||
HWINFO_RAM
|
||||
HWINFO_GPU
|
||||
HWINFO_BATTERY)
|
||||
foreach(OPTION IN LISTS OPTIONS_LIST)
|
||||
if(${OPTION})
|
||||
list(APPEND HWINFO_DEFINITIONS ${OPTION})
|
||||
endif()
|
||||
endforeach()
|
||||
|
||||
target_compile_definitions(hwinfo PUBLIC ${HWINFO_DEFINITIONS})
|
||||
|
||||
install(TARGETS hwinfo DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
install(DIRECTORY include/hwinfo DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
|
||||
|
||||
# filesystem_utils
|
||||
add_library(
|
||||
hwinfo_utils_filesystem
|
||||
# apple specific definitions
|
||||
apple/utils/filesystem.cpp
|
||||
apple/battery.cpp
|
||||
apple/cpu.cpp
|
||||
apple/gpu.cpp
|
||||
apple/ram.cpp
|
||||
apple/os.cpp
|
||||
apple/mainboard.cpp
|
||||
apple/disk.cpp
|
||||
# linux specific definitions
|
||||
linux/utils/filesystem.cpp
|
||||
linux/battery.cpp
|
||||
linux/cpu.cpp
|
||||
linux/gpu.cpp
|
||||
linux/ram.cpp
|
||||
linux/os.cpp
|
||||
linux/mainboard.cpp
|
||||
linux/disk.cpp
|
||||
# windows specific definitions
|
||||
windows/utils/filesystem.cpp
|
||||
windows/utils/wmi_wrapper.cpp
|
||||
windows/battery.cpp
|
||||
windows/cpu.cpp
|
||||
windows/gpu.cpp
|
||||
windows/ram.cpp
|
||||
windows/os.cpp
|
||||
windows/mainboard.cpp
|
||||
windows/disk.cpp
|
||||
)
|
||||
windows/utils/filesystem.cpp)
|
||||
add_library(hwinfo::utils::filesystem ALIAS hwinfo_utils_filesystem)
|
||||
|
||||
if (WIN32 AND ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
|
||||
target_link_libraries(HWinfo PUBLIC "wbemuuid")
|
||||
endif ()
|
||||
target_include_directories(
|
||||
hwinfo_utils_filesystem
|
||||
PUBLIC $<BUILD_INTERFACE:${HWINFO_INCLUDE_DIR}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
|
||||
|
||||
if (APPLE)
|
||||
target_link_libraries(HWinfo PUBLIC "-framework IOKit" "-framework CoreFoundation")
|
||||
target_compile_definitions(hwinfo_utils_filesystem PUBLIC ${HWINFO_DEFINITIONS})
|
||||
|
||||
# wmi_wrapper on windows
|
||||
add_library(
|
||||
hwinfo_utils_wmi
|
||||
# windows specific definitions
|
||||
windows/utils/wmi_wrapper.cpp)
|
||||
add_library(hwinfo::utils::wmi ALIAS hwinfo_utils_wmi)
|
||||
|
||||
if(WIN32 AND ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU")
|
||||
target_link_libraries(hwinfo_utils_wmi PRIVATE "wbemuuid")
|
||||
endif()
|
||||
|
||||
if (NOT DEFINED NO_OCL)
|
||||
target_link_libraries(HWinfo PUBLIC miss-opencl_static)
|
||||
endif ()
|
||||
target_include_directories(
|
||||
hwinfo_utils_wmi PUBLIC $<BUILD_INTERFACE:${HWINFO_INCLUDE_DIR}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
|
||||
|
||||
add_library(${PROJECT_NAME}::HWinfo ALIAS HWinfo)
|
||||
target_compile_definitions(hwinfo_utils_wmi PUBLIC ${HWINFO_DEFINITIONS})
|
||||
|
||||
install(TARGETS HWinfo DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
# PCIMapper on Unix
|
||||
add_library(hwinfo_utils_PCIMapper PCIMapper.cpp)
|
||||
add_library(hwinfo::utils::PCIMapper ALIAS hwinfo_utils_PCIMapper)
|
||||
|
||||
target_include_directories(
|
||||
hwinfo_utils_PCIMapper
|
||||
PUBLIC $<BUILD_INTERFACE:${HWINFO_INCLUDE_DIR}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
|
||||
|
||||
target_compile_definitions(hwinfo_utils_PCIMapper PUBLIC ${HWINFO_DEFINITIONS})
|
||||
|
||||
# battery
|
||||
if(HWINFO_BATTERY)
|
||||
add_library(
|
||||
hwinfo_battery
|
||||
battery.cpp
|
||||
# apple specific definitions
|
||||
apple/battery.cpp
|
||||
# linux specific definitions
|
||||
linux/battery.cpp
|
||||
# windows specific definitions
|
||||
windows/battery.cpp)
|
||||
add_library(hwinfo::battery ALIAS hwinfo_battery)
|
||||
|
||||
target_include_directories(
|
||||
hwinfo_battery PUBLIC $<BUILD_INTERFACE:${HWINFO_INCLUDE_DIR}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
|
||||
|
||||
target_link_libraries(hwinfo_battery PRIVATE hwinfo::utils::filesystem
|
||||
hwinfo::utils::wmi)
|
||||
|
||||
target_compile_definitions(hwinfo_battery PUBLIC ${HWINFO_DEFINITIONS})
|
||||
|
||||
install(TARGETS hwinfo_battery DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
|
||||
target_link_libraries(hwinfo PUBLIC hwinfo_battery)
|
||||
endif()
|
||||
|
||||
# cpu
|
||||
if(HWINFO_CPU)
|
||||
add_library(
|
||||
hwinfo_cpu
|
||||
cpu.cpp
|
||||
# apple specific definitions
|
||||
apple/cpu.cpp
|
||||
# linux specific definitions
|
||||
linux/cpu.cpp
|
||||
# windows specific definitions
|
||||
windows/cpu.cpp)
|
||||
add_library(hwinfo::cpu ALIAS hwinfo_cpu)
|
||||
|
||||
target_include_directories(
|
||||
hwinfo_cpu PUBLIC $<BUILD_INTERFACE:${HWINFO_INCLUDE_DIR}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
|
||||
|
||||
target_link_libraries(hwinfo_cpu PRIVATE hwinfo::utils::filesystem
|
||||
hwinfo::utils::wmi)
|
||||
|
||||
target_compile_definitions(hwinfo_cpu PUBLIC ${HWINFO_DEFINITIONS})
|
||||
|
||||
target_link_libraries(hwinfo PUBLIC hwinfo_cpu)
|
||||
|
||||
install(TARGETS hwinfo_cpu DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif()
|
||||
|
||||
# disk
|
||||
if(HWINFO_DISK)
|
||||
add_library(
|
||||
hwinfo_disk
|
||||
disk.cpp
|
||||
# apple specific definitions
|
||||
apple/disk.cpp
|
||||
# linux specific definitions
|
||||
linux/disk.cpp
|
||||
# windows specific definitions
|
||||
windows/disk.cpp)
|
||||
add_library(hwinfo::disk ALIAS hwinfo_disk)
|
||||
|
||||
target_include_directories(
|
||||
hwinfo_disk PUBLIC $<BUILD_INTERFACE:${HWINFO_INCLUDE_DIR}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
|
||||
|
||||
target_compile_definitions(hwinfo_disk PUBLIC ${HWINFO_DEFINITIONS})
|
||||
|
||||
target_link_libraries(hwinfo_disk PRIVATE hwinfo::utils::filesystem
|
||||
hwinfo::utils::wmi)
|
||||
|
||||
if(APPLE)
|
||||
target_link_libraries(hwinfo_disk PRIVATE "-framework IOKit"
|
||||
"-framework CoreFoundation")
|
||||
endif()
|
||||
|
||||
install(TARGETS hwinfo_disk DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
|
||||
target_link_libraries(hwinfo PUBLIC hwinfo_disk)
|
||||
endif()
|
||||
|
||||
# gpu
|
||||
if(HWINFO_GPU)
|
||||
add_library(
|
||||
hwinfo_gpu
|
||||
gpu.cpp
|
||||
# apple specific definitions
|
||||
apple/gpu.cpp
|
||||
# linux specific definitions
|
||||
linux/gpu.cpp
|
||||
# windows specific definitions
|
||||
windows/gpu.cpp)
|
||||
add_library(hwinfo::gpu ALIAS hwinfo_gpu)
|
||||
|
||||
target_include_directories(
|
||||
hwinfo_gpu PUBLIC $<BUILD_INTERFACE:${HWINFO_INCLUDE_DIR}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
|
||||
|
||||
target_link_libraries(
|
||||
hwinfo_gpu PRIVATE hwinfo::utils::filesystem hwinfo::utils::wmi
|
||||
hwinfo::utils::PCIMapper)
|
||||
|
||||
target_compile_definitions(hwinfo_gpu PUBLIC ${HWINFO_DEFINITIONS})
|
||||
|
||||
if(HWINFO_GPU_OPENCL)
|
||||
if(NOT TARGET miss-opencl_static)
|
||||
add_subdirectory(${PROJECT_SOURCE_DIR}/external/miss-opencl)
|
||||
endif()
|
||||
|
||||
target_compile_definitions(hwinfo_gpu PRIVATE USE_OCL NOMINMAX)
|
||||
|
||||
target_link_libraries(hwinfo_gpu PRIVATE miss-opencl_static)
|
||||
endif()
|
||||
|
||||
install(TARGETS hwinfo_gpu DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
|
||||
target_link_libraries(hwinfo PUBLIC hwinfo_gpu)
|
||||
endif()
|
||||
|
||||
# mainboard
|
||||
if(HWINFO_MAINBOARD)
|
||||
add_library(
|
||||
hwinfo_mainboard
|
||||
mainboard.cpp
|
||||
# apple specific definitions
|
||||
apple/mainboard.cpp
|
||||
# linux specific definitions
|
||||
linux/mainboard.cpp
|
||||
# windows specific definitions
|
||||
windows/mainboard.cpp)
|
||||
add_library(hwinfo::mainboard ALIAS hwinfo_mainboard)
|
||||
|
||||
target_include_directories(
|
||||
hwinfo_mainboard PUBLIC $<BUILD_INTERFACE:${HWINFO_INCLUDE_DIR}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
|
||||
|
||||
target_compile_definitions(hwinfo_mainboard PUBLIC ${HWINFO_DEFINITIONS})
|
||||
|
||||
target_link_libraries(hwinfo_mainboard PRIVATE hwinfo::utils::wmi)
|
||||
|
||||
install(TARGETS hwinfo_mainboard DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
|
||||
target_link_libraries(hwinfo PUBLIC hwinfo_mainboard)
|
||||
endif()
|
||||
|
||||
# os
|
||||
if(HWINFO_OS)
|
||||
add_library(
|
||||
hwinfo_os
|
||||
os.cpp
|
||||
# apple specific definitions
|
||||
apple/os.cpp
|
||||
# linux specific definitions
|
||||
linux/os.cpp
|
||||
# windows specific definitions
|
||||
windows/os.cpp)
|
||||
add_library(hwinfo::os ALIAS hwinfo_os)
|
||||
|
||||
target_include_directories(
|
||||
hwinfo_os PUBLIC $<BUILD_INTERFACE:${HWINFO_INCLUDE_DIR}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
|
||||
|
||||
target_compile_definitions(hwinfo_os PUBLIC ${HWINFO_DEFINITIONS})
|
||||
|
||||
target_link_libraries(hwinfo_os PRIVATE hwinfo::utils::wmi)
|
||||
|
||||
target_link_libraries(hwinfo PUBLIC hwinfo_os)
|
||||
install(TARGETS hwinfo_os DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif()
|
||||
|
||||
# ram
|
||||
if(HWINFO_RAM)
|
||||
add_library(
|
||||
hwinfo_ram
|
||||
ram.cpp
|
||||
# apple specific definitions
|
||||
apple/ram.cpp
|
||||
# linux specific definitions
|
||||
linux/ram.cpp
|
||||
# windows specific definitions
|
||||
windows/ram.cpp)
|
||||
add_library(hwinfo::ram ALIAS hwinfo_ram)
|
||||
|
||||
target_include_directories(
|
||||
hwinfo_ram PUBLIC $<BUILD_INTERFACE:${HWINFO_INCLUDE_DIR}>
|
||||
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)
|
||||
|
||||
target_compile_definitions(hwinfo_ram PUBLIC ${HWINFO_DEFINITIONS})
|
||||
|
||||
target_link_libraries(hwinfo_ram PRIVATE hwinfo::utils::wmi)
|
||||
|
||||
target_link_libraries(hwinfo PUBLIC hwinfo_ram)
|
||||
|
||||
install(TARGETS hwinfo_ram DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
endif()
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Copyright Leon Freist
|
||||
// Author Leon Freist <freist@informatik.uni-freiburg.de>
|
||||
|
||||
#ifdef HWINFO_BATTERY
|
||||
|
||||
#include "hwinfo/battery.h"
|
||||
|
||||
namespace hwinfo {
|
||||
@@ -53,3 +55,5 @@ uint32_t Battery::energyFull() {
|
||||
double Battery::capacity() { return static_cast<double>(energyNow()) / energyFull(); }
|
||||
|
||||
} // namespace hwinfo
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Copyright (c) Leon Freist <freist@informatik.uni-freiburg.de>
|
||||
// This software is part of HWBenchmark
|
||||
|
||||
#ifdef HWINFO_CPU
|
||||
|
||||
#include "hwinfo/cpu.h"
|
||||
|
||||
#include <string>
|
||||
@@ -42,3 +44,5 @@ int64_t CPU::regularClockSpeed_MHz() const { return _regularClockSpeed_MHz; }
|
||||
const std::vector<std::string>& CPU::flags() const { return _flags; }
|
||||
|
||||
} // namespace hwinfo
|
||||
|
||||
#endif // HWINFO_CPU
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Copyright Leon Freist
|
||||
// Author Leon Freist <freist@informatik.uni-freiburg.de>
|
||||
|
||||
#ifdef HWINFO_DISK
|
||||
|
||||
#include <hwinfo/disk.h>
|
||||
|
||||
namespace hwinfo {
|
||||
@@ -21,3 +23,5 @@ int64_t Disk::size_Bytes() const { return _size_Bytes; }
|
||||
int Disk::id() const { return _id; }
|
||||
|
||||
} // namespace hwinfo
|
||||
|
||||
#endif // HWINFO_DISK
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Copyright Leon Freist
|
||||
// Author Leon Freist <freist@informatik.uni-freiburg.de>
|
||||
|
||||
#ifdef HWINFO_GPU
|
||||
|
||||
#include <hwinfo/gpu.h>
|
||||
|
||||
#include <string>
|
||||
@@ -35,3 +37,5 @@ const std::string& GPU::vendor_id() const { return _vendor_id; }
|
||||
const std::string& GPU::device_id() const { return _device_id; }
|
||||
|
||||
} // namespace hwinfo
|
||||
|
||||
#endif // HWINFO_GPU
|
||||
|
||||
@@ -55,6 +55,8 @@ int64_t hwinfo::filesystem::get_specs_by_file_path(const std::string& path) {
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(HWINFO_CPU)
|
||||
|
||||
hwinfo::Jiffies hwinfo::filesystem::get_jiffies(int index) {
|
||||
// std::string text = "cpu 349585 0 30513 875546 0 935 0 0 0 0";
|
||||
|
||||
@@ -92,4 +94,6 @@ hwinfo::Jiffies hwinfo::filesystem::get_jiffies(int index) {
|
||||
return {all, working};
|
||||
}
|
||||
|
||||
#endif // HWINFO_CPU
|
||||
|
||||
#endif // HWINFO_UNIX
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Copyright (c) Leon Freist <freist@informatik.uni-freiburg.de>
|
||||
// This software is part of HWBenchmark
|
||||
|
||||
#ifdef HWINFO_MAINBOARD
|
||||
|
||||
#include <hwinfo/mainboard.h>
|
||||
|
||||
namespace hwinfo {
|
||||
@@ -18,3 +20,5 @@ const std::string& MainBoard::version() const { return _version; }
|
||||
const std::string& MainBoard::serialNumber() const { return _serialNumber; }
|
||||
|
||||
} // namespace hwinfo
|
||||
|
||||
#endif // HWINFO_MAINBOARD
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Copyright (c) Leon Freist <freist@informatik.uni-freiburg.de>
|
||||
// This software is part of HWBenchmark
|
||||
|
||||
#ifdef HWINFO_OS
|
||||
|
||||
#include "hwinfo/os.h"
|
||||
|
||||
#include <string>
|
||||
@@ -29,3 +31,5 @@ bool OS::isBigEndian() const { return _bigEndian; }
|
||||
bool OS::isLittleEndian() const { return _littleEndian; }
|
||||
|
||||
} // namespace hwinfo
|
||||
|
||||
#endif // HWINFO_OS
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// Copyright (c) Leon Freist <freist@informatik.uni-freiburg.de>
|
||||
// This software is part of HWBenchmark
|
||||
|
||||
#ifdef HWINFO_RAM
|
||||
|
||||
#include <hwinfo/ram.h>
|
||||
|
||||
namespace hwinfo {
|
||||
@@ -18,3 +20,5 @@ int64_t Memory::total_Bytes() const {
|
||||
}
|
||||
|
||||
} // namespace hwinfo
|
||||
|
||||
#endif // HWINFO_RAM
|
||||
|
||||
Reference in New Issue
Block a user