diff --git a/CMakeLists.txt b/CMakeLists.txt index 44ae888..ce4891d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -130,6 +133,36 @@ target_compile_definitions(btop PRIVATE $<$>:_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 diff --git a/README.md b/README.md index 140347a..4ee8474 100644 --- a/README.md +++ b/README.md @@ -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** @@ -503,6 +503,8 @@ Also needs a UTF8 locale and a font that covers: | `-DBTOP_USE_MOLD=` | Use mold to link btop (OFF by default) | | `-DBTOP_PEDANTIC=` | Compile with additional warnings (OFF by default) | | `-DBTOP_WERROR=` | Compile with warnings as errors (OFF by default) | + | `-DBTOP_GPU=` | Enable GPU support (ON by default) | + | `-DBTOP_RSMI_STATIC=` | Build and link the ROCm SMI library statically (OFF by default) | | `-DCMAKE_INSTALL_PREFIX=` | The installation prefix ('/usr/local' by default) | To force a compiler, run `CXX= cmake -B build -G Ninja`