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 to allow for integrations in other projects #306

Merged
merged 11 commits into from
Sep 5, 2024
14 changes: 6 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ jobs:
#don't use run-cmake for windows because only one build should add warnings to pull request
- name: Build 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
Expand All @@ -28,20 +27,19 @@ jobs:
name: ryzenadj-win64-debug
path: |
debug/ryzenadj.exe
debug/libryzenadj.dll
debug/lib/libryzenadj.dll

- name: Build Release
run: |
mkdir build
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
run: |
mkdir release
copy build/ryzenadj.exe release/
copy build/libryzenadj.dll release/
copy build/lib/libryzenadj.dll release/
copy win32/* release/
copy examples/* release/

Expand Down Expand Up @@ -86,8 +84,8 @@ jobs:
with:
name: libryzenadj-win64
path: |
./build/libryzenadj.dll
./build/libryzenadj.lib
./build/lib/libryzenadj.dll
./build/lib/libryzenadj.lib
./lib/ryzenadj.h
./win32/inpoutx64.dll
./win32/WinRing0x64.dll
Expand Down
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-*
55 changes: 15 additions & 40 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,53 +1,28 @@
#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}")
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})
36 changes: 30 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,23 @@ 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.
is very complicated.
The easier way is to use an IDE like QT Creator, CLion or Visual Studio.

### 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