master CMakeLists.txt
ohmu  ·  2026-10-15
   1cmake_minimum_required(VERSION 3.21.0) # C_STANDARD C17 and C23
   2
   3project(fastfetch
   4    VERSION 2.70.0
   5    LANGUAGES C
   6    DESCRIPTION "Fast neofetch-like system information tool"
   7    HOMEPAGE_URL "https://github.com/fastfetch-cli/fastfetch"
   8)
   9
  10set(PROJECT_LICENSE "MIT license")
  11
  12string(TOLOWER "${CMAKE_SYSTEM_PROCESSOR}" CMAKE_SYSTEM_PROCESSOR)
  13if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
  14    set(CMAKE_SYSTEM_PROCESSOR "amd64")
  15elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL "arm64")
  16    set(CMAKE_SYSTEM_PROCESSOR "aarch64")
  17endif()
  18message(STATUS "Build for system processor: ${CMAKE_SYSTEM_PROCESSOR}")
  19
  20###################
  21# Target Platform #
  22###################
  23if(ANDROID)
  24    set(LINUX FALSE)
  25elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
  26    set(LINUX TRUE CACHE BOOL "..." FORCE) # LINUX means GNU/Linux, not just the kernel
  27elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "FreeBSD")
  28    set(FreeBSD TRUE CACHE BOOL "..." FORCE)
  29elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "OpenBSD")
  30    set(OpenBSD TRUE CACHE BOOL "..." FORCE)
  31elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "MidnightBSD")
  32    set(FreeBSD TRUE CACHE BOOL "..." FORCE)
  33    set(MidnightBSD TRUE CACHE BOOL "..." FORCE)
  34elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "NetBSD")
  35    set(NetBSD TRUE CACHE BOOL "..." FORCE)
  36elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "DragonFly")
  37    set(FreeBSD TRUE CACHE BOOL "..." FORCE)
  38    set(DragonFly TRUE CACHE BOOL "..." FORCE)
  39elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "SunOS")
  40    set(SunOS TRUE CACHE BOOL "..." FORCE)
  41elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "Haiku")
  42    set(Haiku TRUE CACHE BOOL "..." FORCE)
  43elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "GNU")
  44    set(GNU TRUE CACHE BOOL "..." FORCE)
  45elseif(NOT APPLE AND NOT WIN32)
  46    message(FATAL_ERROR "Unsupported platform: ${CMAKE_SYSTEM_NAME}")
  47endif()
  48
  49#############################
  50# Compile time dependencies #
  51#############################
  52
  53set(THREADS_PREFER_PTHREAD_FLAG NOT WIN32)
  54find_package(Threads)
  55
  56find_package(PkgConfig)
  57if(NOT PKG_CONFIG_FOUND)
  58    message(WARNING "pkg-config not found, library detection might be limited")
  59endif()
  60
  61include(CheckIncludeFile)
  62include(CheckFunctionExists)
  63include(CheckSymbolExists)
  64
  65if(LINUX)
  66    CHECK_INCLUDE_FILE("linux/version.h" HAVE_LINUX_VERSION_H)
  67    if(NOT HAVE_LINUX_VERSION_H)
  68        message(FATAL_ERROR "Linux headers (linux/version.h) not found! Please install linux-headers package.")
  69    endif()
  70endif()
  71
  72#####################
  73# Configure options #
  74#####################
  75
  76include(CMakeDependentOption)
  77
  78cmake_dependent_option(ENABLE_VULKAN "Enable vulkan" ON "LINUX OR APPLE OR FreeBSD OR OpenBSD OR NetBSD OR WIN32 OR ANDROID OR SunOS OR Haiku OR GNU" OFF)
  79cmake_dependent_option(ENABLE_WAYLAND "Enable wayland-client" ON "ANDROID OR LINUX OR FreeBSD OR OpenBSD OR NetBSD" OFF)
  80cmake_dependent_option(ENABLE_XCB_RANDR "Enable xcb-randr" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR ANDROID OR SunOS OR GNU" OFF)
  81cmake_dependent_option(ENABLE_XRANDR "Enable xrandr" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR ANDROID OR SunOS OR GNU" OFF)
  82cmake_dependent_option(ENABLE_DRM "Enable libdrm" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS OR GNU" OFF)
  83cmake_dependent_option(ENABLE_VADRM "Enable libva-drm" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS OR GNU" OFF)
  84cmake_dependent_option(ENABLE_VAX11 "Enable libva-x11" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS OR GNU" OFF)
  85cmake_dependent_option(ENABLE_VDPAU "Enable vdpau" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS OR GNU" OFF)
  86cmake_dependent_option(ENABLE_GIO "Enable gio-2.0" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR ANDROID OR SunOS OR GNU" OFF)
  87cmake_dependent_option(ENABLE_DCONF "Enable dconf" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR ANDROID OR SunOS OR GNU" OFF)
  88cmake_dependent_option(ENABLE_EET "Enable eet" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR ANDROID OR SunOS OR GNU" OFF)
  89cmake_dependent_option(ENABLE_DBUS "Enable dbus-1" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR ANDROID OR SunOS OR Haiku OR GNU" OFF)
  90cmake_dependent_option(ENABLE_SQLITE3 "Enable sqlite3" ON "LINUX OR FreeBSD OR APPLE OR OpenBSD OR NetBSD OR SunOS OR GNU" OFF)
  91cmake_dependent_option(ENABLE_RPM "Enable rpm" ON "LINUX OR GNU" OFF)
  92cmake_dependent_option(ENABLE_EGL "Enable egl" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR ANDROID OR WIN32 OR SunOS OR Haiku OR GNU" OFF)
  93cmake_dependent_option(ENABLE_GLX "Enable glx" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR ANDROID OR SunOS OR GNU" OFF)
  94cmake_dependent_option(ENABLE_OPENCL "Enable opencl" ON "LINUX OR FreeBSD OR OpenBSD OR NetBSD OR WIN32 OR ANDROID OR SunOS OR Haiku OR GNU" OFF)
  95cmake_dependent_option(ENABLE_FREETYPE "Enable freetype" ON "ANDROID" OFF)
  96cmake_dependent_option(ENABLE_ELF "Enable libelf" ON "LINUX OR ANDROID OR DragonFly OR Haiku OR GNU" OFF)
  97cmake_dependent_option(ENABLE_THREADS "Enable multithreading" ON "Threads_FOUND" OFF)
  98
  99option(ENABLE_IMAGE_LOGO "Enable image logos (sixel / kitty / iTerm / chafa)" ON)
 100# The four below are declared outside the guard on purpose. `cmake_dependent_option` is a macro: when
 101# the condition is false it is never expanded, so nothing rewrites the value already sitting in
 102# CMakeCache.txt, and `cmake -DENABLE_IMAGE_LOGO=OFF .` in an existing build directory would leave
 103# ENABLE_SIXEL=ON behind -- sixel and chafa would still be compiled and linked while image.c, the
 104# only file that uses them, is not. The condition does the disabling instead: it is the fourth
 105# argument's job, and it keeps the option visible and settable in cmake-gui either way.
 106cmake_dependent_option(ENABLE_IMAGEMAGICK7 "Enable imagemagick 7" ON "ENABLE_IMAGE_LOGO;LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS OR Haiku OR GNU" OFF)
 107cmake_dependent_option(ENABLE_IMAGEMAGICK6 "Enable imagemagick 6" ON "ENABLE_IMAGE_LOGO;LINUX OR FreeBSD OR OpenBSD OR NetBSD OR SunOS OR GNU" OFF)
 108cmake_dependent_option(ENABLE_SIXEL "Enable sixel logo output via the embedded libsixel encoder (Windows, macOS and Android; replaces ImageMagick's SIXEL coder)" ON "ENABLE_IMAGE_LOGO;WIN32 OR APPLE OR ANDROID" OFF)
 109cmake_dependent_option(ENABLE_CHAFA "Enable chafa" ON "ENABLE_IMAGE_LOGO;ENABLE_IMAGEMAGICK6 OR ENABLE_IMAGEMAGICK7 OR WIN32 OR APPLE OR ANDROID" OFF)
 110
 111option(ENABLE_ZLIB "Enable zlib" ON)
 112option(ENABLE_SYSTEM_YYJSON "Use system provided (instead of fastfetch embedded) yyjson library" OFF)
 113option(ENABLE_ASAN "Build fastfetch with ASAN (address sanitizer)" OFF)
 114option(ENABLE_TRACER "Build fastfetch with function tracing" OFF)
 115option(ENABLE_LTO "Enable link-time optimization in release mode if supported" ON)
 116option(BUILD_FLASHFETCH "Build flashfetch" ON) # Also build the flashfetch binary
 117option(BUILD_TESTS "Build tests" OFF) # Also create test executables
 118option(SET_TWEAK "Add tweak to project version" ON) # This is set to off by github actions for release builds
 119option(IS_MUSL "Build with musl libc" OFF) # Used by Github Actions
 120option(INSTALL_LICENSE "Install license into /usr/share/licenses" ON)
 121option(ENABLE_EMBEDDED_PCIIDS "Embed pci.ids into fastfetch, requires `python`" OFF)
 122option(ENABLE_EMBEDDED_AMDGPUIDS "Embed amdgpu.ids into fastfetch, requires `python`" OFF)
 123option(ENABLE_WORDEXP "Enable using of wordexp(3) if available, instead of glob(3)" ON)
 124option(ENABLE_LUA "Enable lua scripting for format strings" ON)
 125option(ENABLE_LIBZFS "Enable libzfs" ON)
 126option(ENABLE_WCWIDTH "Detect wide-width characters with wcwidth when calculating logo and separator width. Disable for a smaller and slightly faster build, but logos containing CJK/emoji may be measured too narrow and render incorrectly. Such usecases are uncommon." ON)
 127set(DEFAULT_STRUCTURE "Title:Separator:OS:Host:Kernel:Uptime:Packages:Shell:Display:DE:WM:WMTheme:Theme:Icons:Font:Cursor:Terminal:TerminalFont:CPU:GPU:Memory:Swap:Disk:LocalIp:Battery:PowerAdapter:Locale:Break:Colors" CACHE STRING "Default module structure for detection")
 128if(WIN32 AND NOT CMAKE_SYSTEM_PROCESSOR STREQUAL "aarch64")
 129    option(ENABLE_WIN81_COMPAT "Enable legacy Windows compatibility (Windows 8.1 and later; Windows 7 unsupported)" ON)
 130endif()
 131if(APPLE)
 132    option(ENABLE_APPLE_MEMSIZE_USABLE "Use usable memory size as total memory size in Memory module, to match other systems" OFF)
 133endif()
 134
 135# A module is a directory `src/modules/<module>/` that contains `<module>.c`.
 136# Globbing the sources rather than the directories skips empty directories and
 137# other leftovers, and makes `CONFIGURE_DEPENDS` react to added or removed sources.
 138file(GLOB FF_MODULE_SRCS CONFIGURE_DEPENDS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}/src/modules" "${CMAKE_CURRENT_SOURCE_DIR}/src/modules/*/*.c")
 139set(FF_MODULE_DIRS "")
 140set(FF_MODULE_SRC_DIRS "")
 141foreach(FF_MODULE_SRC ${FF_MODULE_SRCS})
 142    get_filename_component(FF_MODULE_DIR "${FF_MODULE_SRC}" DIRECTORY)
 143    get_filename_component(FF_MODULE_NAME "${FF_MODULE_SRC}" NAME_WE)
 144    if("${FF_MODULE_DIR}" STREQUAL "${FF_MODULE_NAME}")
 145        list(APPEND FF_MODULE_DIRS "${FF_MODULE_DIR}")
 146    endif()
 147    list(APPEND FF_MODULE_SRC_DIRS "${FF_MODULE_DIR}")
 148endforeach()
 149unset(FF_MODULE_SRCS)
 150
 151# A directory of sources whose name no source carries registers no module at all, and nothing else
 152# in the build says so -- the module simply never appears. Reported rather than left to be noticed.
 153# Directories are compared rather than sources, so that a module which keeps helper sources next to
 154# its own `<module>.c` does not warn about every one of them.
 155list(REMOVE_DUPLICATES FF_MODULE_SRC_DIRS)
 156foreach(FF_MODULE_DIR ${FF_MODULE_SRC_DIRS})
 157    if(NOT FF_MODULE_DIR IN_LIST FF_MODULE_DIRS)
 158        message(WARNING "src/modules/${FF_MODULE_DIR}/ contains C sources but no ${FF_MODULE_DIR}.c, "
 159            "so no module is registered for it. A module directory must hold a source file named after it.")
 160    endif()
 161endforeach()
 162unset(FF_MODULE_SRC_DIRS)
 163
 164foreach(FF_MODULE_DIR ${FF_MODULE_DIRS})
 165    string(TOUPPER "${FF_MODULE_DIR}" FF_MODULE_UPPER)
 166    option(MODULE_DISABLE_${FF_MODULE_UPPER} "Disable module ${FF_MODULE_DIR}" OFF)
 167endforeach()
 168
 169set(BINARY_LINK_TYPE_OPTIONS dlopen dynamic static)
 170set(BINARY_LINK_TYPE dlopen CACHE STRING "How to link fastfetch")
 171set_property(CACHE BINARY_LINK_TYPE PROPERTY STRINGS ${BINARY_LINK_TYPE_OPTIONS})
 172if(NOT BINARY_LINK_TYPE IN_LIST BINARY_LINK_TYPE_OPTIONS)
 173    message(FATAL_ERROR "BINARY_LINK_TYPE must be one of ${BINARY_LINK_TYPE_OPTIONS}")
 174endif()
 175
 176file(READ "${CMAKE_CURRENT_SOURCE_DIR}/src/modules/packages/option.h" PACKAGE_MANAGERS)
 177string(REGEX MATCHALL "FF_PACKAGES_FLAG_[A-Z]+_BIT" PACKAGE_MANAGERS "${PACKAGE_MANAGERS}")
 178string(REGEX REPLACE "FF_PACKAGES_FLAG_([A-Z]+)_BIT" "\\1" PACKAGE_MANAGERS "${PACKAGE_MANAGERS}")
 179list(SORT PACKAGE_MANAGERS)
 180foreach(package_manager ${PACKAGE_MANAGERS})
 181    if(package_manager STREQUAL "WINGET")
 182        option(PACKAGES_DISABLE_${package_manager} "Disable ${package_manager} package manager detection by default" ON)
 183    else()
 184        option(PACKAGES_DISABLE_${package_manager} "Disable ${package_manager} package manager detection by default" OFF)
 185    endif()
 186endforeach()
 187option(PACKAGES_REMOVE_DISABLED "Remove disabled package managers from the build entirely, instead of just skipping them at runtime" OFF)
 188
 189if (LINUX)
 190    set(CUSTOM_PCI_IDS_PATH "" CACHE STRING "Custom path to file pci.ids, defaults to `/usr/share/hwdata/pci.ids`")
 191    set(CUSTOM_AMDGPU_IDS_PATH "" CACHE STRING "Custom path to file amdgpu.ids, defaults to `/usr/share/libdrm/amdgpu.ids`")
 192    set(CUSTOM_OS_RELEASE_PATH "" CACHE STRING "Custom path to file os-release, defaults to `/etc/os-release`")
 193endif()
 194
 195####################
 196# Compiler options #
 197####################
 198
 199if(NOT CMAKE_BUILD_TYPE)
 200    set(CMAKE_BUILD_TYPE RelWithDebInfo)
 201endif()
 202
 203message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
 204if(ENABLE_THREADS)
 205    if(CMAKE_USE_WIN32_THREADS_INIT)
 206        message(STATUS "Threads type: Win32 thread")
 207    elseif(CMAKE_USE_PTHREADS_INIT)
 208        message(STATUS "Threads type: pthread")
 209    endif()
 210else()
 211    message(STATUS "Threads type: disabled")
 212endif()
 213
 214set(WARNING_FLAGS "-Wall -Wextra -Wconversion -Werror=uninitialized -Werror=return-type -Werror=vla")
 215
 216if(LINUX)
 217    if(NOT IS_MUSL) # `NOT DEFINED IS_MUSL` doesn't work
 218        execute_process(
 219            COMMAND ${CMAKE_C_COMPILER} -print-file-name=libc.so
 220            OUTPUT_VARIABLE LIBC_PATH
 221            OUTPUT_STRIP_TRAILING_WHITESPACE
 222        )
 223
 224        if(LIBC_PATH MATCHES "-musl")
 225            set(IS_MUSL ON CACHE BOOL "Build with musl libc" FORCE)
 226        endif()
 227    endif()
 228
 229    if(IS_MUSL)
 230        message(STATUS "MUSL libc detected")
 231        # Silence ioctl related warnings
 232        set(WARNING_FLAGS "${WARNING_FLAGS} -Wno-sign-conversion")
 233    endif()
 234endif()
 235
 236# Minimal compiler version supported: GCC 13 (2023-04-26), Clang 16 (2023-03-17)
 237# Most C23 features are allowed with noticeable exceptions of `constexpr` and `#embed`
 238# See https://cppreference.com/c/compiler_support/23 for detail
 239set(CMAKE_C_STANDARD 23)
 240set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} -Werror=incompatible-pointer-types -Werror=implicit-function-declaration -Werror=int-conversion")
 241
 242if(WIN32 OR Haiku)
 243    enable_language(CXX)
 244    if(WIN32)
 245        set(CMAKE_CXX_STANDARD 20)
 246    else()
 247        set(CMAKE_CXX_STANDARD 17)
 248    endif()
 249    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS}")
 250endif()
 251
 252if(WIN32)
 253    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--tsaware -Wl,--build-id")
 254
 255    if(ENABLE_WIN81_COMPAT)
 256        set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--subsystem,console,--major-os-version,6,--minor-os-version,3")
 257    else()
 258        set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--subsystem,console,--major-os-version,10,--minor-os-version,0")
 259    endif()
 260elseif(APPLE AND CMAKE_C_COMPILER_ID MATCHES "Clang")
 261    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fobjc-arc")
 262endif()
 263
 264set(FASTFETCH_FLAGS_DEBUG "-fno-omit-frame-pointer")
 265if(ENABLE_ASAN)
 266    message(STATUS "Address sanitizer enabled (DEBUG only)")
 267    set(FASTFETCH_FLAGS_DEBUG "${FASTFETCH_FLAGS_DEBUG} -fsanitize=address")
 268endif()
 269set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FASTFETCH_FLAGS_DEBUG}")
 270set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${FASTFETCH_FLAGS_DEBUG} -fstack-protector-all -fno-delete-null-pointer-checks")
 271if(NOT WIN32)
 272    set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -rdynamic")
 273endif()
 274
 275if(ENABLE_LTO AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
 276    message(STATUS "Enabling LTO")
 277    include(CheckIPOSupported)
 278    check_ipo_supported(RESULT IPO_SUPPORTED)
 279    if(IPO_SUPPORTED)
 280        set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
 281    endif()
 282endif()
 283
 284# Release and MinSizeRel drop the symbol table and the unwind metadata; Debug and RelWithDebInfo keep
 285# both, so those stay fully debuggable. CMake does not strip MinSizeRel on its own.
 286if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
 287    if(NOT APPLE) # ld: warning: -s is obsolete
 288        # The symbol table is dead weight: 437 KB (16%) of a MinGW build, 91 KB (3%) of a GCC build.
 289        set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-s")
 290    endif()
 291
 292    # Drops .eh_frame / .eh_frame_hdr on ELF (74 KB) and .pdata / .xdata on PE (26 KB). Every C++
 293    # translation unit here is built with -fno-exceptions -fno-rtti and no source file contains a
 294    # single try / catch, so no exception can ever unwind through these frames. The only loss is
 295    # backtrace() / gdb / perf / crash-dump stack walking in a release binary.
 296    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-asynchronous-unwind-tables")
 297    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-asynchronous-unwind-tables")
 298endif()
 299
 300#######################
 301# Target FS structure #
 302#######################
 303
 304if(NOT TARGET_DIR_ROOT)
 305    if(NOT ANDROID)
 306        set(TARGET_DIR_ROOT "")
 307    else()
 308        set(TARGET_DIR_ROOT "/data/data/com.termux/files/usr")
 309    endif()
 310endif()
 311
 312if(NOT TARGET_DIR_USR)
 313    if(NOT ANDROID)
 314        set(TARGET_DIR_USR "${TARGET_DIR_ROOT}/usr")
 315    else()
 316        set(TARGET_DIR_USR "${TARGET_DIR_ROOT}")
 317    endif()
 318endif()
 319
 320if(NOT TARGET_DIR_HOME)
 321    if(APPLE)
 322        set(TARGET_DIR_HOME "${TARGET_DIR_ROOT}/Users")
 323    elseif(ANDROID)
 324        set(TARGET_DIR_HOME "/data/data/com.termux/files/home")
 325    else()
 326        set(TARGET_DIR_HOME "${TARGET_DIR_ROOT}/home")
 327    endif()
 328endif()
 329
 330if(NOT TARGET_DIR_ETC)
 331    set(TARGET_DIR_ETC "${TARGET_DIR_ROOT}/etc")
 332endif()
 333
 334message(STATUS "Target dirs: ROOT=\"${TARGET_DIR_ROOT}\" USR=\"${TARGET_DIR_USR}\" HOME=\"${TARGET_DIR_HOME}\" ETC=\"${TARGET_DIR_ETC}\"")
 335
 336#https://cmake.org/cmake/help/latest/variable/CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT.html
 337if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
 338    set(CMAKE_INSTALL_PREFIX "${TARGET_DIR_USR}" CACHE PATH "..." FORCE)
 339endif()
 340
 341if(NOT CMAKE_INSTALL_SYSCONFDIR)
 342    set(CMAKE_INSTALL_SYSCONFDIR "${TARGET_DIR_ETC}" CACHE PATH "..." FORCE)
 343endif()
 344
 345#################
 346# Tweak version #
 347#################
 348
 349if (SET_TWEAK AND EXISTS "${CMAKE_SOURCE_DIR}/.git")
 350    execute_process(
 351        COMMAND git describe --tags
 352        WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
 353        OUTPUT_VARIABLE PROJECT_VERSION_GIT
 354        OUTPUT_STRIP_TRAILING_WHITESPACE
 355    )
 356    string(REGEX MATCH "-[0-9]+" PROJECT_VERSION_TWEAK "${PROJECT_VERSION_GIT}")
 357endif()
 358if(PROJECT_VERSION_TWEAK)
 359    string(REGEX MATCH "[0-9]+" PROJECT_VERSION_TWEAK_NUM "${PROJECT_VERSION_TWEAK}")
 360else()
 361    set(PROJECT_VERSION_TWEAK_NUM 0)
 362endif()
 363
 364#############
 365# Text data #
 366#############
 367
 368function(fastfetch_encode_c_string STR OUTVAR)
 369    string(REGEX REPLACE "\n$" "" TEMP "${STR}")  # Remove trailing newline
 370    string(REPLACE "\\" "\\\\" TEMP "${TEMP}")    # Escape backslashes
 371    string(REPLACE "\n" "\\n" TEMP "${TEMP}")     # Replace newlines with \n
 372    string(REPLACE "\"" "\\\"" TEMP "${TEMP}")    # Replace quotes with \"
 373    set(${OUTVAR} "\"${TEMP}\"" PARENT_SCOPE)
 374endfunction(fastfetch_encode_c_string)
 375
 376function(fastfetch_load_text FILENAME OUTVAR)
 377    file(READ "${FILENAME}" TEMP)
 378    fastfetch_encode_c_string("${TEMP}" TEMP)
 379    set(${OUTVAR} "${TEMP}" PARENT_SCOPE)
 380endfunction(fastfetch_load_text)
 381
 382find_package(Python)
 383if(Python_FOUND)
 384    message(STATUS "Minifying 'help.json'")
 385    execute_process(COMMAND ${Python_EXECUTABLE} -c "import json,sys;json.dump(json.load(sys.stdin),sys.stdout,separators=(',',':'))"
 386                    INPUT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/doc/help.json"
 387                    OUTPUT_VARIABLE DATATEXT_JSON_HELP)
 388    if(DATATEXT_JSON_HELP STREQUAL "")
 389        message(ERROR "DATATEXT_JSON_HELP is empty, which should not happen!")
 390    endif()
 391else()
 392    message(WARNING "Python3 is not found, 'help.json' will not be minified")
 393    file(READ "${CMAKE_CURRENT_SOURCE_DIR}/doc/help.json" DATATEXT_JSON_HELP)
 394endif()
 395
 396if(ENABLE_EMBEDDED_PCIIDS AND NOT EXISTS "${PROJECT_BINARY_DIR}/fastfetch_pciids.c.inc")
 397    if(Python_FOUND)
 398        if(NOT EXISTS "${PROJECT_BINARY_DIR}/pci.ids")
 399            message(STATUS "'${PROJECT_BINARY_DIR}/pci.ids' is missing, downloading...")
 400            file(DOWNLOAD "https://pci-ids.ucw.cz/v2.2/pci.ids" "${PROJECT_BINARY_DIR}/pci.ids")
 401        endif()
 402        message(STATUS "Generating 'fastfetch_pciids.c.inc'")
 403        execute_process(COMMAND ${Python_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/scripts/gen-pciids.py" "${PROJECT_BINARY_DIR}/pci.ids"
 404                        OUTPUT_FILE "${PROJECT_BINARY_DIR}/fastfetch_pciids.c.inc"
 405                        RESULT_VARIABLE PYTHON_PCIIDS_RETCODE)
 406        if(NOT PYTHON_PCIIDS_RETCODE EQUAL 0)
 407            file(REMOVE "${PROJECT_BINARY_DIR}/fastfetch_pciids.c.inc")
 408            message(WARNING "Failed to generate 'fastfetch_pciids.c.inc'")
 409            set(ENABLE_EMBEDDED_PCIIDS OFF)
 410        endif()
 411    else()
 412        message(WARNING "Python3 is not found, 'fastfetch_pciids.c.inc' will not be generated")
 413        set(ENABLE_EMBEDDED_PCIIDS OFF)
 414    endif()
 415endif()
 416
 417if(ENABLE_EMBEDDED_AMDGPUIDS AND NOT EXISTS "${PROJECT_BINARY_DIR}/fastfetch_amdgpuids.c.inc")
 418    if(Python_FOUND)
 419        if(NOT EXISTS "${PROJECT_BINARY_DIR}/amdgpu.ids")
 420            message(STATUS "'${PROJECT_BINARY_DIR}/amdgpu.ids' is missing, downloading...")
 421            file(DOWNLOAD "https://gitlab.freedesktop.org/mesa/drm/-/raw/main/data/amdgpu.ids" "${PROJECT_BINARY_DIR}/amdgpu.ids")
 422        endif()
 423        message(STATUS "Generating 'fastfetch_amdgpuids.c.inc'")
 424        execute_process(COMMAND ${Python_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/scripts/gen-amdgpuids.py" "${PROJECT_BINARY_DIR}/amdgpu.ids"
 425                        OUTPUT_FILE "${PROJECT_BINARY_DIR}/fastfetch_amdgpuids.c.inc"
 426                        RESULT_VARIABLE PYTHON_AMDGPUIDS_RETCODE)
 427        if(NOT PYTHON_AMDGPUIDS_RETCODE EQUAL 0)
 428            file(REMOVE "${PROJECT_BINARY_DIR}/fastfetch_amdgpuids.c.inc")
 429            message(WARNING "Failed to generate 'fastfetch_amdgpuids.c.inc'")
 430            set(ENABLE_EMBEDDED_AMDGPUIDS OFF)
 431        endif()
 432    else()
 433        message(WARNING "Python3 is not found, 'fastfetch_amdgpuids.c.inc' will not be generated")
 434        set(ENABLE_EMBEDDED_AMDGPUIDS OFF)
 435    endif()
 436endif()
 437
 438if(Python_FOUND)
 439    message(STATUS "Generating 'fastfetch.1'")
 440    execute_process(COMMAND ${Python_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/scripts/gen-man.py"
 441                    OUTPUT_FILE "${PROJECT_BINARY_DIR}/fastfetch.1"
 442                    RESULT_VARIABLE PYTHON_MANPAGE_RETCODE)
 443        if(NOT PYTHON_MANPAGE_RETCODE EQUAL 0)
 444            message(FATAL_ERROR "Failed to generate 'fastfetch.1'")
 445        endif()
 446else()
 447    message(WARNING "Python3 is not found, use basic 'fastfetch.1.in' instead")
 448    string(TIMESTAMP FASTFETCH_BUILD_DATE "%d %B %Y" UTC)
 449    configure_file(doc/fastfetch.1.in fastfetch.1 @ONLY)
 450endif()
 451
 452fastfetch_encode_c_string("${DATATEXT_JSON_HELP}" DATATEXT_JSON_HELP)
 453
 454configure_file(src/fastfetch_config.h.in fastfetch_config.h @ONLY)
 455configure_file(src/fastfetch_datatext.h.in fastfetch_datatext.h @ONLY)
 456if(APPLE)
 457    # `mediaremoted` serves now-playing data only to clients whose bundle id starts
 458    # with "com.apple.": -[MRDMediaRemoteClient isAllowedAccessToDataFromPlayerPath:]
 459    # accepts the 0x200 entitlement bit either for the private
 460    # com.apple.mediaremote.now-playing-read-access entitlement or for that prefix,
 461    # and it derives the client's identity from the code signature / XPC audit token
 462    # rather than from the process's own NSBundle. Both the embedded
 463    # CFBundleIdentifier and the ad-hoc signing identifier below therefore have to
 464    # carry the prefix; keep them in sync through these variables.
 465    set(FASTFETCH_BUNDLE_ID "com.apple.fastfetch")
 466    set(FLASHFETCH_BUNDLE_ID "com.apple.flashfetch")
 467    # configure_file() inputs are not configure dependencies on their own, so
 468    # without this an edit to Info.plist.in never even regenerates Info.plist.
 469    set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/common/apple/Info.plist.in")
 470    # Each executable gets its own plist: the file is embedded with -sectcreate and read
 471    # back by the system as the bundle id, so two targets sharing one would leave one of
 472    # them advertising an identifier that its code signature does not match.
 473    set(BUNDLE_ID "${FASTFETCH_BUNDLE_ID}")
 474    configure_file(src/common/apple/Info.plist.in Info.plist @ONLY)
 475    if(BUILD_FLASHFETCH)
 476        set(BUNDLE_ID "${FLASHFETCH_BUNDLE_ID}")
 477        configure_file(src/common/apple/Info.plist.in Info.plist.flashfetch @ONLY)
 478    endif()
 479    unset(BUNDLE_ID)
 480endif()
 481
 482####################
 483# Ascii image data #
 484####################
 485
 486file(GLOB LOGO_FILES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/logo/ascii/[a-z_]/*.txt")
 487set(LOGO_BUILTIN_H "#pragma once\n#pragma GCC diagnostic ignored \"-Wtrigraphs\"\n\n")
 488foreach(file ${LOGO_FILES})
 489    fastfetch_load_text("${file}" content)
 490    get_filename_component(file "${file}" NAME_WE)
 491    string(TOUPPER "${file}" file)
 492    set(LOGO_BUILTIN_H "${LOGO_BUILTIN_H}#define FASTFETCH_DATATEXT_LOGO_${file} ${content}\n")
 493endforeach()
 494file(GENERATE OUTPUT logo_builtin.h CONTENT "${LOGO_BUILTIN_H}")
 495
 496#######################
 497# libfastfetch target #
 498#######################
 499
 500set(LIBFASTFETCH_SRC
 501    src/common/impl/commandoption.c
 502    src/common/impl/debug.c
 503    src/common/impl/duration.c
 504    src/common/impl/font.c
 505    src/common/impl/format.c
 506    src/common/impl/frequency.c
 507    src/common/impl/genconfig.c
 508    src/common/impl/init.c
 509    src/common/impl/jsonconfig.c
 510    src/common/impl/library.c
 511    src/common/impl/lua.c
 512    src/common/impl/netif.c
 513    src/common/impl/networking_common.c
 514    src/common/impl/option.c
 515    src/common/impl/parsing.c
 516    src/common/impl/percent.c
 517    src/common/impl/printing.c
 518    src/common/impl/properties.c
 519    src/common/impl/settings.c
 520    src/common/impl/size.c
 521    src/common/impl/temps.c
 522    src/common/impl/time.c
 523    src/common/impl/edidHelper.c
 524    src/common/impl/base64.c
 525    src/common/impl/FFcache.c
 526    src/common/impl/FFlist.c
 527    src/common/impl/FFstrbuf.c
 528    src/common/impl/path.c
 529    src/common/impl/FFPlatform.c
 530    src/common/impl/smbios.c
 531    src/common/impl/strutil.c
 532    src/common/impl/zlib.c
 533    src/detection/bluetoothradio/bluetoothradio.c
 534    src/detection/bootmgr/bootmgr.c
 535    src/detection/chassis/chassis.c
 536    src/detection/codec/codec.c
 537    src/detection/codec/codec_vulkan.c
 538    src/detection/cpu/cpu.c
 539    src/detection/cpu/cpu_x86.c
 540    src/detection/cpuusage/cpuusage.c
 541    src/detection/command/command.c
 542    src/detection/disk/disk.c
 543    src/detection/diskio/diskio.c
 544    src/detection/displayserver/displayserver.c
 545    src/detection/editor/editor.c
 546    src/detection/font/font.c
 547    src/detection/gpu/gpu.c
 548    src/detection/host/host_mac.c
 549    src/detection/media/media.c
 550    src/detection/netio/netio.c
 551    src/detection/opencl/opencl.c
 552    src/detection/opengl/opengl_shared.c
 553    src/detection/os/os.c
 554    src/detection/packages/packages.c
 555    src/detection/physicalmemory/physicalmemory.c
 556    src/detection/publicip/publicip.c
 557    src/detection/terminaltheme/terminaltheme.c
 558    src/detection/top/top.c
 559    src/detection/terminalfont/terminalfont.c
 560    src/detection/terminalshell/terminalshell.c
 561    src/detection/version/version.c
 562    src/detection/vulkan/vulkan.c
 563    src/detection/weather/weather.c
 564    src/detection/zpool/zpool.c
 565    src/logo/builtin.c
 566    src/logo/logo.c
 567    src/modules/modules.c
 568    src/options/display.c
 569    src/options/logo.c
 570    src/options/general.c
 571)
 572
 573if(ENABLE_IMAGE_LOGO)
 574    list(APPEND LIBFASTFETCH_SRC
 575        src/logo/image/image.c
 576        src/logo/image/im6.c
 577        src/logo/image/im7.c
 578        src/logo/image/sixel.c
 579    )
 580    if(ANDROID)
 581        list(APPEND LIBFASTFETCH_SRC
 582            src/logo/image/aid.c
 583        )
 584    endif()
 585endif()
 586
 587foreach(FF_MODULE_DIR ${FF_MODULE_DIRS})
 588    list(APPEND LIBFASTFETCH_SRC
 589        src/modules/${FF_MODULE_DIR}/${FF_MODULE_DIR}.c
 590    )
 591endforeach()
 592
 593if(LINUX)
 594    list(APPEND LIBFASTFETCH_SRC
 595        src/common/impl/dbus.c
 596        src/common/impl/io_unix.c
 597        src/common/impl/netif_linux.c
 598        src/common/impl/networking_linux.c
 599        src/common/impl/processing_linux.c
 600        src/common/impl/FFPlatform_unix.c
 601        src/common/impl/binary_linux.c
 602        src/common/impl/kmod_linux.c
 603        src/detection/battery/battery_linux.c
 604        src/detection/bios/bios_linux.c
 605        src/detection/board/board_linux.c
 606        src/detection/bootmgr/bootmgr_linux.c
 607        src/detection/brightness/brightness_linux.c
 608        src/detection/btrfs/btrfs_linux.c
 609        src/detection/chassis/chassis_linux.c
 610        src/detection/codec/codec_linux.c
 611        src/detection/cpu/cpu_linux.c
 612        src/detection/cpucache/cpucache_linux.c
 613        src/detection/cpuusage/cpuusage_linux.c
 614        src/detection/cursor/cursor_linux.c
 615        src/detection/bluetooth/bluetooth_linux.c
 616        src/detection/bluetoothradio/bluetoothradio_linux.c
 617        src/detection/disk/disk_linux.c
 618        src/detection/dns/dns_linux.c
 619        src/detection/physicaldisk/physicaldisk_linux.c
 620        src/detection/physicalmemory/physicalmemory_linux.c
 621        src/detection/diskio/diskio_linux.c
 622        src/detection/displayserver/linux/displayserver_linux.c
 623        src/detection/displayserver/linux/common.c
 624        src/detection/displayserver/linux/drm.c
 625        src/detection/displayserver/linux/wayland/wayland.c
 626        src/detection/displayserver/linux/wayland/global-output.c
 627        src/detection/displayserver/linux/wayland/wl-output-protocol.c
 628        src/detection/displayserver/linux/wayland/wp-color-management-v1-protocol.c
 629        src/detection/displayserver/linux/wayland/kde-output.c
 630        src/detection/displayserver/linux/wayland/kde-output-device-v2-protocol.c
 631        src/detection/displayserver/linux/wayland/xdg-output-unstable-v1-protocol.c
 632        src/detection/displayserver/linux/wmde.c
 633        src/detection/displayserver/linux/xcb.c
 634        src/detection/displayserver/linux/xlib.c
 635        src/detection/font/font_linux.c
 636        src/detection/gpu/gpu_linux.c
 637        src/detection/gpu/gpu_drm.c
 638        src/detection/gpu/gpu_pci.c
 639        src/detection/gpu/gpu_windows.c
 640        src/detection/gtk_qt/gtk.c
 641        src/detection/host/host_linux.c
 642        src/detection/icons/icons_linux.c
 643        src/detection/initsystem/initsystem_linux.c
 644        src/detection/keyboard/keyboard_linux.c
 645        src/detection/libc/libc_linux.c
 646        src/detection/lm/lm_linux.c
 647        src/detection/loadavg/loadavg_linux.c
 648        src/detection/locale/locale_linux.c
 649        src/detection/localip/localip_linux.c
 650        src/detection/gamepad/gamepad_linux.c
 651        src/detection/media/media_linux.c
 652        src/detection/memory/memory_linux.c
 653        src/detection/mouse/mouse_linux.c
 654        src/detection/netio/netio_linux.c
 655        src/detection/opengl/opengl_linux.c
 656        src/detection/os/os_linux.c
 657        src/detection/packages/packages_linux.c
 658        src/detection/packages/packages_nix.c
 659        src/detection/poweradapter/poweradapter_linux.c
 660        src/detection/processes/processes_linux.c
 661        src/detection/gtk_qt/qt.c
 662        src/detection/sound/sound_linux.c
 663        src/detection/swap/swap_linux.c
 664        src/detection/terminalfont/terminalfont_linux.c
 665        src/detection/terminalshell/terminalshell_linux.c
 666        src/detection/terminalsize/terminalsize_linux.c
 667        src/detection/theme/theme_linux.c
 668        src/detection/top/top_linux.c
 669        src/detection/tpm/tpm_linux.c
 670        src/detection/uptime/uptime_linux.c
 671        src/detection/users/users_linux.c
 672        src/detection/wallpaper/wallpaper_linux.c
 673        src/detection/wifi/wifi_linux.c
 674        src/detection/wm/wm_linux.c
 675        src/detection/de/de_linux.c
 676        src/detection/wmtheme/wmtheme_linux.c
 677        src/detection/camera/camera_linux.c
 678    )
 679elseif(ANDROID)
 680    list(APPEND LIBFASTFETCH_SRC
 681        src/common/android/applabel.c
 682        src/common/android/binder.c
 683        src/common/android/dex.c
 684        src/common/android/package.c
 685        src/common/android/zip.c
 686        src/common/impl/dbus.c
 687        src/common/impl/io_unix.c
 688        src/common/impl/netif_linux.c
 689        src/common/impl/networking_linux.c
 690        src/common/impl/processing_linux.c
 691        src/common/impl/FFPlatform_unix.c
 692        src/common/impl/binary_linux.c
 693        src/common/impl/kmod_linux.c
 694        src/detection/battery/battery_android.c
 695        src/detection/bios/bios_android.c
 696        src/detection/bluetooth/bluetooth_nosupport.c
 697        src/detection/bluetoothradio/bluetoothradio_nosupport.c
 698        src/detection/board/board_android.c
 699        src/detection/bootmgr/bootmgr_nosupport.c
 700        src/detection/brightness/brightness_nosupport.c
 701        src/detection/btrfs/btrfs_nosupport.c
 702        src/detection/chassis/chassis_nosupport.c
 703        src/detection/codec/codec_android.c
 704        src/detection/cpu/cpu_linux.c
 705        src/detection/cpucache/cpucache_linux.c
 706        src/detection/cursor/cursor_linux.c
 707        src/detection/cpuusage/cpuusage_linux.c
 708        src/detection/disk/disk_linux.c
 709        src/detection/dns/dns_linux.c
 710        src/detection/physicaldisk/physicaldisk_linux.c
 711        src/detection/physicalmemory/physicalmemory_nosupport.c
 712        src/detection/diskio/diskio_linux.c
 713        src/detection/displayserver/displayserver_android.c
 714        src/detection/displayserver/linux/wayland/wayland.c
 715        src/detection/displayserver/linux/wayland/global-output.c
 716        src/detection/displayserver/linux/wayland/kde-output.c
 717        src/detection/displayserver/linux/wayland/wl-output-protocol.c
 718        src/detection/displayserver/linux/wayland/wp-color-management-v1-protocol.c
 719        src/detection/displayserver/linux/wayland/kde-output-device-v2-protocol.c
 720        src/detection/displayserver/linux/wayland/xdg-output-unstable-v1-protocol.c
 721        src/detection/displayserver/linux/common.c
 722        src/detection/displayserver/linux/wmde.c
 723        src/detection/displayserver/linux/xcb.c
 724        src/detection/displayserver/linux/xlib.c
 725        src/detection/gtk_qt/gtk.c
 726        src/detection/gtk_qt/qt.c
 727        src/detection/font/font_linux.c
 728        src/detection/gpu/gpu_android.c
 729        src/detection/host/host_android.c
 730        src/detection/icons/icons_linux.c
 731        src/detection/initsystem/initsystem_linux.c
 732        src/detection/keyboard/keyboard_nosupport.c
 733        src/detection/libc/libc_android.c
 734        src/detection/lm/lm_nosupport.c
 735        src/detection/loadavg/loadavg_linux.c
 736        src/detection/locale/locale_linux.c
 737        src/detection/localip/localip_linux.c
 738        src/detection/gamepad/gamepad_nosupport.c
 739        src/detection/media/media_android.c
 740        src/detection/media/media_linux.c
 741        src/detection/memory/memory_linux.c
 742        src/detection/mouse/mouse_nosupport.c
 743        src/detection/netio/netio_linux.c
 744        src/detection/opengl/opengl_linux.c
 745        src/detection/os/os_android.c
 746        src/detection/packages/packages_linux.c
 747        src/detection/packages/packages_nix.c
 748        src/detection/poweradapter/poweradapter_nosupport.c
 749        src/detection/processes/processes_linux.c
 750        src/detection/sound/sound_android.c
 751        src/detection/sound/sound_linux.c
 752        src/detection/swap/swap_linux.c
 753        src/detection/terminalfont/terminalfont_android.c
 754        src/detection/terminalfont/terminalfont_linux.c
 755        src/detection/terminalshell/terminalshell_linux.c
 756        src/detection/terminalsize/terminalsize_linux.c
 757        src/detection/theme/theme_linux.c
 758        src/detection/top/top_linux.c
 759        src/detection/tpm/tpm_nosupport.c
 760        src/detection/uptime/uptime_linux.c
 761        src/detection/users/users_linux.c
 762        src/detection/wallpaper/wallpaper_android.c
 763        src/detection/wallpaper/wallpaper_linux.c
 764        src/detection/wifi/wifi_android.c
 765        src/detection/wm/wm_linux.c
 766        src/detection/de/de_linux.c
 767        src/detection/wmtheme/wmtheme_linux.c
 768        src/detection/camera/camera_android.c
 769    )
 770elseif(FreeBSD)
 771    list(APPEND LIBFASTFETCH_SRC
 772        src/common/impl/dbus.c
 773        src/common/impl/io_unix.c
 774        src/common/impl/netif_bsd.c
 775        src/common/impl/networking_linux.c
 776        src/common/impl/processing_linux.c
 777        src/common/impl/sysctl.c
 778        src/common/impl/FFPlatform_unix.c
 779        src/common/impl/binary_linux.c
 780        src/common/impl/kmod_bsd.c
 781        src/detection/battery/battery_bsd.c
 782        src/detection/bios/bios_bsd.c
 783        src/detection/bluetoothradio/bluetoothradio_nosupport.c
 784        src/detection/board/board_bsd.c
 785        src/detection/bootmgr/bootmgr_bsd.c
 786        src/detection/brightness/brightness_bsd.c
 787        src/detection/btrfs/btrfs_nosupport.c
 788        src/detection/chassis/chassis_bsd.c
 789        src/detection/codec/codec_linux.c
 790        src/detection/cpu/cpu_bsd.c
 791        src/detection/cpucache/cpucache_shared.c
 792        src/detection/cpuusage/cpuusage_bsd.c
 793        src/detection/cursor/cursor_linux.c
 794        src/detection/disk/disk_bsd.c
 795        src/detection/dns/dns_linux.c
 796        src/detection/physicaldisk/physicaldisk_bsd.c
 797        src/detection/physicalmemory/physicalmemory_linux.c
 798        src/detection/diskio/diskio_bsd.c
 799        src/detection/displayserver/linux/displayserver_linux.c
 800        src/detection/displayserver/linux/common.c
 801        src/detection/displayserver/linux/drm.c
 802        src/detection/displayserver/linux/wayland/wayland.c
 803        src/detection/displayserver/linux/wayland/global-output.c
 804        src/detection/displayserver/linux/wayland/kde-output.c
 805        src/detection/displayserver/linux/wayland/wl-output-protocol.c
 806        src/detection/displayserver/linux/wayland/wp-color-management-v1-protocol.c
 807        src/detection/displayserver/linux/wayland/kde-output-device-v2-protocol.c
 808        src/detection/displayserver/linux/wayland/xdg-output-unstable-v1-protocol.c
 809        src/detection/displayserver/linux/wmde.c
 810        src/detection/displayserver/linux/xcb.c
 811        src/detection/displayserver/linux/xlib.c
 812        src/detection/font/font_linux.c
 813        src/detection/gpu/gpu_bsd.c
 814        src/detection/gpu/gpu_drm.c
 815        src/detection/gpu/gpu_pci.c
 816        src/detection/gpu/gpu_bsddrm.c
 817        src/detection/gtk_qt/gtk.c
 818        src/detection/host/host_bsd.c
 819        src/detection/lm/lm_linux.c
 820        src/detection/icons/icons_linux.c
 821        src/detection/initsystem/initsystem_linux.c
 822        src/detection/keyboard/keyboard_bsd.c
 823        src/detection/libc/libc_bsd.c
 824        src/detection/loadavg/loadavg_bsd.c
 825        src/detection/locale/locale_linux.c
 826        src/detection/localip/localip_linux.c
 827        src/detection/gamepad/gamepad_bsd.c
 828        src/detection/media/media_linux.c
 829        src/detection/memory/memory_bsd.c
 830        src/detection/mouse/mouse_bsd.c
 831        src/detection/netio/netio_bsd.c
 832        src/detection/opengl/opengl_linux.c
 833        src/detection/os/os_linux.c
 834        src/detection/packages/packages_bsd.c
 835        src/detection/poweradapter/poweradapter_nosupport.c
 836        src/detection/gtk_qt/qt.c
 837        src/detection/sound/sound_bsd.c
 838        src/detection/swap/swap_bsd.c
 839        src/detection/terminalfont/terminalfont_linux.c
 840        src/detection/terminalshell/terminalshell_linux.c
 841        src/detection/terminalsize/terminalsize_linux.c
 842        src/detection/theme/theme_linux.c
 843        src/detection/tpm/tpm_bsd.c
 844        src/detection/uptime/uptime_bsd.c
 845        src/detection/users/users_linux.c
 846        src/detection/wallpaper/wallpaper_linux.c
 847        src/detection/wm/wm_linux.c
 848        src/detection/de/de_linux.c
 849        src/detection/wmtheme/wmtheme_linux.c
 850        src/detection/camera/camera_linux.c
 851    )
 852    if(DragonFly)
 853        list(APPEND LIBFASTFETCH_SRC
 854            src/detection/bluetooth/bluetooth_nosupport.c
 855            src/detection/processes/processes_dbsd.c
 856            src/detection/top/top_dbsd.c
 857            src/detection/wifi/wifi_nosupport.c
 858        )
 859    else()
 860        list(APPEND LIBFASTFETCH_SRC
 861            src/detection/bluetooth/bluetooth_bsd.c
 862            src/detection/processes/processes_bsd.c
 863            src/detection/top/top_bsd.c
 864            src/detection/wifi/wifi_bsd.c
 865        )
 866    endif()
 867elseif(NetBSD)
 868    list(APPEND LIBFASTFETCH_SRC
 869        src/common/impl/dbus.c
 870        src/common/impl/io_unix.c
 871        src/common/impl/netif_bsd.c
 872        src/common/impl/networking_linux.c
 873        src/common/impl/processing_linux.c
 874        src/common/impl/sysctl.c
 875        src/common/impl/FFPlatform_unix.c
 876        src/common/impl/binary_linux.c
 877        src/common/impl/kmod_nbsd.c
 878        src/detection/battery/battery_nbsd.c
 879        src/detection/bios/bios_nbsd.c
 880        src/detection/bluetooth/bluetooth_bsd.c
 881        src/detection/bluetoothradio/bluetoothradio_nosupport.c
 882        src/detection/board/board_nbsd.c
 883        src/detection/bootmgr/bootmgr_bsd.c
 884        src/detection/brightness/brightness_nbsd.c
 885        src/detection/btrfs/btrfs_nosupport.c
 886        src/detection/chassis/chassis_nbsd.c
 887        src/detection/codec/codec_linux.c
 888        src/detection/cpu/cpu_nbsd.c
 889        src/detection/cpucache/cpucache_shared.c
 890        src/detection/cpuusage/cpuusage_bsd.c
 891        src/detection/cursor/cursor_linux.c
 892        src/detection/disk/disk_bsd.c
 893        src/detection/dns/dns_linux.c
 894        src/detection/physicaldisk/physicaldisk_nbsd.c
 895        src/detection/physicalmemory/physicalmemory_linux.c
 896        src/detection/diskio/diskio_nbsd.c
 897        src/detection/displayserver/linux/displayserver_linux.c
 898        src/detection/displayserver/linux/common.c
 899        src/detection/displayserver/linux/drm.c
 900        src/detection/displayserver/linux/wayland/wayland.c
 901        src/detection/displayserver/linux/wayland/global-output.c
 902        src/detection/displayserver/linux/wayland/kde-output.c
 903        src/detection/displayserver/linux/wayland/wl-output-protocol.c
 904        src/detection/displayserver/linux/wayland/wp-color-management-v1-protocol.c
 905        src/detection/displayserver/linux/wayland/kde-output-device-v2-protocol.c
 906        src/detection/displayserver/linux/wayland/xdg-output-unstable-v1-protocol.c
 907        src/detection/displayserver/linux/wmde.c
 908        src/detection/displayserver/linux/xcb.c
 909        src/detection/displayserver/linux/xlib.c
 910        src/detection/font/font_linux.c
 911        src/detection/gpu/gpu_nbsd.c
 912        src/detection/gpu/gpu_pci.c
 913        src/detection/gtk_qt/gtk.c
 914        src/detection/host/host_nbsd.c
 915        src/detection/lm/lm_linux.c
 916        src/detection/icons/icons_linux.c
 917        src/detection/initsystem/initsystem_linux.c
 918        src/detection/keyboard/keyboard_nosupport.c
 919        src/detection/libc/libc_nosupport.c
 920        src/detection/loadavg/loadavg_bsd.c
 921        src/detection/locale/locale_linux.c
 922        src/detection/localip/localip_linux.c
 923        src/detection/gamepad/gamepad_nosupport.c
 924        src/detection/media/media_linux.c
 925        src/detection/memory/memory_nbsd.c
 926        src/detection/mouse/mouse_nosupport.c
 927        src/detection/netio/netio_bsd.c
 928        src/detection/opengl/opengl_linux.c
 929        src/detection/os/os_nbsd.c
 930        src/detection/packages/packages_nbsd.c
 931        src/detection/poweradapter/poweradapter_nosupport.c
 932        src/detection/processes/processes_nbsd.c
 933        src/detection/gtk_qt/qt.c
 934        src/detection/sound/sound_nbsd.c
 935        src/detection/swap/swap_obsd.c
 936        src/detection/terminalfont/terminalfont_linux.c
 937        src/detection/terminalshell/terminalshell_linux.c
 938        src/detection/terminalsize/terminalsize_linux.c
 939        src/detection/theme/theme_linux.c
 940        src/detection/tpm/tpm_nosupport.c
 941        src/detection/top/top_nbsd.c
 942        src/detection/uptime/uptime_bsd.c
 943        src/detection/users/users_linux.c
 944        src/detection/wallpaper/wallpaper_linux.c
 945        src/detection/wifi/wifi_nbsd.c
 946        src/detection/wm/wm_linux.c
 947        src/detection/de/de_linux.c
 948        src/detection/wmtheme/wmtheme_linux.c
 949        src/detection/camera/camera_linux.c
 950    )
 951elseif(OpenBSD)
 952    list(APPEND LIBFASTFETCH_SRC
 953        src/common/impl/dbus.c
 954        src/common/impl/io_unix.c
 955        src/common/impl/netif_bsd.c
 956        src/common/impl/networking_linux.c
 957        src/common/impl/processing_linux.c
 958        src/common/impl/sysctl.c
 959        src/common/impl/FFPlatform_unix.c
 960        src/common/impl/binary_linux.c
 961        src/common/impl/smbios.c
 962        src/common/impl/kmod_nosupport.c
 963        src/detection/battery/battery_obsd.c
 964        src/detection/bios/bios_windows.c
 965        src/detection/bluetooth/bluetooth_nosupport.c
 966        src/detection/bluetoothradio/bluetoothradio_nosupport.c
 967        src/detection/board/board_windows.c
 968        src/detection/bootmgr/bootmgr_bsd.c
 969        src/detection/brightness/brightness_obsd.c
 970        src/detection/btrfs/btrfs_nosupport.c
 971        src/detection/chassis/chassis_windows.c
 972        src/detection/codec/codec_linux.c
 973        src/detection/cpu/cpu_obsd.c
 974        src/detection/cpucache/cpucache_shared.c
 975        src/detection/cpuusage/cpuusage_bsd.c
 976        src/detection/cursor/cursor_linux.c
 977        src/detection/disk/disk_bsd.c
 978        src/detection/dns/dns_linux.c
 979        src/detection/physicaldisk/physicaldisk_obsd.c
 980        src/detection/physicalmemory/physicalmemory_linux.c
 981        src/detection/diskio/diskio_obsd.c
 982        src/detection/displayserver/linux/displayserver_linux.c
 983        src/detection/displayserver/linux/common.c
 984        src/detection/displayserver/linux/drm.c
 985        src/detection/displayserver/linux/wayland/wayland.c
 986        src/detection/displayserver/linux/wayland/global-output.c
 987        src/detection/displayserver/linux/wayland/kde-output.c
 988        src/detection/displayserver/linux/wayland/wl-output-protocol.c
 989        src/detection/displayserver/linux/wayland/wp-color-management-v1-protocol.c
 990        src/detection/displayserver/linux/wayland/kde-output-device-v2-protocol.c
 991        src/detection/displayserver/linux/wayland/xdg-output-unstable-v1-protocol.c
 992        src/detection/displayserver/linux/wmde.c
 993        src/detection/displayserver/linux/xcb.c
 994        src/detection/displayserver/linux/xlib.c
 995        src/detection/font/font_linux.c
 996        src/detection/gpu/gpu_pci.c
 997        src/detection/gpu/gpu_obsd.c
 998        src/detection/gpu/gpu_drm.c
 999        src/detection/gpu/gpu_bsddrm.c
1000        src/detection/gtk_qt/gtk.c
1001        src/detection/host/host_obsd.c
1002        src/detection/lm/lm_linux.c
1003        src/detection/icons/icons_linux.c
1004        src/detection/initsystem/initsystem_linux.c
1005        src/detection/keyboard/keyboard_nosupport.c
1006        src/detection/libc/libc_nosupport.c
1007        src/detection/loadavg/loadavg_bsd.c
1008        src/detection/locale/locale_linux.c
1009        src/detection/localip/localip_linux.c
1010        src/detection/gamepad/gamepad_nosupport.c
1011        src/detection/media/media_linux.c
1012        src/detection/memory/memory_obsd.c
1013        src/detection/mouse/mouse_nosupport.c
1014        src/detection/netio/netio_bsd.c
1015        src/detection/opengl/opengl_linux.c
1016        src/detection/os/os_obsd.c
1017        src/detection/packages/packages_obsd.c
1018        src/detection/poweradapter/poweradapter_nosupport.c
1019        src/detection/processes/processes_obsd.c
1020        src/detection/gtk_qt/qt.c
1021        src/detection/sound/sound_obsd.c
1022        src/detection/swap/swap_obsd.c
1023        src/detection/terminalfont/terminalfont_linux.c
1024        src/detection/terminalshell/terminalshell_linux.c
1025        src/detection/terminalsize/terminalsize_linux.c
1026        src/detection/theme/theme_linux.c
1027        src/detection/tpm/tpm_nosupport.c
1028        src/detection/top/top_obsd.c
1029        src/detection/uptime/uptime_bsd.c
1030        src/detection/users/users_obsd.c
1031        src/detection/wallpaper/wallpaper_linux.c
1032        src/detection/wifi/wifi_obsd.c
1033        src/detection/wm/wm_linux.c
1034        src/detection/de/de_linux.c
1035        src/detection/wmtheme/wmtheme_linux.c
1036        src/detection/camera/camera_linux.c
1037    )
1038elseif(APPLE)
1039    list(APPEND LIBFASTFETCH_SRC
1040        src/common/impl/io_unix.c
1041        src/common/impl/netif_apple.c
1042        src/common/impl/networking_linux.c
1043        src/common/impl/processing_linux.c
1044        src/common/impl/sysctl.c
1045        src/common/impl/FFPlatform_unix.c
1046        src/common/impl/binary_apple.c
1047        src/common/impl/kmod_apple.c
1048        src/common/apple/cf_helpers.c
1049        src/common/apple/osascript.m
1050        src/common/apple/smc_temps.c
1051        src/common/apple/version.m
1052        src/detection/battery/battery_apple.c
1053        src/detection/bluetooth/bluetooth_apple.m
1054        src/detection/bluetoothradio/bluetoothradio_apple.m
1055        src/detection/bootmgr/bootmgr_apple.c
1056        src/detection/brightness/brightness_apple.c
1057        src/detection/btrfs/btrfs_nosupport.c
1058        src/detection/codec/codec_apple.c
1059        src/detection/cpu/cpu_apple.c
1060        src/detection/cpucache/cpucache_apple.c
1061        src/detection/cpuusage/cpuusage_apple.c
1062        src/detection/cursor/cursor_apple.c
1063        src/detection/disk/disk_bsd.c
1064        src/detection/dns/dns_apple.c
1065        src/detection/physicaldisk/physicaldisk_apple.c
1066        src/detection/diskio/diskio_apple.c
1067        src/detection/displayserver/displayserver_apple.c
1068        src/detection/font/font_apple.m
1069        src/detection/gpu/gpu_apple.c
1070        src/detection/gpu/gpu_apple.m
1071        src/detection/icons/icons_nosupport.c
1072        src/detection/initsystem/initsystem_linux.c
1073        src/detection/keyboard/keyboard_apple.c
1074        src/detection/lm/lm_apple.m
1075        src/detection/loadavg/loadavg_bsd.c
1076        src/detection/libc/libc_apple.c
1077        src/detection/locale/locale_linux.c
1078        src/detection/localip/localip_linux.c
1079        src/detection/localip/localip_apple.c
1080        src/detection/gamepad/gamepad_apple.m
1081        src/detection/media/media_apple.m
1082        src/detection/memory/memory_apple.c
1083        src/detection/mouse/mouse_apple.c
1084        src/detection/netio/netio_apple.c
1085        src/detection/opengl/opengl_apple.c
1086        src/detection/os/os_apple.m
1087        src/detection/packages/packages_apple.c
1088        src/detection/packages/packages_nix.c
1089        src/detection/poweradapter/poweradapter_apple.c
1090        src/detection/processes/processes_apple.c
1091        src/detection/sound/sound_apple.c
1092        src/detection/swap/swap_apple.c
1093        src/detection/terminalfont/terminalfont_apple.m
1094        src/detection/terminalshell/terminalshell_linux.c
1095        src/detection/terminalsize/terminalsize_linux.c
1096        src/detection/theme/theme_apple.c
1097        src/detection/top/top_apple.c
1098        src/detection/tpm/tpm_apple.c
1099        src/detection/uptime/uptime_bsd.c
1100        src/detection/users/users_linux.c
1101        src/detection/wallpaper/wallpaper_apple.m
1102        src/detection/wifi/wifi_apple.m
1103        src/detection/wm/wm_apple.m
1104        src/detection/de/de_nosupport.c
1105        src/detection/wmtheme/wmtheme_apple.c
1106        src/detection/camera/camera_apple.m
1107    )
1108    if(ENABLE_IMAGE_LOGO)
1109        list(APPEND LIBFASTFETCH_SRC
1110            src/logo/image/imageio.c
1111        )
1112    endif()
1113    # CMAKE_SYSTEM_PROCESSOR has been normalized before
1114    if(CMAKE_SYSTEM_PROCESSOR STREQUAL "amd64")
1115        list(APPEND LIBFASTFETCH_SRC
1116            src/detection/bios/bios_windows.c
1117            src/detection/board/board_windows.c
1118            src/detection/chassis/chassis_windows.c
1119            src/detection/host/host_windows.c
1120            src/detection/physicalmemory/physicalmemory_linux.c
1121        )
1122    else()
1123        list(APPEND LIBFASTFETCH_SRC
1124            src/detection/bios/bios_apple.c
1125            src/detection/board/board_apple.c
1126            src/detection/chassis/chassis_apple.c
1127            src/detection/host/host_apple.c
1128            src/detection/physicalmemory/physicalmemory_apple.m
1129        )
1130    endif()
1131elseif(WIN32)
1132    list(APPEND LIBFASTFETCH_SRC
1133        src/common/impl/io_windows.c
1134        src/common/impl/netif_windows.c
1135        src/common/impl/networking_windows.c
1136        src/common/impl/processing_windows.c
1137        src/common/impl/FFPlatform_windows.c
1138        src/common/impl/binary_windows.c
1139        src/common/impl/kmod_windows.c
1140        src/common/windows/getline.c
1141        src/common/windows/com.c
1142        src/common/windows/folders.c
1143        src/common/windows/registry.c
1144        src/common/windows/unicode.c
1145        src/common/windows/variant.cpp
1146        src/common/windows/winrt.cpp
1147        src/common/windows/version.c
1148        src/detection/battery/battery_windows.c
1149        src/detection/bios/bios_windows.c
1150        src/detection/bluetooth/bluetooth_windows.c
1151        src/detection/bluetooth/bluetooth_windows.cpp
1152        src/detection/bluetoothradio/bluetoothradio_windows.c
1153        src/detection/board/board_windows.c
1154        src/detection/bootmgr/bootmgr_windows.c
1155        src/detection/brightness/brightness_windows.c
1156        src/detection/btrfs/btrfs_nosupport.c
1157        src/detection/chassis/chassis_windows.c
1158        src/detection/codec/codec_windows.cpp
1159        src/detection/cpu/cpu_windows.c
1160        src/detection/cpucache/cpucache_windows.c
1161        src/detection/cpuusage/cpuusage_windows.c
1162        src/detection/cursor/cursor_windows.c
1163        src/detection/disk/disk_windows.c
1164        src/detection/physicaldisk/physicaldisk_windows.c
1165        src/detection/diskio/diskio_windows.c
1166        src/detection/displayserver/displayserver_windows.c
1167        src/detection/dns/dns_windows.c
1168        src/detection/font/font_windows.c
1169        src/detection/gpu/gpu_windows.c
1170        src/detection/gpu/gpu_windows.cpp
1171        src/detection/host/host_windows.c
1172        src/detection/icons/icons_windows.c
1173        src/detection/initsystem/initsystem_windows.c
1174        src/detection/keyboard/keyboard_windows.c
1175        src/detection/libc/libc_windows.cpp
1176        src/detection/lm/lm_windows.c
1177        src/detection/loadavg/loadavg_nosupport.c
1178        src/detection/locale/locale_windows.c
1179        src/detection/localip/localip_windows.c
1180        src/detection/gamepad/gamepad_windows.c
1181        src/detection/media/media_windows.cpp
1182        src/detection/memory/memory_windows.c
1183        src/detection/mouse/mouse_windows.c
1184        src/detection/physicalmemory/physicalmemory_linux.c
1185        src/detection/netio/netio_windows.c
1186        src/detection/opengl/opengl_windows.c
1187        src/detection/os/os_windows.c
1188        src/detection/packages/packages_windows.c
1189        src/detection/poweradapter/poweradapter_nosupport.c
1190        src/detection/processes/processes_windows.c
1191        src/detection/sound/sound_windows.cpp
1192        src/detection/swap/swap_windows.c
1193        src/detection/terminalfont/terminalfont_windows.c
1194        src/detection/terminalshell/terminalshell_windows.c
1195        src/detection/terminalsize/terminalsize_windows.c
1196        src/detection/theme/theme_windows.c
1197        src/detection/top/top_windows.c
1198        src/detection/tpm/tpm_windows.c
1199        src/detection/uptime/uptime_windows.c
1200        src/detection/users/users_windows.c
1201        src/detection/wallpaper/wallpaper_windows.c
1202        src/detection/wifi/wifi_windows.c
1203        src/detection/wm/wm_windows.c
1204        src/detection/de/de_nosupport.c
1205        src/detection/wmtheme/wmtheme_windows.c
1206        src/detection/camera/camera_windows.cpp
1207    )
1208    if(ENABLE_IMAGE_LOGO)
1209        list(APPEND LIBFASTFETCH_SRC
1210            src/logo/image/wic.cpp
1211        )
1212    endif()
1213elseif(SunOS)
1214    list(APPEND LIBFASTFETCH_SRC
1215        src/common/impl/dbus.c
1216        src/common/impl/io_unix.c
1217        src/common/impl/netif_apple.c
1218        src/common/impl/networking_linux.c
1219        src/common/impl/processing_linux.c
1220        src/common/impl/FFPlatform_unix.c
1221        src/common/impl/binary_linux.c
1222        src/common/impl/kmod_sunos.c
1223        src/detection/battery/battery_sunos.c
1224        src/detection/bios/bios_windows.c
1225        src/detection/board/board_windows.c
1226        src/detection/bootmgr/bootmgr_nosupport.c
1227        src/detection/brightness/brightness_nosupport.c
1228        src/detection/btrfs/btrfs_nosupport.c
1229        src/detection/chassis/chassis_windows.c
1230        src/detection/cpu/cpu_sunos.c
1231        src/detection/cpucache/cpucache_shared.c
1232        src/detection/cpuusage/cpuusage_sunos.c
1233        src/detection/cursor/cursor_linux.c
1234        src/detection/bluetooth/bluetooth_nosupport.c
1235        src/detection/bluetoothradio/bluetoothradio_nosupport.c
1236        src/detection/codec/codec_linux.c
1237        src/detection/disk/disk_sunos.c
1238        src/detection/dns/dns_linux.c
1239        src/detection/physicaldisk/physicaldisk_sunos.c
1240        src/detection/physicalmemory/physicalmemory_linux.c
1241        src/detection/diskio/diskio_sunos.c
1242        src/detection/displayserver/linux/displayserver_linux.c
1243        src/detection/displayserver/linux/common.c
1244        src/detection/displayserver/linux/drm.c
1245        src/detection/displayserver/linux/wayland/wayland.c
1246        src/detection/displayserver/linux/wayland/global-output.c
1247        src/detection/displayserver/linux/wayland/kde-output.c
1248        src/detection/displayserver/linux/wayland/wl-output-protocol.c
1249        src/detection/displayserver/linux/wayland/wp-color-management-v1-protocol.c
1250        src/detection/displayserver/linux/wayland/kde-output-device-v2-protocol.c
1251        src/detection/displayserver/linux/wayland/xdg-output-unstable-v1-protocol.c
1252        src/detection/displayserver/linux/wmde.c
1253        src/detection/displayserver/linux/xcb.c
1254        src/detection/displayserver/linux/xlib.c
1255        src/detection/font/font_linux.c
1256        src/detection/gpu/gpu_sunos.c
1257        src/detection/gpu/gpu_pci.c
1258        src/detection/gtk_qt/gtk.c
1259        src/detection/host/host_windows.c
1260        src/detection/icons/icons_linux.c
1261        src/detection/initsystem/initsystem_linux.c
1262        src/detection/keyboard/keyboard_nosupport.c
1263        src/detection/libc/libc_nosupport.c
1264        src/detection/lm/lm_linux.c
1265        src/detection/loadavg/loadavg_sunos.c
1266        src/detection/locale/locale_linux.c
1267        src/detection/localip/localip_linux.c
1268        src/detection/gamepad/gamepad_nosupport.c
1269        src/detection/media/media_linux.c
1270        src/detection/memory/memory_sunos.c
1271        src/detection/mouse/mouse_nosupport.c
1272        src/detection/netio/netio_sunos.c
1273        src/detection/opengl/opengl_linux.c
1274        src/detection/os/os_sunos.c
1275        src/detection/packages/packages_sunos.c
1276        src/detection/poweradapter/poweradapter_nosupport.c
1277        src/detection/processes/processes_sunos.c
1278        src/detection/gtk_qt/qt.c
1279        src/detection/sound/sound_sunos.c
1280        src/detection/swap/swap_sunos.c
1281        src/detection/terminalfont/terminalfont_linux.c
1282        src/detection/terminalshell/terminalshell_linux.c
1283        src/detection/terminalsize/terminalsize_linux.c
1284        src/detection/theme/theme_linux.c
1285        src/detection/top/top_sunos.c
1286        src/detection/tpm/tpm_nosupport.c
1287        src/detection/uptime/uptime_sunos.c
1288        src/detection/users/users_linux.c
1289        src/detection/wallpaper/wallpaper_linux.c
1290        src/detection/wifi/wifi_sunos.c
1291        src/detection/wm/wm_nosupport.c
1292        src/detection/de/de_linux.c
1293        src/detection/wmtheme/wmtheme_linux.c
1294        src/detection/camera/camera_nosupport.c
1295    )
1296elseif(Haiku)
1297    list(APPEND LIBFASTFETCH_SRC
1298        src/common/impl/dbus.c
1299        src/common/impl/io_unix.c
1300        src/common/impl/netif_haiku.c
1301        src/common/impl/networking_linux.c
1302        src/common/impl/processing_linux.c
1303        src/common/impl/FFPlatform_unix.c
1304        src/common/impl/binary_linux.c
1305        src/common/impl/kmod_nosupport.c
1306        src/common/haiku/version.cpp
1307        src/detection/battery/battery_haiku.c
1308        src/detection/bios/bios_windows.c
1309        src/detection/board/board_windows.c
1310        src/detection/bootmgr/bootmgr_haiku.cpp
1311        src/detection/brightness/brightness_haiku.cpp
1312        src/detection/btrfs/btrfs_nosupport.c
1313        src/detection/chassis/chassis_windows.c
1314        src/detection/cpu/cpu_haiku.c
1315        src/detection/cpucache/cpucache_shared.c
1316        src/detection/cpuusage/cpuusage_haiku.c
1317        src/detection/cursor/cursor_nosupport.c
1318        src/detection/bluetooth/bluetooth_haiku.cpp
1319        src/detection/bluetoothradio/bluetoothradio_nosupport.c
1320        src/detection/codec/codec_linux.c
1321        src/detection/disk/disk_haiku.cpp
1322        src/detection/dns/dns_linux.c
1323        src/detection/physicaldisk/physicaldisk_haiku.c
1324        src/detection/physicalmemory/physicalmemory_linux.c
1325        src/detection/diskio/diskio_nosupport.c
1326        src/detection/displayserver/displayserver_haiku.cpp
1327        src/detection/font/font_haiku.cpp
1328        src/detection/gpu/gpu_haiku.c
1329        src/detection/gpu/gpu_pci.c
1330        src/detection/gtk_qt/gtk.c
1331        src/detection/host/host_windows.c
1332        src/detection/icons/icons_nosupport.c
1333        src/detection/initsystem/initsystem_haiku.c
1334        src/detection/keyboard/keyboard_haiku.cpp
1335        src/detection/libc/libc_nosupport.c
1336        src/detection/lm/lm_nosupport.c
1337        src/detection/locale/locale_linux.c
1338        src/detection/localip/localip_linux.c
1339        src/detection/gamepad/gamepad_haiku.cpp
1340        src/detection/media/media_linux.c
1341        src/detection/memory/memory_haiku.c
1342        src/detection/mouse/mouse_haiku.cpp
1343        src/detection/netio/netio_haiku.cpp
1344        src/detection/opengl/opengl_haiku.cpp
1345        src/detection/os/os_haiku.c
1346        src/detection/packages/packages_haiku.c
1347        src/detection/poweradapter/poweradapter_nosupport.c
1348        src/detection/processes/processes_haiku.c
1349        src/detection/gtk_qt/qt.c
1350        src/detection/sound/sound_haiku.cpp
1351        src/detection/swap/swap_haiku.c
1352        src/detection/terminalfont/terminalfont_linux.c
1353        src/detection/terminalshell/terminalshell_linux.c
1354        src/detection/terminalsize/terminalsize_linux.c
1355        src/detection/theme/theme_nosupport.c
1356        src/detection/top/top_haiku.c
1357        src/detection/tpm/tpm_nosupport.c
1358        src/detection/uptime/uptime_haiku.c
1359        src/detection/users/users_linux.c
1360        src/detection/wallpaper/wallpaper_haiku.cpp
1361        src/detection/wifi/wifi_haiku.cpp
1362        src/detection/wm/wm_nosupport.c
1363        src/detection/de/de_nosupport.c
1364        src/detection/wmtheme/wmtheme_haiku.cpp
1365        src/detection/camera/camera_nosupport.c
1366    )
1367    set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} bsd)
1368    check_function_exists(getloadavg HAVE_GETLOADAVG)
1369    if(HAVE_GETLOADAVG)
1370        list(APPEND LIBFASTFETCH_SRC src/detection/loadavg/loadavg_sunos.c)
1371    else()
1372        list(APPEND LIBFASTFETCH_SRC src/detection/loadavg/loadavg_nosupport.c)
1373    endif()
1374elseif(GNU)
1375    list(APPEND LIBFASTFETCH_SRC
1376        src/common/impl/dbus.c
1377        src/common/impl/io_unix.c
1378        src/common/impl/netif_gnu.c
1379        src/common/impl/networking_linux.c
1380        src/common/impl/processing_linux.c
1381        src/common/impl/FFPlatform_unix.c
1382        src/common/impl/binary_linux.c
1383        src/common/impl/kmod_nosupport.c
1384        src/detection/battery/battery_nosupport.c
1385        src/detection/bios/bios_nosupport.c
1386        src/detection/board/board_nosupport.c
1387        src/detection/bootmgr/bootmgr_nosupport.c
1388        src/detection/brightness/brightness_nosupport.c
1389        src/detection/btrfs/btrfs_nosupport.c
1390        src/detection/chassis/chassis_nosupport.c
1391        src/detection/cpu/cpu_linux.c
1392        src/detection/cpucache/cpucache_nosupport.c
1393        src/detection/cpuusage/cpuusage_linux.c
1394        src/detection/cursor/cursor_linux.c
1395        src/detection/bluetooth/bluetooth_linux.c
1396        src/detection/bluetoothradio/bluetoothradio_linux.c
1397        src/detection/codec/codec_linux.c
1398        src/detection/disk/disk_linux.c
1399        src/detection/dns/dns_linux.c
1400        src/detection/physicaldisk/physicaldisk_nosupport.c
1401        src/detection/physicalmemory/physicalmemory_nosupport.c
1402        src/detection/diskio/diskio_nosupport.c
1403        src/detection/displayserver/linux/displayserver_linux.c
1404        src/detection/displayserver/linux/wayland/wayland.c
1405        src/detection/displayserver/linux/common.c
1406        src/detection/displayserver/linux/drm.c
1407        src/detection/displayserver/linux/wmde.c
1408        src/detection/displayserver/linux/xcb.c
1409        src/detection/displayserver/linux/xlib.c
1410        src/detection/font/font_linux.c
1411        src/detection/gpu/gpu_gnu.c
1412        src/detection/gpu/gpu_pci.c
1413        src/detection/gtk_qt/gtk.c
1414        src/detection/host/host_nosupport.c
1415        src/detection/icons/icons_linux.c
1416        src/detection/initsystem/initsystem_linux.c
1417        src/detection/keyboard/keyboard_nosupport.c
1418        src/detection/libc/libc_linux.c
1419        src/detection/lm/lm_linux.c
1420        src/detection/loadavg/loadavg_sunos.c
1421        src/detection/locale/locale_linux.c
1422        src/detection/localip/localip_linux.c
1423        src/detection/gamepad/gamepad_nosupport.c
1424        src/detection/media/media_linux.c
1425        src/detection/memory/memory_linux.c
1426        src/detection/mouse/mouse_nosupport.c
1427        src/detection/netio/netio_nosupport.c
1428        src/detection/opengl/opengl_linux.c
1429        src/detection/os/os_linux.c
1430        src/detection/packages/packages_linux.c
1431        src/detection/packages/packages_nix.c
1432        src/detection/poweradapter/poweradapter_nosupport.c
1433        src/detection/processes/processes_gnu.c
1434        src/detection/gtk_qt/qt.c
1435        src/detection/sound/sound_linux.c
1436        src/detection/swap/swap_linux.c
1437        src/detection/terminalfont/terminalfont_linux.c
1438        src/detection/terminalshell/terminalshell_linux.c
1439        src/detection/terminalsize/terminalsize_linux.c
1440        src/detection/theme/theme_linux.c
1441        src/detection/top/top_gnu.c
1442        src/detection/tpm/tpm_nosupport.c
1443        src/detection/uptime/uptime_linux.c
1444        src/detection/users/users_linux.c
1445        src/detection/wallpaper/wallpaper_linux.c
1446        src/detection/wifi/wifi_nosupport.c
1447        src/detection/wm/wm_linux.c
1448        src/detection/de/de_linux.c
1449        src/detection/wmtheme/wmtheme_linux.c
1450        src/detection/camera/camera_nosupport.c
1451   )
1452endif()
1453
1454if(ENABLE_TRACER)
1455    message(STATUS "Tracer is enabled")
1456    list(APPEND LIBFASTFETCH_SRC src/common/impl/tracer.c)
1457    if(CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT CMAKE_BUILD_TYPE STREQUAL "Debug")
1458        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -finstrument-functions-after-inlining")
1459    else()
1460        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -finstrument-functions -Dinline=\"__attribute__((no_instrument_function)) inline\"")
1461    endif()
1462    if(NOT WIN32)
1463        set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -rdynamic")
1464    elseif(CMAKE_C_COMPILER_ID MATCHES "Clang")
1465        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -gcodeview -fuse-ld=lld")
1466        set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--pdb=${CMAKE_BINARY_DIR}/fastfetch.pdb")
1467    endif()
1468endif()
1469
1470# Proprietary GPU driver APIs
1471if(LINUX OR FreeBSD OR WIN32)
1472    list(APPEND LIBFASTFETCH_SRC src/detection/gpu/gpu_nvidia.c)
1473    list(APPEND LIBFASTFETCH_SRC src/detection/gpu/gpu_mthreads.c)
1474endif()
1475if(WIN32)
1476    list(APPEND LIBFASTFETCH_SRC src/detection/gpu/gpu_intel.c)
1477    list(APPEND LIBFASTFETCH_SRC src/detection/gpu/gpu_amd.c)
1478
1479    if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
1480        message(STATUS "WinRT support is disabled due to known issues with g++")
1481        set(HAVE_WINRT FALSE)
1482    else()
1483        include(CheckIncludeFileCXX)
1484        CHECK_INCLUDE_FILE_CXX("winrt/Windows.Foundation.h" HAVE_WINRT)
1485        if(HAVE_WINRT)
1486            message(STATUS "WinRT headers are available, media detection will be enabled")
1487        else()
1488            message(WARNING "WinRT headers are NOT available, media detection will be disabled")
1489        endif()
1490    endif()
1491endif()
1492if(NOT WIN32)
1493    check_function_exists(pipe2 HAVE_PIPE2)
1494endif()
1495check_function_exists(memrchr HAVE_MEMRCHR)
1496if(NOT HAVE_MEMRCHR)
1497    list(APPEND LIBFASTFETCH_SRC src/common/impl/memrchr.c)
1498endif()
1499if(ENABLE_WCWIDTH)
1500    list(APPEND LIBFASTFETCH_SRC src/common/impl/wcwidth.c)
1501endif()
1502
1503if(ENABLE_SYSTEM_YYJSON)
1504    find_package(yyjson)
1505    if(yyjson_FOUND)
1506        message(STATUS "System provided yyjson is used")
1507    else()
1508        message(FATAL_ERROR "ENABLE_SYSTEM_YYJSON is set but system provided yyjson is not found")
1509    endif()
1510else()
1511    list(APPEND LIBFASTFETCH_SRC
1512        src/3rdparty/yyjson/yyjson.c
1513    )
1514endif()
1515
1516if(ENABLE_SIXEL)
1517    set(FF_SIXEL_SRC
1518        src/3rdparty/sixel/allocator.c
1519        src/3rdparty/sixel/dither.c
1520        src/3rdparty/sixel/output.c
1521        src/3rdparty/sixel/pixelformat.c
1522        src/3rdparty/sixel/quant.c
1523        src/3rdparty/sixel/status.c
1524        src/3rdparty/sixel/tosixel.c
1525    )
1526    list(APPEND LIBFASTFETCH_SRC ${FF_SIXEL_SRC})
1527
1528    set_source_files_properties(${FF_SIXEL_SRC} PROPERTIES COMPILE_OPTIONS "-Wno-conversion")
1529endif()
1530
1531add_library(libfastfetch OBJECT
1532    ${LIBFASTFETCH_SRC}
1533)
1534
1535foreach(FF_MODULE_DIR ${FF_MODULE_DIRS})
1536    string(TOUPPER "${FF_MODULE_DIR}" FF_MODULE_UPPER)
1537    if(MODULE_DISABLE_${FF_MODULE_UPPER})
1538        target_compile_definitions(libfastfetch PUBLIC FF_MODULE_DISABLE_${FF_MODULE_UPPER}=1)
1539    endif()
1540endforeach()
1541
1542include(CheckCSourceCompiles)
1543check_c_source_compiles("int main(void){int arr[1];return _Countof(arr);}" COMPILER_SUPPORTS_COUNT_OF)
1544if(COMPILER_SUPPORTS_COUNT_OF)
1545    message(STATUS "C2Y _Countof is supported by the compiler")
1546    target_compile_definitions(libfastfetch PUBLIC FF_SUPPORTS_COUNT_OF=1)
1547else()
1548    message(STATUS "C2Y _Countof is NOT supported by the compiler")
1549endif()
1550
1551# Test C23 compiler support
1552check_c_source_compiles("enum my_enum: long{MY_ENUM_ZERO}; void test(void*p){} int main(int,const char**){[[gnu::cleanup(test)]] void* x=nullptr; return (int)MY_ENUM_ZERO;}" COMPILER_SUPPORTS_C23)
1553if(NOT COMPILER_SUPPORTS_C23)
1554    message(FATAL_ERROR "Compiler does not support C23. Please use a newer compiler.")
1555endif()
1556
1557# A hack for AppleClang 17, which supports most C23 features we use except for the `auto` keyword.
1558# See https://github.com/Homebrew/homebrew-core/pull/297403
1559check_c_source_compiles("int main(void){auto v = 12.34; return (int)v;}" COMPILER_SUPPORTS_AUTO)
1560if(NOT COMPILER_SUPPORTS_AUTO)
1561    message(WARNING "Compiler does not support C23 'auto' keyword. A workaround will be applied.")
1562    target_compile_definitions(libfastfetch PUBLIC $<$<COMPILE_LANGUAGE:C>:auto=__auto_type>)
1563endif()
1564
1565if(yyjson_FOUND)
1566    target_compile_definitions(libfastfetch PUBLIC FF_USE_SYSTEM_YYJSON=1)
1567    target_link_libraries(libfastfetch PUBLIC yyjson::yyjson)
1568    # `target_link_libraries(yyjson::yyjson)` sets rpath implicitly
1569endif()
1570
1571# Used for dlopen finding dylibs installed by package managers
1572# `/opt/homebrew/lib`, `/usr/local/lib` and `/opt/local/lib` are not on the
1573# dlopen search path by default
1574if(APPLE AND BINARY_LINK_TYPE STREQUAL "dlopen")
1575    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,/opt/homebrew/lib -Wl,-rpath,/usr/local/lib -Wl,-rpath,/opt/local/lib")
1576endif()
1577
1578# Termux installs the libraries fastfetch dlopens -- freetype among them -- under TARGET_DIR_ROOT, which
1579# is not on the Android linker's default search path (DT_RUNPATH, LD_LIBRARY_PATH and the default
1580# namespace). Termux's own clang injects -rpath=$PREFIX/lib into every binary it links, so a build made
1581# inside Termux finds them; a plain NDK build, which is what the CI does, does not.
1582if(ANDROID)
1583    if(CMAKE_SIZEOF_VOID_P EQUAL 8)
1584        set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,${TARGET_DIR_ROOT}/lib -Wl,-rpath,/vendor/lib64 -Wl,-rpath,/system/lib64")
1585    else()
1586        set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,${TARGET_DIR_ROOT}/lib -Wl,-rpath,/vendor/lib -Wl,-rpath,/system/lib")
1587    endif()
1588endif()
1589
1590if(LINUX AND EXISTS "/lib/ld-musl-${CMAKE_HOST_SYSTEM_PROCESSOR}.so.1")
1591    execute_process(COMMAND "/lib/ld-musl-${CMAKE_HOST_SYSTEM_PROCESSOR}.so.1"
1592                    ERROR_VARIABLE LD_MUSL_RESULT)
1593    if("${LD_MUSL_RESULT}" MATCHES "Version ([0-9]+\\.[0-9]+\\.[0-9]+)")
1594        target_compile_definitions(libfastfetch PUBLIC FF_MUSL_VERSION="${CMAKE_MATCH_1}")
1595    endif()
1596endif()
1597if(APPLE AND EXISTS "/usr/bin/otool")
1598    execute_process(COMMAND /usr/bin/otool -L /usr/bin/otool
1599                    OUTPUT_VARIABLE OTOOL_OTOOL_RESULT)
1600    if("${OTOOL_OTOOL_RESULT}" MATCHES "libSystem\\.B\\.dylib \\(.*current version ([0-9]+\\.[0-9]+\\.[0-9]+)\\)")
1601        target_compile_definitions(libfastfetch PUBLIC FF_LIBSYSTEM_VERSION="${CMAKE_MATCH_1}")
1602    endif()
1603endif()
1604if(MidnightBSD AND EXISTS "/usr/bin/objdump")
1605    execute_process(COMMAND /bin/sh -c "/usr/bin/objdump -T /lib/libc.so.* | grep 'FBSD_[0-9][0-9]*\\.[0-9][0-9]*' -o | sort -Vru | head -1"
1606                    OUTPUT_VARIABLE OBJDUMP_T_RESULT)
1607    if("${OBJDUMP_T_RESULT}" MATCHES "FBSD_([0-9]+\\.[0-9]+)")
1608        message(STATUS "Found FBSD ${CMAKE_MATCH_1}")
1609        target_compile_definitions(libfastfetch PUBLIC FF_FBSD_VERSION="${CMAKE_MATCH_1}")
1610    endif()
1611elseif(FreeBSD AND EXISTS "/usr/local/bin/objdump")
1612    execute_process(COMMAND /bin/sh -c "/usr/local/bin/objdump -T /lib/libc.so.* | grep 'FBSD_[0-9][0-9]*\\.[0-9][0-9]*' -o | sort -Vru | head -1"
1613                    OUTPUT_VARIABLE OBJDUMP_T_RESULT)
1614    if("${OBJDUMP_T_RESULT}" MATCHES "FBSD_([0-9]+\\.[0-9]+)")
1615        message(STATUS "Found FBSD ${CMAKE_MATCH_1}")
1616        target_compile_definitions(libfastfetch PUBLIC FF_FBSD_VERSION="${CMAKE_MATCH_1}")
1617    endif()
1618elseif(DragonFly AND EXISTS "/usr/local/bin/objdump")
1619    execute_process(COMMAND /bin/sh -c "/usr/local/bin/objdump -T /lib/libc.so.* | grep 'DF[0-9][0-9]*\\.[0-9][0-9]*' -o | sort -Vru | head -1"
1620                    OUTPUT_VARIABLE OBJDUMP_T_RESULT)
1621    if("${OBJDUMP_T_RESULT}" MATCHES "DF([0-9]+\\.[0-9]+)")
1622        message(STATUS "Found DF ${CMAKE_MATCH_1}")
1623        target_compile_definitions(libfastfetch PUBLIC FF_DF_VERSION="${CMAKE_MATCH_1}")
1624    endif()
1625endif()
1626
1627if(LINUX)
1628    target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE _ATFILE_SOURCE __STDC_WANT_LIB_EXT1__ _FILE_OFFSET_BITS=64 _TIME_BITS=64) # "$<$<CONFIG:Release>:_FORTIFY_SOURCE=3>"
1629elseif(ANDROID)
1630    target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE _FILE_OFFSET_BITS=64 "$<$<CONFIG:DEBUG>:__BIONIC_FORTIFY>" "$<$<CONFIG:DEBUG>:__BIONIC_FORTIFY_RUNTIME_CHECKS_ENABLED>")
1631elseif(WIN32)
1632    target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE WIN32_LEAN_AND_MEAN WINRT_LEAN_AND_MEAN _WIN32_WINNT=0x0A00 NOMINMAX UNICODE) # "$<$<CONFIG:Release>:_FORTIFY_SOURCE=3>"
1633elseif(APPLE)
1634    target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE _XOPEN_SOURCE __STDC_WANT_LIB_EXT1__ _FILE_OFFSET_BITS=64 _DARWIN_C_SOURCE)
1635elseif(OpenBSD)
1636    target_compile_definitions(libfastfetch PUBLIC _XOPEN_SOURCE=700 _FILE_OFFSET_BITS=64 _BSD_SOURCE)
1637    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,/usr/X11R6/lib") # detect x11 lib path automatically
1638elseif(DragonFly)
1639    target_compile_definitions(libfastfetch PUBLIC __FreeBSD__)
1640elseif(SunOS)
1641    target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE __STDC_WANT_LIB_EXT1__ _FILE_OFFSET_BITS=64 __EXTENSIONS__ _POSIX_C_SOURCE)
1642elseif(NetBSD)
1643    target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE)
1644    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-char-subscripts")
1645    set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath,/usr/X11R7/lib -Wl,-rpath,/usr/pkg/lib") # ditto
1646elseif(Haiku)
1647    target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE)
1648elseif(GNU)
1649    # On Hurd PATH_MAX is not defined. Set an arbitrary limit as workaround.
1650    target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE PATH_MAX=4096 O_PATH=O_NORW)
1651endif()
1652
1653if(APPLE)
1654    if(ENABLE_APPLE_MEMSIZE_USABLE)
1655        target_compile_definitions(libfastfetch PUBLIC FF_APPLE_MEMSIZE_USABLE=1)
1656    else()
1657        target_compile_definitions(libfastfetch PUBLIC FF_APPLE_MEMSIZE_USABLE=0)
1658    endif()
1659endif()
1660
1661if(WIN32)
1662    check_function_exists(_msize HAVE_MSVC_MSIZE)
1663    if(HAVE_MSVC_MSIZE)
1664        target_compile_definitions(libfastfetch PUBLIC FF_HAVE_MSVC_MSIZE=1)
1665    endif()
1666
1667    if(ENABLE_WIN81_COMPAT)
1668        target_compile_definitions(libfastfetch PUBLIC FF_WIN81_COMPAT=1)
1669    else()
1670        target_compile_definitions(libfastfetch PUBLIC FF_WIN81_COMPAT=0)
1671    endif()
1672else()
1673    check_function_exists(malloc_usable_size HAVE_MALLOC_USABLE_SIZE)
1674    if(HAVE_MALLOC_USABLE_SIZE)
1675        target_compile_definitions(libfastfetch PUBLIC FF_HAVE_MALLOC_USABLE_SIZE=1)
1676    else()
1677        check_function_exists(malloc_size HAVE_MALLOC_SIZE)
1678        if(HAVE_MALLOC_SIZE)
1679            target_compile_definitions(libfastfetch PUBLIC FF_HAVE_MALLOC_SIZE=1)
1680        endif()
1681    endif()
1682endif()
1683
1684if(FreeBSD OR OpenBSD OR NetBSD)
1685    include(CheckStructHasMember)
1686    set(CMAKE_REQUIRED_DEFINITIONS "-D_IFI_OQDROPS=1")
1687    CHECK_STRUCT_HAS_MEMBER("struct if_data" ifi_oqdrops net/if.h HAVE_IFI_OQDROPS LANGUAGE C)
1688    if(HAVE_IFI_OQDROPS)
1689    target_compile_definitions(libfastfetch PUBLIC _IFI_OQDROPS FF_HAVE_IFI_OQDROPS)
1690    endif()
1691    unset(CMAKE_REQUIRED_DEFINITIONS)
1692endif()
1693
1694if(OpenBSD)
1695    check_symbol_exists("getexecpath" "unistd.h" HAVE_GETEXECPATH)
1696    if(HAVE_GETEXECPATH)
1697        target_compile_definitions(libfastfetch PUBLIC FF_HAVE_GETEXECPATH=1)
1698    endif()
1699endif()
1700
1701if(HAVE_PIPE2)
1702    target_compile_definitions(libfastfetch PUBLIC FF_HAVE_PIPE2)
1703endif()
1704
1705if(NOT "${CUSTOM_PCI_IDS_PATH}" STREQUAL "")
1706    message(STATUS "Custom file path of pci.ids: ${CUSTOM_PCI_IDS_PATH}")
1707    target_compile_definitions(libfastfetch PUBLIC FF_CUSTOM_PCI_IDS_PATH=${CUSTOM_PCI_IDS_PATH})
1708endif()
1709if(NOT "${CUSTOM_AMDGPU_IDS_PATH}" STREQUAL "")
1710    message(STATUS "Custom file path of amdgpu.ids: ${CUSTOM_AMDGPU_IDS_PATH}")
1711    target_compile_definitions(libfastfetch PUBLIC FF_CUSTOM_AMDGPU_IDS_PATH=${CUSTOM_AMDGPU_IDS_PATH})
1712endif()
1713if(NOT "${CUSTOM_OS_RELEASE_PATH}" STREQUAL "")
1714    message(STATUS "Custom file path of os_release: ${CUSTOM_OS_RELEASE_PATH}")
1715    target_compile_definitions(libfastfetch PUBLIC FF_CUSTOM_OS_RELEASE_PATH=${CUSTOM_OS_RELEASE_PATH})
1716endif()
1717if(NOT "${CUSTOM_LSB_RELEASE_PATH}" STREQUAL "")
1718    message(STATUS "Custom file path of lsb_release: ${CUSTOM_LSB_RELEASE_PATH}")
1719    target_compile_definitions(libfastfetch PUBLIC FF_CUSTOM_LSB_RELEASE_PATH=${CUSTOM_LSB_RELEASE_PATH})
1720endif()
1721
1722if(NOT BINARY_LINK_TYPE STREQUAL "dlopen")
1723    message(STATUS "Enabling custom link type: ${BINARY_LINK_TYPE}")
1724    target_compile_definitions(libfastfetch PUBLIC FF_DISABLE_DLOPEN=1)
1725    if(NOT WIN32)
1726        set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,--copy-dt-needed-entries")
1727    endif()
1728endif()
1729
1730function(ff_lib_enable VARNAME PKGCONFIG_NAMES CMAKE_NAME) # [CMAKE_TARGET_NAME]
1731    if(NOT ENABLE_${VARNAME})
1732        return()
1733    endif()
1734
1735    if(PKG_CONFIG_FOUND)
1736        pkg_search_module(${VARNAME} QUIET ${PKGCONFIG_NAMES})
1737        if(${VARNAME}_FOUND)
1738            set(${VARNAME}_FOUND "pkg-config")
1739        endif()
1740    endif()
1741
1742    if(NOT ${VARNAME}_FOUND)
1743        find_package(${CMAKE_NAME} QUIET)
1744
1745        set(${VARNAME}_FOUND ${${CMAKE_NAME}_FOUND})
1746        if(${VARNAME}_FOUND)
1747            set(${VARNAME}_FOUND "CMake")
1748
1749            # Some CMake packages (e.g. quickjs) are target-based only and
1750            # don't expose *_INCLUDE_DIRS/*_LIBRARIES variables.
1751            if(ARGC GREATER 3)
1752                set(_FF_CMAKE_TARGET ${ARGV3})
1753                if(NOT _FF_CMAKE_TARGET STREQUAL "")
1754                    if(NOT DEFINED ${VARNAME}_INCLUDE_DIRS OR "${${VARNAME}_INCLUDE_DIRS}" STREQUAL "")
1755                        get_target_property(_FF_CMAKE_TARGET_INCLUDES ${_FF_CMAKE_TARGET} INTERFACE_INCLUDE_DIRECTORIES)
1756                        if(_FF_CMAKE_TARGET_INCLUDES)
1757                            set(${VARNAME}_INCLUDE_DIRS ${_FF_CMAKE_TARGET_INCLUDES})
1758                        endif()
1759                    endif()
1760
1761                    if(NOT DEFINED ${VARNAME}_LIBRARIES OR "${${VARNAME}_LIBRARIES}" STREQUAL "")
1762                        get_target_property(_FF_CMAKE_TARGET_LIBRARIES ${_FF_CMAKE_TARGET} INTERFACE_LINK_LIBRARIES)
1763                        if(_FF_CMAKE_TARGET_LIBRARIES)
1764                            set(${VARNAME}_LIBRARIES ${_FF_CMAKE_TARGET_LIBRARIES})
1765                        else()
1766                            set(${VARNAME}_LIBRARIES ${_FF_CMAKE_TARGET})
1767                        endif()
1768                    endif()
1769
1770                    if(NOT BINARY_LINK_TYPE STREQUAL "dlopen")
1771                        # INTERFACE_LINK_LIBRARIES doesn't expose libvarname.a
1772                        target_link_libraries(libfastfetch PRIVATE ${_FF_CMAKE_TARGET})
1773                    endif()
1774                endif()
1775            else()
1776                # find_package modules disagree on how they name their result variables. Newer ones
1777                # export <PackageName>_* (FindVulkan sets Vulkan_INCLUDE_DIRS), but older ones only
1778                # set the upper-case form: FindFreetype sets FREETYPE_INCLUDE_DIRS and
1779                # FREETYPE_LIBRARIES and has no Freetype_INCLUDE_DIRS at all. Assigning
1780                # unconditionally would therefore wipe the include path the module had just
1781                # provided, and the package would be "found" with nothing to compile against.
1782                # Fill in only the gaps.
1783                foreach(_FF_SUFFIX INCLUDE_DIRS LIBRARIES CFLAGS_OTHER)
1784                    if(NOT DEFINED ${VARNAME}_${_FF_SUFFIX} OR "${${VARNAME}_${_FF_SUFFIX}}" STREQUAL "")
1785                        set(${VARNAME}_${_FF_SUFFIX} ${${CMAKE_NAME}_${_FF_SUFFIX}})
1786                    endif()
1787                endforeach()
1788            endif()
1789        endif()
1790    endif()
1791
1792    if(NOT ${VARNAME}_FOUND)
1793        message(STATUS "Library: missing: ${VARNAME}")
1794        return()
1795    endif()
1796
1797    message(STATUS "Library: found ${VARNAME} by ${${VARNAME}_FOUND}")
1798
1799    target_compile_definitions(libfastfetch PUBLIC FF_HAVE_${VARNAME}=1)
1800    target_include_directories(libfastfetch PRIVATE ${${VARNAME}_INCLUDE_DIRS})
1801
1802    if(NOT BINARY_LINK_TYPE STREQUAL "dlopen")
1803        target_link_directories(libfastfetch PRIVATE ${${VARNAME}_LIBRARY_DIRS})
1804        target_link_libraries(libfastfetch PRIVATE ${${VARNAME}_LIBRARIES})
1805    endif()
1806
1807    foreach(FLAG ${${VARNAME}_CFLAGS_OTHER})
1808        if(FLAG MATCHES "-D.*")
1809            string(SUBSTRING ${FLAG} 2 -1 FLAG)
1810            target_compile_definitions(libfastfetch PUBLIC ${FLAG})
1811        endif()
1812    endforeach()
1813endfunction()
1814
1815ff_lib_enable(VULKAN
1816    "vulkan"
1817    "Vulkan"
1818)
1819ff_lib_enable(WAYLAND
1820    "wayland-client"
1821    "WaylandClient"
1822)
1823ff_lib_enable(XCB_RANDR
1824    "xcb-randr"
1825    "XcbRandr"
1826)
1827ff_lib_enable(XRANDR
1828    "xrandr"
1829    "XRandr"
1830)
1831ff_lib_enable(DRM
1832    "libdrm"
1833    "Libdrm"
1834)
1835ff_lib_enable(VADRM
1836    "libva-drm"
1837    "Libva-drm"
1838)
1839ff_lib_enable(VAX11
1840    "libva-x11"
1841    "Libva-x11"
1842)
1843ff_lib_enable(VDPAU
1844    "vdpau"
1845    "vdpau"
1846)
1847ff_lib_enable(GIO
1848    "gio-2.0"
1849    "GIO"
1850)
1851ff_lib_enable(DCONF
1852    "dconf"
1853    "DConf"
1854)
1855ff_lib_enable(EET
1856    "eet"
1857    "Eet"
1858)
1859ff_lib_enable(DBUS
1860    "dbus-1"
1861    "DBus"
1862)
1863ff_lib_enable(SQLITE3
1864    "sqlite3"
1865    "SQLite3"
1866)
1867ff_lib_enable(RPM
1868    "rpm"
1869    "RPM"
1870)
1871ff_lib_enable(IMAGEMAGICK7
1872    "MagickCore-7.Q16HDRI;MagickCore-7.Q16;MagickCore-7;/usr/lib/imagemagick7/pkgconfig/MagickCore-7.Q16HDRI.pc;/usr/lib/imagemagick7/pkgconfig/MagickCore-7.Q16.pc;/usr/lib/imagemagick7/pkgconfig/MagickCore-7.pc"
1873    "ImageMagick7"
1874)
1875ff_lib_enable(IMAGEMAGICK6
1876    "MagickCore-6.Q16HDRI;MagickCore-6.Q16;MagickCore-6;/usr/lib/imagemagick6/pkgconfig/MagickCore-6.Q16HDRI.pc;/usr/lib/imagemagick6/pkgconfig/MagickCore-6.Q16.pc;/usr/lib/imagemagick6/pkgconfig/MagickCore-6.pc"
1877    "ImageMagick6"
1878)
1879ff_lib_enable(ZLIB
1880    "zlib"
1881    "ZLIB"
1882)
1883ff_lib_enable(CHAFA
1884    "chafa>=1.10"
1885    "Chafa"
1886)
1887ff_lib_enable(EGL
1888    "egl"
1889    "EGL"
1890)
1891if(NOT OpenBSD AND NOT NetBSD)
1892    ff_lib_enable(GLX
1893        "glx"
1894        "GLX"
1895    )
1896else()
1897    ff_lib_enable(GLX
1898        "gl"
1899        "GL"
1900    )
1901endif()
1902ff_lib_enable(OPENCL
1903    "OpenCL"
1904    "OpenCL"
1905)
1906# `Freetype` is the module CMake ships (Modules/FindFreetype.cmake); there is no FindFreeType2, so
1907# this name never resolved and only pkg-config could ever turn freetype on.
1908ff_lib_enable(FREETYPE
1909    "freetype2"
1910    "Freetype"
1911)
1912ff_lib_enable(ELF
1913    "libelf"
1914    "libelf"
1915)
1916if(ENABLE_LUA)
1917    # Lua is a special case since its CMake config does not follow the usual pattern
1918    find_package(Lua QUIET)
1919    if(Lua_FOUND AND NOT DEFINED Lua_VERSION) # For CMake 4.2- compatible
1920        set(Lua_VERSION ${LUA_VERSION_STRING})
1921        set(Lua_VERSION_MAJOR ${LUA_VERSION_MAJOR})
1922        set(Lua_VERSION_MINOR ${LUA_VERSION_MINOR})
1923    endif()
1924    if(Lua_FOUND)
1925        if((NOT Lua_VERSION_MAJOR EQUAL 5) OR Lua_VERSION_MINOR LESS 3 OR Lua_VERSION_MINOR GREATER 5)
1926            message(STATUS "Library: Lua version ${Lua_VERSION} is not supported, requires 5.3-5.5")
1927            unset(Lua_FOUND)
1928        else()
1929            target_compile_definitions(libfastfetch PUBLIC FF_HAVE_LUA=1)
1930            target_include_directories(libfastfetch PUBLIC ${LUA_INCLUDE_DIR})
1931
1932            if(NOT BINARY_LINK_TYPE STREQUAL "dlopen")
1933                target_link_libraries(libfastfetch PRIVATE ${LUA_LIBRARIES})
1934            endif()
1935            message(STATUS "Library: found LUA ${Lua_VERSION} by CMake")
1936        endif()
1937    else()
1938        message(STATUS "Library: missing: LUA")
1939    endif()
1940endif()
1941
1942if(ENABLE_THREADS)
1943    target_compile_definitions(libfastfetch PUBLIC FF_HAVE_THREADS=1)
1944    if(CMAKE_USE_PTHREADS_INIT) #Threads::Threads is not set for WIN32
1945        target_link_libraries(libfastfetch PRIVATE Threads::Threads)
1946    endif()
1947endif()
1948
1949if(ENABLE_IMAGE_LOGO)
1950    target_compile_definitions(libfastfetch PUBLIC FF_HAVE_IMAGE_LOGO=1)
1951endif()
1952
1953if(ENABLE_EMBEDDED_PCIIDS)
1954    target_compile_definitions(libfastfetch PUBLIC FF_HAVE_EMBEDDED_PCIIDS=1)
1955endif()
1956if(ENABLE_EMBEDDED_AMDGPUIDS)
1957    target_compile_definitions(libfastfetch PUBLIC FF_HAVE_EMBEDDED_AMDGPUIDS=1)
1958endif()
1959if(ENABLE_LIBZFS)
1960    target_compile_definitions(libfastfetch PUBLIC FF_HAVE_LIBZFS=1)
1961
1962    if(NOT BINARY_LINK_TYPE STREQUAL "dlopen")
1963        target_link_libraries(libfastfetch
1964            PRIVATE "zfs"
1965        )
1966    endif()
1967endif()
1968if(ENABLE_WCWIDTH)
1969    target_compile_definitions(libfastfetch PUBLIC FF_ENABLE_WCWIDTH=1)
1970endif()
1971if(NOT HAVE_MEMRCHR)
1972    target_compile_definitions(libfastfetch PUBLIC FF_HAVE_CUSTOM_MEMRCHR=1)
1973endif()
1974
1975if(LINUX)
1976    target_link_libraries(libfastfetch
1977        PRIVATE "m"
1978    )
1979
1980    if(ENABLE_DIRECTX_HEADERS)
1981        if(NOT BINARY_LINK_TYPE STREQUAL "dlopen")
1982            target_link_libraries(libfastfetch
1983                PRIVATE "/usr/lib/wsl/lib/libdxcore.so"
1984            )
1985        endif()
1986    endif()
1987elseif(APPLE)
1988    target_link_libraries(libfastfetch
1989        PRIVATE "-framework AVFoundation"
1990        PRIVATE "-framework Accelerate"
1991        PRIVATE "-framework Cocoa"
1992        PRIVATE "-framework CoreAudio"
1993        PRIVATE "-framework CoreBluetooth"
1994        PRIVATE "-framework CoreFoundation"
1995        PRIVATE "-framework CoreMedia"
1996        PRIVATE "-framework CoreVideo"
1997        PRIVATE "-framework CoreWLAN"
1998        PRIVATE "-framework GameController"
1999        PRIVATE "-framework IOBluetooth"
2000        PRIVATE "-framework IOKit"
2001        PRIVATE "-framework ImageIO"
2002        PRIVATE "-framework Metal"
2003        PRIVATE "-framework OpenCL"
2004        PRIVATE "-framework OpenGL"
2005        PRIVATE "-framework SystemConfiguration"
2006        PRIVATE "-framework VideoToolbox"
2007
2008        PRIVATE "-F /System/Library/PrivateFrameworks"
2009        PRIVATE "-weak_framework DisplayServices"
2010        PRIVATE "-weak_framework MediaRemote"
2011        PRIVATE "-weak_framework SkyLight"
2012    )
2013elseif(WIN32)
2014    target_link_libraries(libfastfetch
2015        PRIVATE "gdi32"
2016        PRIVATE "iphlpapi"
2017        PRIVATE "ole32"
2018        PRIVATE "oleaut32"
2019        PRIVATE "ws2_32"
2020        PRIVATE "ntdll"
2021        PRIVATE "version"
2022        PRIVATE "hid"
2023        PRIVATE "wtsapi32"
2024        PRIVATE "cfgmgr32"
2025        PRIVATE "winbrand"
2026        PRIVATE "secur32"
2027        PRIVATE "shlwapi"
2028    )
2029    if(ENABLE_IMAGE_LOGO)
2030        # Only src/logo/image/wic.cpp uses WIC, and that file is only compiled with image logos
2031        # enabled (see the WIN32 source list above). Verified by building with
2032        # `-DENABLE_IMAGE_LOGO=OFF` and removing the library from the link line: it links and runs
2033        # without it, and nothing else in the tree references IWIC*.
2034        target_link_libraries(libfastfetch
2035            PRIVATE "windowscodecs"
2036        )
2037    endif()
2038    if(NOT ENABLE_WIN81_COMPAT)
2039        target_link_libraries(libfastfetch
2040            PRIVATE "mincore"
2041        )
2042    endif()
2043    if(HAVE_WINRT)
2044        target_link_libraries(libfastfetch
2045            PRIVATE "runtimeobject"
2046        )
2047    endif()
2048    if(ENABLE_TRACER)
2049        target_link_libraries(libfastfetch
2050            PRIVATE "dbghelp"
2051        )
2052    endif()
2053elseif(FreeBSD)
2054    target_link_libraries(libfastfetch
2055        PRIVATE "m"
2056        PRIVATE "usbhid"
2057        PRIVATE "bluetooth"
2058    )
2059    if(NOT DragonFly)
2060        target_link_libraries(libfastfetch
2061            PRIVATE "geom"
2062        )
2063    else()
2064        target_link_libraries(libfastfetch
2065            PRIVATE "devstat"
2066        )
2067    endif()
2068elseif(OpenBSD)
2069    target_link_libraries(libfastfetch
2070        PRIVATE "m"
2071        PRIVATE "sndio"
2072        PRIVATE "util"
2073    )
2074elseif(NetBSD)
2075    target_link_libraries(libfastfetch
2076        PRIVATE "bluetooth"
2077        PRIVATE "m"
2078        PRIVATE "prop"
2079        PRIVATE "util"
2080    )
2081elseif(SunOS)
2082    target_link_libraries(libfastfetch
2083        PRIVATE "m"
2084        PRIVATE "socket"
2085        PRIVATE "kstat"
2086        PRIVATE "proc"
2087        PRIVATE "devinfo"
2088    )
2089elseif(GNU)
2090    target_link_libraries(libfastfetch
2091        PRIVATE "m"
2092        PRIVATE "ps"
2093    )
2094elseif(ANDROID)
2095    target_link_libraries(libfastfetch
2096        PRIVATE "m"
2097        PRIVATE jnigraphics
2098        PRIVATE mediandk
2099        PRIVATE camera2ndk
2100    )
2101    if(ENABLE_WORDEXP)
2102        # https://github.com/termux/termux-packages/pull/7056
2103        CHECK_LIBRARY_EXISTS(-l:libandroid-wordexp.a wordexp "" HAVE_LIBANDROID_WORDEXP_STATIC)
2104        if(HAVE_LIBANDROID_WORDEXP_STATIC)
2105            target_link_libraries(libfastfetch
2106                PRIVATE -l:libandroid-wordexp.a
2107            )
2108        else()
2109            CHECK_LIBRARY_EXISTS(android-wordexp wordexp "" HAVE_LIBANDROID_WORDEXP)
2110            if(HAVE_LIBANDROID_WORDEXP)
2111                target_link_libraries(libfastfetch
2112                    PRIVATE android-wordexp
2113                )
2114            endif()
2115        endif()
2116    endif()
2117
2118    # Three APIs are newer than the API level this build targets: AImageDecoder is 30,
2119    # AndroidBitmap_compress is 30, and AMediaCodec_getName / AMediaCodec_releaseName are 28.
2120    # fastfetch keeps running on devices below those levels, and the NDK headers mark the entry
2121    # points unavailable there, so they have to be weak references -- a strong reference would fail
2122    # the load on an older device. Guarding every use with __builtin_available() is what makes that
2123    # safe, and turning the guard diagnostic into an error keeps a use from slipping past it.
2124    #
2125    # Each one lives in the library that provides it, and that library is linked above:
2126    # AImageDecoder_* and AndroidBitmap_compress are exported by libjnigraphics.so, and
2127    # AMediaCodec_* by libmediandk.so. Checked on a device (Android 16, API 36) with
2128    # `readelf --dyn-syms /system/lib64/libjnigraphics.so` and a dlopen/dlsym probe: every
2129    # AImageDecoder_* entry point resolves there and none of them resolves in libandroid.so, which
2130    # is why libandroid.so is *not* linked -- nothing fastfetch calls comes from it. Keep the
2131    # provider library linked for the reason the NDK requires it: an undefined weak symbol resolves
2132    # to NULL rather than failing the load, and FF_ANDROID_API_AT_LEAST() reads the platform level,
2133    # not the symbol, so it would send the call straight through a NULL pointer on every device new
2134    # enough to pass the guard.
2135    #
2136    # camera_android.c is deliberately not in this list. The camera2 NDK is a *library* that starts at
2137    # API 24, and a weak reference weakens the symbol, never the library: DT_NEEDED would still name
2138    # libcamera2ndk.so, and a device below API 24 would fail to load fastfetch at all. The NDK's guide
2139    # is explicit that there is no such thing as a weak library reference, and that dlopen is the only
2140    # way to reach a library newer than minSdkVersion. Nothing here pins ANDROID_PLATFORM, so a build
2141    # aimed below 24 would need that; on the supported path -- Termux, which targets 24 -- the library
2142    # is always present and the plain call is correct. libjnigraphics itself is one of them and is
2143    # linked unconditionally above, so the encoder only needs its symbol weakened, not its library.
2144    set_source_files_properties(
2145        ${CMAKE_CURRENT_SOURCE_DIR}/src/logo/image/aid.c
2146        ${CMAKE_CURRENT_SOURCE_DIR}/src/detection/media/media_android.c
2147        ${CMAKE_CURRENT_SOURCE_DIR}/src/detection/codec/codec_android.c
2148        PROPERTIES COMPILE_OPTIONS "-D__ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__;-Werror=unguarded-availability")
2149elseif(Haiku)
2150    target_link_libraries(libfastfetch
2151        PRIVATE "network"
2152        PRIVATE "bnetapi"
2153        PRIVATE "media"
2154        PRIVATE "device"
2155        PRIVATE "bluetooth"
2156        PRIVATE "GL"
2157        PRIVATE "be"
2158        PRIVATE "gnu"
2159        PRIVATE "bsd"
2160    )
2161endif()
2162
2163target_include_directories(libfastfetch
2164    PUBLIC ${PROJECT_BINARY_DIR}
2165    PUBLIC ${PROJECT_SOURCE_DIR}/src
2166)
2167
2168if(ENABLE_SIXEL)
2169    # src/3rdparty/sixel/*.c include <sixel.h> (angle brackets, so the directory itself
2170    # has to be on the include path)
2171    target_include_directories(libfastfetch PRIVATE ${PROJECT_SOURCE_DIR}/src/3rdparty/sixel)
2172
2173    # The vendored subset is not a library to be detected, so FF_HAVE_SIXEL can't come
2174    # from ff_lib_enable() and has to be defined here
2175    target_compile_definitions(libfastfetch PUBLIC FF_HAVE_SIXEL=1)
2176endif()
2177
2178target_link_libraries(libfastfetch
2179    PRIVATE ${CMAKE_DL_LIBS}
2180)
2181
2182target_compile_options(libfastfetch PUBLIC
2183    $<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions -fno-rtti>)
2184
2185if(FreeBSD)
2186    set(CMAKE_REQUIRED_INCLUDES "/usr/local/include" "/usr/include")
2187endif()
2188if(LINUX OR FreeBSD OR OpenBSD OR NetBSD)
2189    CHECK_INCLUDE_FILE("linux/videodev2.h" HAVE_LINUX_VIDEODEV2)
2190    if(HAVE_LINUX_VIDEODEV2)
2191        target_compile_definitions(libfastfetch PUBLIC FF_HAVE_LINUX_VIDEODEV2=1)
2192    endif()
2193endif()
2194if(NOT WIN32)
2195    CHECK_INCLUDE_FILE("utmpx.h" HAVE_UTMPX)
2196    if(HAVE_UTMPX)
2197        target_compile_definitions(libfastfetch PUBLIC FF_HAVE_UTMPX=1)
2198    endif()
2199    if(ENABLE_WORDEXP)
2200        CHECK_INCLUDE_FILE("wordexp.h" HAVE_WORDEXP)
2201        if(HAVE_WORDEXP)
2202            target_compile_definitions(libfastfetch PUBLIC FF_HAVE_WORDEXP=1)
2203            message(STATUS "wordexp.h found, wordexp support enabled")
2204        else()
2205            set(ENABLE_WORDEXP OFF)
2206        endif()
2207    endif()
2208    if(NOT ENABLE_WORDEXP)
2209        # wordexp.h is not the only thing that can be missing. bionic declares glob() and globfree()
2210        # only from API 28, so an NDK build aimed at 24 has neither and a fallback that assumed glob
2211        # would have nothing to call. The symbol is what has to be checked, not the header: <glob.h>
2212        # is present at every level, it just declares nothing below 28.
2213        check_symbol_exists("glob" "glob.h" HAVE_GLOB)
2214        if(HAVE_GLOB)
2215            target_compile_definitions(libfastfetch PUBLIC FF_HAVE_GLOB=1)
2216            message(STATUS "wordexp.h not found or disabled, glob used instead")
2217        else()
2218            message(STATUS "neither wordexp.h nor glob.h is usable, config paths will not be expanded")
2219        endif()
2220    endif()
2221    if(ENABLE_THREADS AND CMAKE_USE_PTHREADS_INIT)
2222        CHECK_INCLUDE_FILE("pthread_np.h" HAVE_PTHREAD_NP)
2223        if(HAVE_PTHREAD_NP)
2224            target_compile_definitions(libfastfetch PUBLIC FF_HAVE_PTHREAD_NP=1)
2225            set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} pthread_np.h)
2226        endif()
2227        set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} Threads::Threads)
2228        check_function_exists("pthread_timedjoin_np" HAVE_TIMEDJOIN_NP)
2229        if(HAVE_TIMEDJOIN_NP)
2230            target_compile_definitions(libfastfetch PUBLIC FF_HAVE_TIMEDJOIN_NP=1)
2231        else()
2232            message(WARNING "pthread_timedjoin_np was not found; networking timeout will not work")
2233        endif()
2234    endif()
2235elseif(HAVE_WINRT)
2236    target_compile_definitions(libfastfetch PUBLIC FF_HAVE_WINRT=1)
2237endif()
2238
2239set(PACKAGES_DISABLE_LIST "")
2240foreach(package_manager ${PACKAGE_MANAGERS})
2241    if(PACKAGES_DISABLE_${package_manager})
2242        list(APPEND PACKAGES_DISABLE_LIST "${package_manager}")
2243    endif()
2244endforeach()
2245if("${PACKAGES_DISABLE_LIST}" STREQUAL "")
2246    set(PACKAGES_DISABLE_LIST "FF_PACKAGES_FLAG_NONE")
2247else()
2248    message(STATUS "Disabled package managers: ${PACKAGES_DISABLE_LIST}")
2249    list(TRANSFORM PACKAGES_DISABLE_LIST PREPEND "FF_PACKAGES_FLAG_")
2250    list(TRANSFORM PACKAGES_DISABLE_LIST APPEND "_BIT")
2251    list(JOIN PACKAGES_DISABLE_LIST " | " PACKAGES_DISABLE_LIST)
2252endif()
2253target_compile_definitions(libfastfetch PUBLIC "FF_PACKAGES_DISABLE_LIST=${PACKAGES_DISABLE_LIST}")
2254if(PACKAGES_REMOVE_DISABLED)
2255    target_compile_definitions(libfastfetch PUBLIC FF_PACKAGES_REMOVE_DISABLED=1)
2256endif()
2257
2258######################
2259# Executable targets #
2260######################
2261
2262add_executable(fastfetch
2263    src/fastfetch.c
2264)
2265target_compile_definitions(fastfetch
2266    PRIVATE FASTFETCH_TARGET_BINARY_NAME=fastfetch
2267)
2268target_link_libraries(fastfetch
2269    PRIVATE libfastfetch
2270)
2271
2272# Prevent fastfetch from linking to libstdc++
2273set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "")
2274set(CMAKE_CXX_IMPLICIT_LINK_DIRECTORIES "")
2275set_target_properties(fastfetch PROPERTIES LINKER_LANGUAGE C)
2276
2277if(WIN32)
2278    # version.rc embeds manifest.xml (RT_MANIFEST) and logo.ico (ICON) as *resource
2279    # references*, not as #includes, so the resource compiler never reports them and
2280    # CMake would keep a stale .res when only the manifest or the icon changes. Both
2281    # are plain files rather than generated ones, so declare them by hand; the source
2282    # file property is per-path, which is why flashfetch below needs no repeat.
2283    set_property(SOURCE src/common/windows/version.rc APPEND PROPERTY OBJECT_DEPENDS
2284        "${CMAKE_CURRENT_SOURCE_DIR}/src/common/windows/manifest.xml"
2285        "${CMAKE_CURRENT_SOURCE_DIR}/src/common/windows/logo.ico"
2286    )
2287    target_sources(fastfetch
2288        PRIVATE src/common/windows/version.rc
2289    )
2290elseif(APPLE)
2291    target_link_options(fastfetch
2292        PRIVATE LINKER:-sectcreate,__TEXT,__info_plist,Info.plist
2293    )
2294    # `LINKER:` options are handed to ld verbatim and are not registered as build
2295    # dependencies, so without this ninja never relinks when Info.plist changes.
2296    set_property(TARGET fastfetch APPEND PROPERTY LINK_DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/Info.plist")
2297    # ld derives the ad-hoc code-signing identifier from the output file name and
2298    # ignores the embedded CFBundleIdentifier, so set it explicitly.
2299    add_custom_command(TARGET fastfetch POST_BUILD
2300        COMMAND codesign --force --sign - --identifier "${FASTFETCH_BUNDLE_ID}" "$<TARGET_FILE:fastfetch>"
2301        VERBATIM
2302    )
2303endif()
2304
2305if(BINARY_LINK_TYPE STREQUAL "static")
2306    target_link_options(fastfetch PRIVATE "-static")
2307endif()
2308
2309# Apply all above parameters to flashfetch if it is built
2310if (BUILD_FLASHFETCH)
2311    add_executable(flashfetch
2312        src/flashfetch.c
2313    )
2314    target_compile_definitions(flashfetch
2315        PRIVATE FASTFETCH_TARGET_BINARY_NAME=flashfetch
2316    )
2317    target_link_libraries(flashfetch
2318        PRIVATE libfastfetch
2319    )
2320
2321    set_target_properties(flashfetch PROPERTIES LINKER_LANGUAGE C)
2322
2323    if(WIN32)
2324        target_sources(flashfetch
2325            PRIVATE src/common/windows/version.rc
2326        )
2327    elseif(APPLE)
2328        # flashfetch embeds its own plist so that its CFBundleIdentifier matches the
2329        # identifier it is signed with below (see the APPLE block near the top).
2330        target_link_options(flashfetch
2331            PRIVATE LINKER:-sectcreate,__TEXT,__info_plist,Info.plist.flashfetch
2332        )
2333        set_property(TARGET flashfetch APPEND PROPERTY LINK_DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/Info.plist.flashfetch")
2334        add_custom_command(TARGET flashfetch POST_BUILD
2335            COMMAND codesign --force --sign - --identifier "${FLASHFETCH_BUNDLE_ID}" "$<TARGET_FILE:flashfetch>"
2336            VERBATIM
2337        )
2338    endif()
2339
2340    if(BINARY_LINK_TYPE STREQUAL "static")
2341        target_link_options(flashfetch PRIVATE "-static")
2342    endif()
2343endif()
2344
2345###################
2346# Testing targets #
2347###################
2348
2349if (BUILD_TESTS)
2350    add_executable(fastfetch-test-cache
2351        tests/cache.c
2352    )
2353    target_link_libraries(fastfetch-test-cache
2354        PRIVATE libfastfetch
2355    )
2356
2357    add_executable(fastfetch-test-logo
2358        tests/logo.c
2359    )
2360    target_link_libraries(fastfetch-test-logo
2361        PRIVATE libfastfetch
2362    )
2363
2364    add_executable(fastfetch-test-strbuf
2365        tests/strbuf.c
2366    )
2367    target_link_libraries(fastfetch-test-strbuf
2368        PRIVATE libfastfetch
2369    )
2370
2371    add_executable(fastfetch-test-list
2372        tests/list.c
2373    )
2374    target_link_libraries(fastfetch-test-list
2375        PRIVATE libfastfetch
2376    )
2377
2378    add_executable(fastfetch-test-format
2379        tests/format.c
2380    )
2381    target_link_libraries(fastfetch-test-format
2382        PRIVATE libfastfetch
2383    )
2384
2385    add_executable(fastfetch-test-color
2386        tests/color.c
2387    )
2388    target_link_libraries(fastfetch-test-color
2389        PRIVATE libfastfetch
2390    )
2391
2392    add_executable(fastfetch-test-duration
2393        tests/duration.c
2394    )
2395    target_link_libraries(fastfetch-test-duration
2396        PRIVATE libfastfetch
2397    )
2398
2399    add_executable(fastfetch-test-strutil
2400        tests/strutil.c
2401    )
2402    target_link_libraries(fastfetch-test-strutil
2403        PRIVATE libfastfetch
2404    )
2405
2406    add_executable(fastfetch-test-networking
2407        tests/networking.c
2408    )
2409    target_link_libraries(fastfetch-test-networking
2410        PRIVATE libfastfetch
2411    )
2412
2413    add_executable(fastfetch-test-base64
2414        tests/base64.c
2415    )
2416    target_link_libraries(fastfetch-test-base64
2417        PRIVATE libfastfetch
2418    )
2419
2420    add_executable(fastfetch-test-parsing
2421        tests/parsing.c
2422    )
2423    target_link_libraries(fastfetch-test-parsing
2424        PRIVATE libfastfetch
2425    )
2426
2427    add_executable(fastfetch-test-properties
2428        tests/properties.c
2429    )
2430    target_link_libraries(fastfetch-test-properties
2431        PRIVATE libfastfetch
2432    )
2433
2434    add_executable(fastfetch-test-size
2435        tests/size.c
2436    )
2437    target_link_libraries(fastfetch-test-size
2438        PRIVATE libfastfetch
2439    )
2440
2441    add_executable(fastfetch-test-frequency
2442        tests/frequency.c
2443    )
2444    target_link_libraries(fastfetch-test-frequency
2445        PRIVATE libfastfetch
2446    )
2447
2448    add_executable(fastfetch-test-percent
2449        tests/percent.c
2450    )
2451    target_link_libraries(fastfetch-test-percent
2452        PRIVATE libfastfetch
2453    )
2454
2455    add_executable(fastfetch-test-temps
2456        tests/temps.c
2457    )
2458    target_link_libraries(fastfetch-test-temps
2459        PRIVATE libfastfetch
2460    )
2461
2462    add_executable(fastfetch-test-endian
2463        tests/endian.c
2464    )
2465    target_link_libraries(fastfetch-test-endian
2466        PRIVATE libfastfetch
2467    )
2468
2469    add_executable(fastfetch-test-endian-bigendian
2470        tests/endian-bigendian.c
2471    )
2472    target_link_libraries(fastfetch-test-endian-bigendian
2473        PRIVATE libfastfetch
2474    )
2475
2476    add_executable(fastfetch-test-gpu-pci
2477        tests/gpu_pci.c
2478    )
2479    target_link_libraries(fastfetch-test-gpu-pci
2480        PRIVATE libfastfetch
2481    )
2482
2483    enable_testing()
2484    add_test(NAME test-cache COMMAND fastfetch-test-cache)
2485    add_test(NAME test-logo COMMAND fastfetch-test-logo)
2486    add_test(NAME test-strbuf COMMAND fastfetch-test-strbuf)
2487    add_test(NAME test-list COMMAND fastfetch-test-list)
2488    add_test(NAME test-format COMMAND fastfetch-test-format)
2489    add_test(NAME test-color COMMAND fastfetch-test-color)
2490    add_test(NAME test-duration COMMAND fastfetch-test-duration)
2491    add_test(NAME test-strutil COMMAND fastfetch-test-strutil)
2492    add_test(NAME test-networking COMMAND fastfetch-test-networking)
2493    add_test(NAME test-base64 COMMAND fastfetch-test-base64)
2494    add_test(NAME test-parsing COMMAND fastfetch-test-parsing)
2495    add_test(NAME test-properties COMMAND fastfetch-test-properties)
2496    add_test(NAME test-size COMMAND fastfetch-test-size)
2497    add_test(NAME test-frequency COMMAND fastfetch-test-frequency)
2498    add_test(NAME test-percent COMMAND fastfetch-test-percent)
2499    add_test(NAME test-temps COMMAND fastfetch-test-temps)
2500    add_test(NAME test-endian COMMAND fastfetch-test-endian)
2501    add_test(NAME test-endian-bigendian COMMAND fastfetch-test-endian-bigendian)
2502    add_test(NAME test-gpu-pci COMMAND fastfetch-test-gpu-pci)
2503endif()
2504
2505##################
2506# install target #
2507##################
2508
2509include(GNUInstallDirs)
2510
2511install(
2512    TARGETS fastfetch
2513    DESTINATION "${CMAKE_INSTALL_BINDIR}"
2514)
2515
2516if (TARGET flashfetch)
2517    install(
2518        TARGETS flashfetch
2519        DESTINATION "${CMAKE_INSTALL_BINDIR}"
2520    )
2521endif()
2522
2523install(
2524    FILES "${CMAKE_SOURCE_DIR}/completions/${CMAKE_PROJECT_NAME}.bash"
2525    DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/bash-completion/completions"
2526    RENAME "${CMAKE_PROJECT_NAME}"
2527)
2528
2529install(
2530    FILES "${CMAKE_SOURCE_DIR}/completions/${CMAKE_PROJECT_NAME}.zsh"
2531    DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/zsh/site-functions"
2532    RENAME "_${CMAKE_PROJECT_NAME}"
2533)
2534
2535install(
2536    FILES "${CMAKE_SOURCE_DIR}/completions/${CMAKE_PROJECT_NAME}.fish"
2537    DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/fish/vendor_completions.d"
2538    RENAME "${CMAKE_PROJECT_NAME}.fish"
2539)
2540
2541install(
2542    DIRECTORY "${CMAKE_SOURCE_DIR}/presets"
2543    DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/${CMAKE_PROJECT_NAME}"
2544)
2545
2546if(INSTALL_LICENSE)
2547    install(
2548        FILES "${CMAKE_SOURCE_DIR}/LICENSE"
2549        DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/licenses/${CMAKE_PROJECT_NAME}"
2550    )
2551endif()
2552
2553install(
2554    FILES "${PROJECT_BINARY_DIR}/fastfetch.1"
2555    DESTINATION "${CMAKE_INSTALL_MANDIR}/man1"
2556)
2557
2558##################
2559# package target #
2560##################
2561
2562set(CPACK_GENERATOR "TGZ;ZIP")
2563if(APPLE)
2564    if(CMAKE_OSX_ARCHITECTURES MATCHES ";") # multiple architectures, e.g. arm64;x86_64
2565        set(_FF_CPACK_ARCH universal)
2566    else()
2567        set(_FF_CPACK_ARCH ${CMAKE_SYSTEM_PROCESSOR})
2568    endif()
2569    string(TOLOWER "${CMAKE_PROJECT_NAME}-macos-${_FF_CPACK_ARCH}" CPACK_PACKAGE_FILE_NAME) # use macos instead of darwin
2570elseif(IS_MUSL)
2571    string(TOLOWER "${CMAKE_PROJECT_NAME}-musl-${CMAKE_SYSTEM_PROCESSOR}" CPACK_PACKAGE_FILE_NAME)
2572else()
2573    string(TOLOWER "${CMAKE_PROJECT_NAME}-${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}" CPACK_PACKAGE_FILE_NAME)
2574endif()
2575
2576if(LINUX)
2577    find_program(HAVE_DPKG "dpkg")
2578    if(HAVE_DPKG)
2579        set(CPACK_GENERATOR "${CPACK_GENERATOR};DEB")
2580
2581        set(CPACK_DEBIAN_PACKAGE_SECTION, "utils")
2582        set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional")
2583
2584        if(NOT IS_MUSL)
2585            EXECUTE_PROCESS(
2586                COMMAND getconf GNU_LIBC_VERSION
2587                OUTPUT_VARIABLE GLIBC_VERSION
2588                OUTPUT_STRIP_TRAILING_WHITESPACE)
2589            if(GLIBC_VERSION)
2590                STRING(REPLACE "glibc " "" GLIBC_VERSION ${GLIBC_VERSION})
2591                set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= ${GLIBC_VERSION})")
2592                message(STATUS "found glibc ${GLIBC_VERSION}")
2593            else()
2594                message(WARNING "Could not determine glibc version. If `musl` is used, `-DIS_MUSL=ON` should be set")
2595            endif()
2596        endif()
2597    endif()
2598
2599    if(NOT IS_MUSL)
2600        find_program(HAVE_RPMBUILD "rpmbuild")
2601        if(HAVE_RPMBUILD)
2602            set(CPACK_GENERATOR "${CPACK_GENERATOR};RPM")
2603
2604            set(CPACK_RPM_PACKAGE_LICENSE "MIT")
2605        endif()
2606    endif()
2607elseif(FreeBSD AND NOT DragonFly)
2608    set(CPACK_FREEBSD_PACKAGE_LICENSE "MIT")
2609    set(CPACK_GENERATOR "${CPACK_GENERATOR};FREEBSD")
2610endif()
2611
2612set(CPACK_SET_DESTDIR ON)
2613
2614set(CPACK_PACKAGE_CONTACT "Carter Li <zhangsongcui@live.cn>")
2615set(CPACK_PACKAGE_DESCRIPTION "\
2616fastfetch is a neofetch-like tool for fetching system information and displaying them in a pretty way. \
2617It is written mostly in C to achieve much better performance.\
2618")
2619
2620include(CPack)