Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rework cmake v2 #312

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
50 changes: 32 additions & 18 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,46 @@ jobs:
steps:
# Checks-out
- uses: actions/checkout@v2

- uses: ilammy/msvc-dev-cmd@v1

#don't use run-cmake for windows because only one build should add warnings to pull request
- name: Build Debug
- name: Build ryzenadj Debug
run: |
mkdir debug
cmake -B debug -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Debug
cd debug
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Debug ..
nmake

- name: Upload ryzenadj debug
- name: Upload ryzenadj Debug
uses: actions/upload-artifact@v2
with:
name: ryzenadj-win64-debug
path: |
debug/ryzenadj.exe
debug/libryzenadj.dll

- name: Build Release
- name: Build libryzenadj Debug
run: |
mkdir build
cmake -S lib -B debuglib -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Debug
cd debuglib
nmake

- name: Upload libryzenadj Debug
uses: actions/upload-artifact@v2
with:
name: libryzenadj-win64-debug
path: |
debuglib/libryzenadj.dll

- name: Build ryzenadj Release
run: |
cmake -B build -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release
cd build
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release ..
nmake

- name: Prepair Release Folder
- name: Prepair ryzenadj Release Folder
run: |
mkdir release
copy build/ryzenadj.exe release/
copy build/libryzenadj.dll release/
copy build/lib/libryzenadj.lib release/
copy win32/* release/
copy examples/* release/

Expand Down Expand Up @@ -72,7 +81,7 @@ jobs:
# }
# exit 0

- name: Upload ryzenadj
- name: Upload ryzenadj Release
uses: actions/upload-artifact@v2
with:
name: ryzenadj-win64
Expand All @@ -81,13 +90,19 @@ jobs:
!release/*.lib
!release/*.exp

- name: Upload libryzenadj
- name: Build libryzenadj Release
run: |
cmake -S lib -B buildlib -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release
cd buildlib
nmake

- name: Upload libryzenadj Release
uses: actions/upload-artifact@v2
with:
name: libryzenadj-win64
path: |
./build/libryzenadj.dll
./build/libryzenadj.lib
./buildlib/libryzenadj.dll
./buildlib/libryzenadj.lib
./lib/ryzenadj.h
./win32/inpoutx64.dll
./win32/WinRing0x64.dll
Expand All @@ -109,8 +124,8 @@ jobs:

- name: Test make like readme
run: |
mkdir build && cd build
cmake DCMAKE_BUILD_TYPE=Release ..
cmake -B build -DCMAKE_BUILD_TYPE=Release
cd build
make

# - name: Test Scripts
Expand All @@ -130,4 +145,3 @@ jobs:
# exit 1
# fi
# exit 0

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,5 @@ ASALocalRun/
healthchecksdb

# End of https://www.gitignore.io/api/visualstudio

cmake-build-*
56 changes: 16 additions & 40 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,53 +1,29 @@
#cmake version
CMAKE_MINIMUM_REQUIRED(VERSION 3.9)
CMAKE_MINIMUM_REQUIRED(VERSION 3.23)

#define project name
PROJECT(ryzenadj)
PROJECT(ryzenadjcli)

set(CMAKE_C_VISIBILITY_PRESET hidden)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)

message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
option(BUILD_SHARED_LIBS OFF)
add_subdirectory(lib)

#Enable LTO
include(CheckIPOSupported)
check_ipo_supported(RESULT supported OUTPUT error)
if( supported )
message(STATUS "IPO / LTO enabled")
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()
check_ipo_supported(RESULT has_ipo OUTPUT error)

INCLUDE_DIRECTORIES(${INC_DIR})

AUX_SOURCE_DIRECTORY(./ SRC_DIR)

if(WIN32)
set(OS_SOURCE lib/osdep_win32.cpp)
set(OS_LINK_LIBRARY WinRing0x64)
set(OS_LINK_DIR ./win32)
else()
set(OS_SOURCE lib/osdep_linux.c)
#if (CMAKE_BUILD_TYPE STREQUAL "Release")
#Static link libpci in release build
#set(OS_LINK_LIBRARY libpci.a)
#else()
set(OS_LINK_LIBRARY pci)
#endif()
endif()
add_executable(${PROJECT_NAME} argparse.c main.c)
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "ryzenadj")

LINK_DIRECTORIES(${OS_LINK_DIR})
if(has_ipo)
message(STATUS "${PROJECT_NAME}: IPO / LTO enabled")
set_property(TARGET ${PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()

set(COMMON_SOURCES lib/nb_smu_ops.c lib/api.c lib/cpuid.c)
add_definitions(-D_LIBRYZENADJ_INTERNAL)
if (WIN32)
target_link_directories(${PROJECT_NAME} PRIVATE win32)
endif ()

ADD_EXECUTABLE(${PROJECT_NAME} ${OS_SOURCE} ${COMMON_SOURCES} argparse.c main.c)
target_link_libraries(${PROJECT_NAME} ${OS_LINK_LIBRARY})
#SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE C)
option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
ADD_LIBRARY (libryzenadj ${OS_SOURCE} ${COMMON_SOURCES})
set_target_properties(libryzenadj PROPERTIES PREFIX "")
target_link_libraries(libryzenadj ${OS_LINK_LIBRARY})
#SET_TARGET_PROPERTIES(libryzenadj PROPERTIES LINKER_LANGUAGE C)
include(GNUInstallDirs)
target_link_libraries(${PROJECT_NAME} RYADJ::RyzenAdjLib)
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
43 changes: 37 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,23 @@ On Fedora:

sudo dnf install cmake gcc-c++ pciutils-devel

On Arch:

sudo pacman -S base-devel pciutils cmake

If your Distribution is not supported, try finding the packages or use [Distrobox](https://github.com/89luca89/distrobox) or [Toolbox](https://docs.fedoraproject.org/en-US/fedora-silverblue/toolbox/) instead.

The simplest way to build it:

git clone https://github.com/FlyGoat/RyzenAdj.git
cd RyzenAdj
rm -r win32
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake -B build -DCMAKE_BUILD_TYPE=Release
cd build
make
if [ -d ~/.local/bin ]; then ln -s ryzenadj ~/.local/bin/ryzenadj && echo "symlinked to ~/.local/bin/ryzenadj"; fi
if [ -d ~/.bin ]; then ln -s ryzenadj ~/.bin/ryzenadj && echo "symlinked to ~/.bin/ryzenadj"; fi

To install to your system

make install

### Windows

Expand All @@ -141,4 +146,30 @@ Required dll is included in ./win32 of source tree. Please put the dll
library and sys driver in the same folder with ryzenadj.exe.

We don't recommend you to build by yourself on Windows since the environment configuarion
is very complicated. If you would like to use ryzenadj functions in your program, see libryzenadj.
may be convoluted.
The easier way is to use an IDE like QT Creator, CLion or Visual Studio.

A new option is [Windows Terminal](https://github.com/microsoft/terminal) (pre-installed in Windows 11 and above) and VS 2022.

- Run terminal and open a new `Developer Command Prompt for VS 2022` or `Developer PowerSchell for VS 2022`
- cd to ryzenadj folder
- run `cmake -B build -G Ninja`
- run `ninja -C build`

### Library

If you would like to use ryzenadj functions in your program, see libryzenadj.

If you would like to use ryzenadj in your project, you can add it as submodule or import the folder.

Add ryzenadj library to your CMakeLists.txt

add_subdirectory(PathTo/RyzenAdj/lib EXCLUDE_FROM_ALL)

If building for Windows, add

target_link_directories(${PROJECT_NAME} PRIVATE PathTo/RyzenAdj/win32)

Finally, link libryzenadj

target_link_libraries(${PROJECT_NAME} PRIVATE RYADJ::RyzenAdjLib)
65 changes: 65 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
CMAKE_MINIMUM_REQUIRED(VERSION 3.23)

project(ryzenadj)

option(BUILD_SHARED_LIBS "Build using shared libraries" ON)

include(CheckIPOSupported)
check_ipo_supported(RESULT has_ipo OUTPUT error)

set(PROJECT_SOURCES
nb_smu_ops.c
api.c
cpuid.c
)

set(PUB_HEADERS
ryzenadj.h
)

if (WIN32)
set(LINK_LIBS WinRing0x64)

list(APPEND PROJECT_SOURCES
osdep_win32.cpp
)

elseif (LINUX)
set(LINK_LIBS pci)

list(APPEND PROJECT_SOURCES
osdep_linux.c
)

else ()
message(FATAL_ERROR "!Unsupported OS!")
endif ()

add_library(${PROJECT_NAME} ${PUB_HEADERS} ${PROJECT_SOURCES})
add_library("RYADJ::RyzenAdjLib" ALIAS ${PROJECT_NAME})

if(has_ipo)
message(STATUS "${PROJECT_NAME}: IPO / LTO enabled")
set_property(TARGET ${PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
endif()

if (WIN32)
set_target_properties(${PROJECT_NAME} PROPERTIES OUTPUT_NAME "libryzenadj")
target_link_directories(${PROJECT_NAME} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/../win32")
endif ()

target_compile_definitions(${PROJECT_NAME} PUBLIC _LIBRYZENADJ_INTERNAL)
target_link_libraries(${PROJECT_NAME} ${LINK_LIBS})

target_sources(${PROJECT_NAME} PUBLIC
FILE_SET rylib_headers
TYPE HEADERS
FILES ${PUB_HEADERS}
)

include(GNUInstallDirs)
install(TARGETS ${PROJECT_NAME}
FILE_SET rylib_headers DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
5 changes: 0 additions & 5 deletions lib/ryzenadj_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
#ifndef RYZENADJ_PRIV_H
#define RYZENADJ_PRIV_H

#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>

#include "nb_smu_ops.h"

struct _ryzen_access {
Expand Down
Loading