2023-08-29 20:39:00 +02:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
#
|
|
|
|
# CMake configuration for btop
|
|
|
|
#
|
|
|
|
|
2023-12-02 00:34:32 +01:00
|
|
|
cmake_minimum_required(VERSION 3.24)
|
2023-08-29 20:39:00 +02:00
|
|
|
|
|
|
|
# Disable in-source builds since they would override the Makefile
|
|
|
|
if("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
|
|
|
|
message(FATAL_ERROR "In-source builds are not allowed")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
project("btop"
|
|
|
|
VERSION 1.2.13
|
|
|
|
DESCRIPTION "A monitor of resources"
|
|
|
|
HOMEPAGE_URL "https://github.com/aristocratos/btop"
|
|
|
|
LANGUAGES CXX
|
|
|
|
)
|
|
|
|
|
2023-12-02 00:34:32 +01:00
|
|
|
include(CheckCXXCompilerFlag)
|
|
|
|
include(CheckIncludeFileCXX)
|
|
|
|
include(CheckIPOSupported)
|
|
|
|
include(CMakeDependentOption)
|
|
|
|
|
|
|
|
# Make our Find<Package>.cmake files available
|
2023-08-29 20:39:00 +02:00
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
|
|
|
|
|
|
|
|
# When the build type is not set we can't fortify
|
|
|
|
if(NOT CMAKE_BUILD_TYPE)
|
|
|
|
set(CMAKE_BUILD_TYPE Release)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
set(CMAKE_CXX_STANDARD 20)
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
|
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
|
|
|
set(CMAKE_COLOR_DIAGNOSTICS ON)
|
|
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
|
|
|
|
|
|
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)
|
2023-11-26 22:56:58 +01:00
|
|
|
option(BTOP_GPU "Enable GPU support" ON)
|
|
|
|
cmake_dependent_option(BTOP_RSMI_STATIC "Link statically to ROCm SMI" OFF "BTOP_GPU" OFF)
|
2023-08-29 20:39:00 +02:00
|
|
|
|
2023-12-02 00:34:32 +01:00
|
|
|
if(BTOP_STATIC AND NOT APPLE)
|
2023-08-29 20:39:00 +02:00
|
|
|
# Set this before calling find_package
|
|
|
|
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
add_executable(btop
|
|
|
|
src/btop.cpp
|
|
|
|
src/btop_config.cpp
|
|
|
|
src/btop_draw.cpp
|
|
|
|
src/btop_input.cpp
|
|
|
|
src/btop_menu.cpp
|
|
|
|
src/btop_shared.cpp
|
|
|
|
src/btop_theme.cpp
|
|
|
|
src/btop_tools.cpp
|
|
|
|
)
|
|
|
|
|
2023-12-02 00:34:32 +01:00
|
|
|
if(APPLE)
|
|
|
|
target_sources(btop PRIVATE src/osx/btop_collect.cpp src/osx/sensors.cpp src/osx/smc.cpp)
|
2023-08-29 20:39:00 +02:00
|
|
|
elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
|
|
|
|
target_sources(btop PRIVATE src/freebsd/btop_collect.cpp)
|
2023-12-02 00:34:32 +01:00
|
|
|
elseif(LINUX)
|
2023-08-29 20:39:00 +02:00
|
|
|
target_sources(btop PRIVATE src/linux/btop_collect.cpp)
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "${CMAKE_SYSTEM_NAME} is not supported")
|
|
|
|
endif()
|
|
|
|
|
2023-12-02 00:35:13 +01:00
|
|
|
check_include_file_cxx(ranges CXX_HAVE_RANGES)
|
|
|
|
if(NOT CXX_HAVE_RANGES)
|
2023-12-02 00:34:32 +01:00
|
|
|
message(FATAL_ERROR "The compiler doesn't support <ranges>")
|
|
|
|
endif()
|
|
|
|
|
2023-08-29 20:39:00 +02:00
|
|
|
# Check for and enable LTO
|
|
|
|
check_ipo_supported(RESULT ipo_supported)
|
|
|
|
if(ipo_supported AND BTOP_LTO)
|
|
|
|
set_target_properties(btop PROPERTIES INTERPROCEDURAL_OPTIMIZATION ON)
|
|
|
|
endif()
|
|
|
|
|
2023-12-02 00:34:32 +01:00
|
|
|
target_compile_options(btop PRIVATE -Wall -Wextra -Wpedantic -ftree-vectorize)
|
2023-08-29 20:39:00 +02:00
|
|
|
|
|
|
|
if(BTOP_PEDANTIC)
|
|
|
|
target_compile_options(btop PRIVATE
|
2023-12-02 00:34:32 +01:00
|
|
|
-Wshadow -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Wunused -Woverloaded-virtual
|
|
|
|
-Wconversion -Wsign-conversion -Wdouble-promotion -Wformat=2 -Wimplicit-fallthrough -Weffc++
|
|
|
|
$<$<CXX_COMPILER_ID:Clang>:-Wheader-hygiene -Wgnu -Wthread-safety>
|
|
|
|
$<$<CXX_COMPILER_ID:GNU>:-Wduplicated-cond -Wduplicated-branches -Wlogical-op>
|
|
|
|
$<$<CXX_COMPILER_ID:GNU>:-Wnull-dereference -Wuseless-cast>
|
2023-08-29 20:39:00 +02:00
|
|
|
)
|
|
|
|
endif()
|
|
|
|
if(BTOP_WERROR)
|
|
|
|
target_compile_options(btop PRIVATE -Werror)
|
|
|
|
endif()
|
|
|
|
|
2023-12-02 00:34:32 +01:00
|
|
|
if(NOT APPLE)
|
|
|
|
target_compile_options(btop PRIVATE -fstack-clash-protection)
|
|
|
|
endif()
|
|
|
|
check_cxx_compiler_flag(-fstack-protector HAS_FSTACK_PROTECTOR)
|
|
|
|
if(HAS_FSTACK_PROTECTOR)
|
2023-08-29 20:39:00 +02:00
|
|
|
target_compile_options(btop PRIVATE -fstack-protector)
|
|
|
|
endif()
|
2023-12-02 00:34:32 +01:00
|
|
|
check_cxx_compiler_flag(-fcf-protection HAS_FCF_PROTECTION)
|
|
|
|
if(HAS_FCF_PROTECTION)
|
2023-08-29 20:39:00 +02:00
|
|
|
target_compile_options(btop PRIVATE -fcf-protection)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
target_compile_definitions(btop PRIVATE
|
|
|
|
_FILE_OFFSET_BITS=64
|
2023-12-02 00:34:32 +01:00
|
|
|
$<$<CONFIG:Debug>:_GLIBCXX_ASSERTIONS _LIBCPP_ENABLE_ASSERTIONS=1>
|
2023-08-29 20:39:00 +02:00
|
|
|
# Only has an effect with optimizations enabled
|
|
|
|
$<$<NOT:$<CONFIG:Debug>>:_FORTIFY_SOURCE=2>
|
|
|
|
)
|
|
|
|
|
2023-12-02 00:34:32 +01:00
|
|
|
target_include_directories(btop SYSTEM PRIVATE include)
|
|
|
|
|
|
|
|
# Enable pthreads
|
|
|
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
|
|
|
find_package(Threads REQUIRED)
|
|
|
|
target_link_libraries(btop Threads::Threads)
|
|
|
|
|
2023-11-26 22:56:58 +01:00
|
|
|
# Enable GPU support
|
2023-12-02 00:34:32 +01:00
|
|
|
if(LINUX AND BTOP_GPU)
|
2023-11-26 22:56:58 +01:00
|
|
|
target_compile_definitions(btop PRIVATE GPU_SUPPORT)
|
|
|
|
|
|
|
|
if(BTOP_RSMI_STATIC)
|
2023-12-02 00:34:32 +01:00
|
|
|
# ROCm doesn't properly add it's folders to the module path if `CMAKE_MODULE_PATH` is already
|
|
|
|
# set
|
2023-11-26 22:56:58 +01:00
|
|
|
# We could also manully append ROCm's path here
|
|
|
|
set(_CMAKE_MODULE_PATH CMAKE_MODULE_PATH)
|
|
|
|
unset(CMAKE_MODULE_PATH)
|
|
|
|
|
2023-12-02 00:34:32 +01:00
|
|
|
# NOTE: This might be problematic in the future if other sub projects depend on this or if
|
|
|
|
# btop starts producing libraries
|
2023-11-26 22:56:58 +01:00
|
|
|
# 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)
|
2023-12-02 00:34:32 +01:00
|
|
|
# Export ROCm's properties to a target
|
2023-11-26 22:56:58 +01:00
|
|
|
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)
|
|
|
|
|
2023-12-02 00:34:32 +01:00
|
|
|
target_link_libraries(btop ROCm)
|
2023-11-26 22:56:58 +01:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2023-08-29 20:39:00 +02:00
|
|
|
if(BTOP_USE_MOLD)
|
|
|
|
target_link_options(btop PRIVATE -fuse-ld=mold)
|
|
|
|
endif()
|
|
|
|
|
|
|
|
if(BTOP_STATIC)
|
|
|
|
target_compile_definitions(btop PRIVATE STATIC_BUILD)
|
|
|
|
target_link_options(btop PRIVATE -static LINKER:--fatal-warnings)
|
|
|
|
endif()
|
|
|
|
|
2023-12-02 00:34:32 +01:00
|
|
|
# Other platform depdendent flags
|
|
|
|
if(APPLE)
|
|
|
|
target_link_libraries(btop
|
|
|
|
$<LINK_LIBRARY:FRAMEWORK,CoreFoundation> $<LINK_LIBRARY:FRAMEWORK,IOKit>
|
|
|
|
)
|
2023-08-29 20:39:00 +02:00
|
|
|
elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
|
2023-12-02 00:34:32 +01:00
|
|
|
# Avoid version mismatch for libstdc++ when a specific version of GCC is installed and not the
|
|
|
|
# default one since all use the default ones RPATH
|
|
|
|
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
|
|
|
string(REGEX MATCH "^[0-9]+" GCC_VERSION_MAJOR "${CMAKE_CXX_COMPILER_VERSION}")
|
|
|
|
set_target_properties(btop PROPERTIES
|
|
|
|
INSTALL_RPATH "/usr/local/lib/gcc${GCC_VERSION_MAJOR}"
|
|
|
|
BUILD_WITH_INSTALL_RPATH TRUE
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2023-11-26 21:39:13 +01:00
|
|
|
find_package(devstat REQUIRED)
|
2023-12-02 00:34:32 +01:00
|
|
|
target_link_libraries(btop devstat::devstat)
|
2023-08-29 20:39:00 +02:00
|
|
|
if(BTOP_STATIC)
|
2023-11-26 21:39:13 +01:00
|
|
|
find_package(elf REQUIRED)
|
2023-12-02 00:34:32 +01:00
|
|
|
find_package(kvm REQUIRED)
|
|
|
|
target_link_libraries(btop elf::elf kvm::kvm)
|
2023-08-29 20:39:00 +02:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
|
|
|
install(TARGETS btop RUNTIME)
|
|
|
|
install(FILES "btop.desktop" DESTINATION "share/applications")
|
|
|
|
install(FILES "Img/icon.png" DESTINATION "share/icons/hicolor/48x48/apps" RENAME "btop.png")
|
|
|
|
install(FILES "Img/icon.svg" DESTINATION "share/icons/hicolor/scalable/apps" RENAME "btop.svg")
|
|
|
|
install(DIRECTORY "themes" DESTINATION "share/btop")
|
|
|
|
|