-
-
Notifications
You must be signed in to change notification settings - Fork 605
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Linux is completly supported FreeBSD is not able to create a static executable for now. See https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=273398 MacOS was not tested by me
- Loading branch information
Showing
2 changed files
with
281 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# CMake configuration file for btop | ||
cmake_minimum_required(VERSION 3.12) | ||
|
||
# -O3 is not tested right now | ||
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -DNDEBUG" CACHE STRING INTERNAL) | ||
|
||
# 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 build are disable to preserve btop's Makefile") | ||
endif() | ||
|
||
project("btop" | ||
VERSION 1.2.13 | ||
DESCRIPTION "A monitor of resources" | ||
HOMEPAGE_URL "https://github.com/aristocratos/btop" | ||
LANGUAGES CXX | ||
) | ||
|
||
set(CMAKE_COLOR_DIAGNOSTICS ON) | ||
# When the build type is empty we can't properly fortify | ||
if(CMAKE_BUILD_TYPE STREQUAL "") | ||
set(CMAKE_BUILD_TYPE Release) | ||
message(STATUS "Set build type to Release") | ||
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 | ||
) | ||
|
||
# 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 | ||
) | ||
elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") | ||
target_sources(btop PRIVATE src/freebsd/btop_collect.cpp) | ||
elseif(CMAKE_SYSTEM_NAME STREQUAL "Linux") | ||
target_sources(btop PRIVATE src/linux/btop_collect.cpp) | ||
else() | ||
message(FATAL_ERROR "${CMAKE_SYSTEM_NAME} is not supported") | ||
endif() | ||
|
||
option(BTOP_STATIC "Link btop statically" OFF) | ||
if(BTOP_STATIC) | ||
target_compile_definitions(btop PRIVATE STATIC_BUILD) | ||
target_link_options(btop PRIVATE -static) | ||
endif() | ||
|
||
option(BTOP_STRIP "Strip executable" ON) | ||
if(BTOP_STRIP AND CMAKE_BUILD_TYPE STREQUAL "Release") | ||
target_link_options(btop PRIVATE -s) | ||
endif() | ||
|
||
set_target_properties(btop PROPERTIES | ||
CXX_STANDARD 20 | ||
CXX_STANDARD_REQUIRED ON | ||
CXX_EXTENSIONS OFF | ||
INTERPROCEDURAL_OPTIMIZATION ON | ||
) | ||
|
||
include(CheckCXXCompilerFlag) | ||
check_cxx_compiler_flag(-fstack-protector CXX_HAS_FSTACK_PROTECTOR) | ||
# TODO: enable more warnings in coordination with upstream | ||
# TODO: filter out -fstack-clash-protection on arm chips | ||
target_compile_options(btop PRIVATE -Wall -Wextra -Wpedantic | ||
-ftree-vectorize -fstack-clash-protection -fcf-protection | ||
$<$<BOOL:CXX_HAS_FSTACK_PROTECTOR>:-fstack-protector> | ||
) | ||
|
||
target_compile_definitions(btop PRIVATE | ||
_FILE_OFFSET_BITS=64 | ||
|
||
_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) | ||
|
||
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) | ||
elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") | ||
target_link_libraries(btop PRIVATE kvm devstat) | ||
if(BTOP_STATIC) | ||
target_link_libraries(btop PRIVATE elf) | ||
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters