diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8a82d8c..c43c500 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -38,14 +38,6 @@ jobs: method: network sub-packages: '["cudart", "nvcc", "nvml_dev"]' - - if: runner.os == 'Linux' - name: Install NVAPI headers on Linux - run: ./nvapi.sh - - - if: runner.os == 'Windows' - name: Install NVAPI headers on Windows - run: .\nvapi.ps1 - - name: Configure project run: > cmake diff --git a/.gitignore b/.gitignore index eb81be9..567609b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1 @@ build/ -nvapi/ -nvapi.tar diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b51cc3..f4068c3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,8 @@ # Specify the minimum required version of CMake -cmake_minimum_required(VERSION 3.17) +cmake_minimum_required(VERSION 3.16) + +# Include the FetchContent module +include(FetchContent) # Define the project name and programming language project(nvidia-pstated C) @@ -7,6 +10,17 @@ project(nvidia-pstated C) # Find the CUDAToolkit package find_package(CUDAToolkit REQUIRED COMPONENTS nvml) +# Declare the nvapi package +FetchContent_Declare( + nvapi + + URL https://download.nvidia.com/XFree86/nvapi-open-source-sdk/R555-OpenSource.tar + URL_HASH SHA256=71339c274a6a633f19b6bd358c7f3045063c6bc106b7dc488aaa7360a6d2b9d7 +) + +# Download and make the nvapi content available for use +FetchContent_MakeAvailable(nvapi) + # Define the executable target add_executable(nvidia-pstated src/main.c @@ -16,7 +30,7 @@ add_executable(nvidia-pstated # Include directories for the target target_include_directories(nvidia-pstated SYSTEM PRIVATE - nvapi + ${nvapi_SOURCE_DIR}/R555-OpenSource ) # Link libraries diff --git a/README.md b/README.md index 81eaa65..af8ebd4 100644 --- a/README.md +++ b/README.md @@ -29,27 +29,10 @@ Download the latest version of the executable for your OS from [releases](https: * CMake * CUDA toolkit -* Wget (only on Linux) -### Linux +### Building ```sh -# Download NVAPI headers -./nvapi.sh - -# Configure -cmake -B build - -# Build -cmake --build build -``` - -### Windows - -```sh -# Download NVAPI headers -.\nvapi.ps1 - # Configure cmake -B build diff --git a/nvapi.ps1 b/nvapi.ps1 deleted file mode 100644 index ea5f1ec..0000000 --- a/nvapi.ps1 +++ /dev/null @@ -1,18 +0,0 @@ -# Constants -$NVAPI_HEADERS = "nvapi" -$NVAPI_HEADERS_ARCHIVE = "nvapi.tar" -$NVAPI_HEADERS_URL = "https://download.nvidia.com/XFree86/nvapi-open-source-sdk/R555-OpenSource.tar" - -# Download NVAPI headers -if (-not (Test-Path $NVAPI_HEADERS_ARCHIVE)) { - Invoke-WebRequest -OutFile $NVAPI_HEADERS_ARCHIVE -Uri $NVAPI_HEADERS_URL -} - -# Extract NVAPI headers -if (-not (Test-Path $NVAPI_HEADERS)) { - # Create directory - New-Item -ItemType Directory -Path $NVAPI_HEADERS - - # Extract headers - tar --directory $NVAPI_HEADERS --extract --file $NVAPI_HEADERS_ARCHIVE --strip-components 2 -} diff --git a/nvapi.sh b/nvapi.sh deleted file mode 100755 index 3af86d2..0000000 --- a/nvapi.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh -set -e - -# Constants -readonly NVAPI_HEADERS="nvapi" -readonly NVAPI_HEADERS_ARCHIVE="nvapi.tar" -readonly NVAPI_HEADERS_URL="https://download.nvidia.com/XFree86/nvapi-open-source-sdk/R555-OpenSource.tar" - -# Download NVAPI headers -if [ ! -f "$NVAPI_HEADERS_ARCHIVE" ]; then - wget --output-document "$NVAPI_HEADERS_ARCHIVE" "$NVAPI_HEADERS_URL" -fi - -# Extract NVAPI headers -if [ ! -d "$NVAPI_HEADERS" ]; then - # Create directory - mkdir "$NVAPI_HEADERS" - - # Extract headers - tar --directory "$NVAPI_HEADERS" --extract --file "$NVAPI_HEADERS_ARCHIVE" --strip-components 2 -fi