mirror of
https://github.com/aristocratos/btop.git
synced 2024-05-16 02:13:46 +12:00
Patch RPATH on FreeBSD, support OSX and format
This commit is contained in:
parent
0d357468b5
commit
e35538fa29
131
CMakeLists.txt
131
CMakeLists.txt
|
@ -3,7 +3,7 @@
|
|||
# CMake configuration for btop
|
||||
#
|
||||
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
cmake_minimum_required(VERSION 3.24)
|
||||
|
||||
# Disable in-source builds since they would override the Makefile
|
||||
if("${CMAKE_CURRENT_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
|
@ -17,7 +17,12 @@ project("btop"
|
|||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
# Make custom modules available
|
||||
include(CheckCXXCompilerFlag)
|
||||
include(CheckIncludeFileCXX)
|
||||
include(CheckIPOSupported)
|
||||
include(CMakeDependentOption)
|
||||
|
||||
# Make our Find<Package>.cmake files available
|
||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
|
||||
|
||||
# When the build type is not set we can't fortify
|
||||
|
@ -31,8 +36,6 @@ set(CMAKE_CXX_EXTENSIONS OFF)
|
|||
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)
|
||||
|
@ -41,20 +44,11 @@ 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)
|
||||
if(BTOP_STATIC AND NOT APPLE)
|
||||
# Set this before calling find_package
|
||||
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
|
||||
endif()
|
||||
|
||||
include(CheckCXXCompilerFlag)
|
||||
include(CheckIncludeFileCXX)
|
||||
include(CheckIPOSupported)
|
||||
|
||||
check_include_file_cxx(ranges CXX_HAS_RANGES)
|
||||
if(NOT CXX_HAS_RANGES)
|
||||
message(FATAL_ERROR "The compiler doesn't support <ranges>")
|
||||
endif()
|
||||
|
||||
add_executable(btop
|
||||
src/btop.cpp
|
||||
src/btop_config.cpp
|
||||
|
@ -66,106 +60,98 @@ add_executable(btop
|
|||
src/btop_tools.cpp
|
||||
)
|
||||
|
||||
# NOTE: Checks can be simplified with CMake 3.25
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
||||
target_sources(btop PRIVATE
|
||||
src/osx/btop_collect.cpp
|
||||
src/osx/sensors.cpp
|
||||
src/osx/smc.cpp
|
||||
)
|
||||
if(APPLE)
|
||||
target_sources(btop PRIVATE src/osx/btop_collect.cpp src/osx/sensors.cpp src/osx/smc.cpp)
|
||||
elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
|
||||
target_sources(btop PRIVATE src/freebsd/btop_collect.cpp)
|
||||
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux")
|
||||
elseif(LINUX)
|
||||
target_sources(btop PRIVATE src/linux/btop_collect.cpp)
|
||||
else()
|
||||
message(FATAL_ERROR "${CMAKE_SYSTEM_NAME} is not supported")
|
||||
endif()
|
||||
|
||||
check_include_file_cxx(ranges CXX_HAS_RANGES)
|
||||
if(NOT CXX_HAS_RANGES)
|
||||
message(FATAL_ERROR "The compiler doesn't support <ranges>")
|
||||
endif()
|
||||
|
||||
# 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()
|
||||
|
||||
# TODO: enable more warnings in coordination with upstream
|
||||
target_compile_options(btop PRIVATE
|
||||
-Wall -Wextra -Wpedantic
|
||||
-ftree-vectorize -fstack-clash-protection
|
||||
)
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||
target_compile_options(btop PRIVATE
|
||||
-Wheader-hygiene -Wgnu -Wthread-safety
|
||||
)
|
||||
endif()
|
||||
target_compile_options(btop PRIVATE -Wall -Wextra -Wpedantic -ftree-vectorize)
|
||||
|
||||
if(BTOP_PEDANTIC)
|
||||
target_compile_options(btop PRIVATE
|
||||
-Wshadow -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Wunused
|
||||
-Woverloaded-virtual -Wconversion -Wsign-conversion -Wdouble-promotion
|
||||
-Wformat=2 -Wimplicit-fallthrough -Weffc++
|
||||
-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>
|
||||
)
|
||||
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
|
||||
target_compile_options(btop PRIVATE
|
||||
-Wduplicated-cond -Wduplicated-branches -Wlogical-op -Wnull-dereference
|
||||
-Wuseless-cast
|
||||
)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if(BTOP_WERROR)
|
||||
target_compile_options(btop PRIVATE -Werror)
|
||||
endif()
|
||||
|
||||
check_cxx_compiler_flag(-fstack-protector CXX_HAS_FSTACK_PROTECTOR)
|
||||
if(CXX_HAS_FSTACK_PROTECTOR)
|
||||
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)
|
||||
target_compile_options(btop PRIVATE -fstack-protector)
|
||||
endif()
|
||||
|
||||
check_cxx_compiler_flag(-fcf-protection CXX_HAS_FCF_PROTECTION)
|
||||
if(CXX_HAS_FCF_PROTECTION)
|
||||
check_cxx_compiler_flag(-fcf-protection HAS_FCF_PROTECTION)
|
||||
if(HAS_FCF_PROTECTION)
|
||||
target_compile_options(btop PRIVATE -fcf-protection)
|
||||
endif()
|
||||
|
||||
target_compile_definitions(btop PRIVATE
|
||||
_FILE_OFFSET_BITS=64
|
||||
_GLIBCXX_ASSERTIONS _LIBCPP_ENABLE_ASSERTIONS=1
|
||||
$<$<CONFIG:Debug>:_GLIBCXX_ASSERTIONS _LIBCPP_ENABLE_ASSERTIONS=1>
|
||||
# Only has an effect with optimizations enabled
|
||||
$<$<NOT:$<CONFIG:Debug>>:_FORTIFY_SOURCE=2>
|
||||
)
|
||||
|
||||
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)
|
||||
|
||||
# Enable GPU support
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND BTOP_GPU)
|
||||
if(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
|
||||
# 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
|
||||
# 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 :-/)
|
||||
# Export ROCm's properties to a target
|
||||
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)
|
||||
target_link_libraries(btop ROCm)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
target_include_directories(btop SYSTEM PRIVATE include)
|
||||
|
||||
# mold
|
||||
if(BTOP_USE_MOLD)
|
||||
target_link_options(btop PRIVATE -fuse-ld=mold)
|
||||
endif()
|
||||
|
@ -175,21 +161,28 @@ if(BTOP_STATIC)
|
|||
target_link_options(btop PRIVATE -static LINKER:--fatal-warnings)
|
||||
endif()
|
||||
|
||||
# Add libraries
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
find_package(Threads REQUIRED)
|
||||
target_link_libraries(btop PRIVATE Threads::Threads)
|
||||
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
|
||||
target_link_libraries(btop PRIVATE $<LINK_LIBRARY:FRAMEWORK,CoreFoundation)
|
||||
target_link_libraries(btop PRIVATE $<LINK_LIBRARY:FRAMEWORK,IOKit)
|
||||
# Other platform depdendent flags
|
||||
if(APPLE)
|
||||
target_link_libraries(btop
|
||||
$<LINK_LIBRARY:FRAMEWORK,CoreFoundation> $<LINK_LIBRARY:FRAMEWORK,IOKit>
|
||||
)
|
||||
elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
|
||||
# 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()
|
||||
|
||||
find_package(devstat REQUIRED)
|
||||
find_package(kvm REQUIRED)
|
||||
target_link_libraries(btop PRIVATE devstat::devstat kvm::kvm)
|
||||
target_link_libraries(btop devstat::devstat)
|
||||
if(BTOP_STATIC)
|
||||
find_package(elf REQUIRED)
|
||||
target_link_libraries(btop PRIVATE elf::elf)
|
||||
find_package(kvm REQUIRED)
|
||||
target_link_libraries(btop elf::elf kvm::kvm)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
|
Loading…
Reference in a new issue