Skip to content

Commit

Permalink
Add GPU options for cmake based builds
Browse files Browse the repository at this point in the history
  • Loading branch information
imwints committed Nov 27, 2023
1 parent 7588d96 commit 2f59e61
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
33 changes: 33 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ set(CMAKE_COLOR_DIAGNOSTICS ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

# Options
include(CMakeDependentOption)
option(BTOP_STATIC "Link btop statically" OFF)
option(BTOP_LTO "Enable LTO" ON)
option(BTOP_USE_MOLD "Use mold to link btop" OFF)
option(BTOP_PEDANTIC "Enable a bunch of additional warnings" OFF)
option(BTOP_WERROR "Compile with warnings as errors" OFF)
option(BTOP_GPU "Enable GPU support" ON)
cmake_dependent_option(BTOP_RSMI_STATIC "Link statically to ROCm SMI" OFF "BTOP_GPU" OFF)

if(BTOP_STATIC)
# Set this before calling find_package
Expand Down Expand Up @@ -130,6 +133,36 @@ target_compile_definitions(btop PRIVATE
$<$<NOT:$<CONFIG:Debug>>:_FORTIFY_SOURCE=2>
)

# Enable GPU support
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND BTOP_GPU)
target_compile_definitions(btop PRIVATE GPU_SUPPORT)

if(BTOP_RSMI_STATIC)
# ROCm doesn't properly add it's folders to the module path
# if `CMAKE_MODULE_PATH` is already set
# We could also manully append ROCm's path here
set(_CMAKE_MODULE_PATH CMAKE_MODULE_PATH)
unset(CMAKE_MODULE_PATH)

# NOTE: This might be problematic in the future if other sub projects
# depend on this or if btop starts producing libraries
# Build a static ROCm library
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)

add_subdirectory(lib/rocm_smi_lib EXCLUDE_FROM_ALL)

add_library(ROCm INTERFACE)
# Export ROCm's properties to a CMake target (which should've been done by ROCm :-/)
target_compile_definitions(ROCm INTERFACE RSMI_STATIC)
target_include_directories(ROCm INTERFACE lib/rocm_smi_lib/include)
target_link_libraries(ROCm INTERFACE rocm_smi64)

set(CMAKE_MODULE_PATH _CMAKE_MODULE_PATH)

target_link_libraries(btop PRIVATE ROCm)
endif()
endif()

target_include_directories(btop SYSTEM PRIVATE include)

# mold
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ Also needs a UTF8 locale and a font that covers:

For x86_64 Linux the flag `GPU_SUPPORT` is automatically set to `true`, to manually disable gpu support set the flag to false, like:

`make GPU_SUPPORT=false`
`make GPU_SUPPORT=false` (or `cmake -DBTOP_GPU=false` with CMake)

* **NVIDIA**

Expand Down Expand Up @@ -503,6 +503,8 @@ Also needs a UTF8 locale and a font that covers:
| `-DBTOP_USE_MOLD=<ON\|OFF>` | Use mold to link btop (OFF by default) |
| `-DBTOP_PEDANTIC=<ON\|OFF>` | Compile with additional warnings (OFF by default) |
| `-DBTOP_WERROR=<ON\|OFF>` | Compile with warnings as errors (OFF by default) |
| `-DBTOP_GPU=<ON\|OFF>` | Enable GPU support (ON by default) |
| `-DBTOP_RSMI_STATIC=<ON\|OFF>` | Build and link the ROCm SMI library statically (OFF by default) |
| `-DCMAKE_INSTALL_PREFIX=<path>` | The installation prefix ('/usr/local' by default) |
To force a compiler, run `CXX=<compiler> cmake -B build -G Ninja`
Expand Down

0 comments on commit 2f59e61

Please sign in to comment.