refactor(cmake): Cleanup

This commit is contained in:
Michael Carlberg 2017-01-26 17:17:02 +01:00
parent b97e4c56c5
commit 43a17c3b36
24 changed files with 410 additions and 758 deletions

View File

@ -8,21 +8,25 @@ project(polybar C CXX)
set(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
${PROJECT_SOURCE_DIR}/cmake
${PROJECT_SOURCE_DIR}/cmake/common
${PROJECT_SOURCE_DIR}/cmake/modules)
include(utils)
include(build/core)
include(build/options)
include(build/targets)
include(build/summary)
include(01-core)
include(02-opts)
include(03-libs)
include(04-targets)
include(05-summary)
add_subdirectory(${PROJECT_SOURCE_DIR}/man)
add_subdirectory(${PROJECT_SOURCE_DIR}/src ${PROJECT_BINARY_DIR}/bin)
add_subdirectory(${PROJECT_SOURCE_DIR}/doc ${PROJECT_BINARY_DIR}/doc)
add_subdirectory(${PROJECT_SOURCE_DIR}/doc/zsh ${PROJECT_BINARY_DIR}/doc/zsh)
add_subdirectory(doc)
add_subdirectory(doc/zsh)
add_subdirectory(include)
add_subdirectory(lib)
add_subdirectory(man)
add_subdirectory(src bin)
if(BUILD_TESTS)
add_subdirectory(${PROJECT_SOURCE_DIR}/tests ${PROJECT_BINARY_DIR}/tests)
add_subdirectory(tests)
else()
add_subdirectory(${PROJECT_SOURCE_DIR}/tests ${PROJECT_BINARY_DIR}/tests EXCLUDE_FROM_ALL)
add_subdirectory(tests EXCLUDE_FROM_ALL)
endif()

View File

@ -1,10 +1,13 @@
#
# Core setup
#
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(THREADS_PREFER_PTHREAD_FLAG ON)
# Export compile commands used for custom targets
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
@ -59,7 +62,7 @@ elseif(CXXLIB_GCC)
endif()
if(ENABLE_CCACHE)
require_binary(ccache)
querybin(ccache)
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${BINPATH_ccache})
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ${BINPATH_ccache})
endif()

70
cmake/02-opts.cmake Normal file
View File

@ -0,0 +1,70 @@
#
# Build options
#
checklib(ENABLE_ALSA "pkg-config" alsa)
checklib(ENABLE_CURL "pkg-config" libcurl)
checklib(ENABLE_I3 "binary" i3)
checklib(ENABLE_MPD "pkg-config" libmpdclient)
checklib(ENABLE_NETWORK "cmake" Libiw)
checklib(WITH_XRM "pkg-config" xcb-xrm)
checklib(WITH_XRANDR_MONITORS "pkg-config" "xrandr>=1.5.0;randrproto>=1.5.0;xcb-proto>=1.12")
option(CXXLIB_CLANG "Link against libc++" OFF)
option(CXXLIB_GCC "Link against stdlibc++" OFF)
option(BUILD_IPC_MSG "Build ipc messager" ON)
option(BUILD_TESTS "Build testsuite" OFF)
option(ENABLE_CCACHE "Enable ccache support" ${DEBUG})
option(ENABLE_ALSA "Enable alsa support" ON)
option(ENABLE_CURL "Enable curl support" ON)
option(ENABLE_I3 "Enable i3 support" ON)
option(ENABLE_MPD "Enable mpd support" ON)
option(ENABLE_NETWORK "Enable network support" ON)
option(ENABLE_XKEYBOARD "Enable xkeyboard support" ON)
option(WITH_XRANDR "xcb-randr support" ON)
option(WITH_XRANDR_MONITORS "xcb-randr monitor support" ON)
option(WITH_XRENDER "xcb-render support" OFF)
option(WITH_XDAMAGE "xcb-damage support" OFF)
option(WITH_XSYNC "xcb-sync support" OFF)
option(WITH_XCOMPOSITE "xcb-composite support" OFF)
option(WITH_XKB "xcb-xkb support" ON)
option(WITH_XRM "xcb-xrm support" ON)
option(DEBUG_LOGGER "Debug logging" ${DEBUG})
option(DEBUG_LOGGER_VERBOSE "Debug logging (verbose)" OFF)
option(DEBUG_HINTS "Debug clickable areas" OFF)
option(DEBUG_WHITESPACE "Debug whitespace" OFF)
option(DEBUG_FONTCONFIG "Debug fontconfig" OFF)
set(SETTING_ALSA_SOUNDCARD "default"
CACHE STRING "Name of the ALSA soundcard driver")
set(SETTING_BSPWM_SOCKET_PATH "/tmp/bspwm_0_0-socket"
CACHE STRING "Path to bspwm socket")
set(SETTING_BSPWM_STATUS_PREFIX "W"
CACHE STRING "Prefix prepended to the bspwm status line")
set(SETTING_CONNECTION_TEST_IP "8.8.8.8"
CACHE STRING "Address to ping when testing network connection")
set(SETTING_PATH_ADAPTER "/sys/class/power_supply/%adapter%"
CACHE STRING "Path to adapter")
set(SETTING_PATH_BACKLIGHT_MAX "/sys/class/backlight/%card%/max_brightness"
CACHE STRING "Path to file containing the maximum backlight value")
set(SETTING_PATH_BACKLIGHT_VAL "/sys/class/backlight/%card%/brightness"
CACHE STRING "Path to file containing the current backlight value")
set(SETTING_PATH_BATTERY "/sys/class/power_supply/%battery%"
CACHE STRING "Path to battery")
set(SETTING_PATH_CPU_INFO "/proc/stat"
CACHE STRING "Path to file containing cpu info")
set(SETTING_PATH_MEMORY_INFO "/proc/meminfo"
CACHE STRING "Path to file containing memory info")
set(SETTING_PATH_MESSAGING_FIFO "/tmp/polybar_mqueue.%pid%"
CACHE STRING "Path to file containing the current temperature")
set(SETTING_PATH_TEMPERATURE_INFO "/sys/class/thermal/thermal_zone%zone%/temp"
CACHE STRING "Path to file containing the current temperature")
if(DEBUG)
set(DEBUG_HINTS_OFFSET_X 0 CACHE INTEGER "Debug hint offset x")
set(DEBUG_HINTS_OFFSET_Y 0 CACHE INTEGER "Debug hint offset y")
endif()

22
cmake/03-libs.cmake Normal file
View File

@ -0,0 +1,22 @@
#
# Check libraries
#
find_package(Threads REQUIRED)
list(APPEND libs ${CMAKE_THREAD_LIBS_INIT})
querylib(TRUE "pkg-config" cairo-fc libs dirs)
querylib(ENABLE_ALSA "pkg-config" alsa libs dirs)
querylib(ENABLE_CURL "pkg-config" libcurl libs dirs)
querylib(ENABLE_MPD "pkg-config" libmpdclient libs dirs)
querylib(ENABLE_NETWORK "cmake" Libiw libs dirs)
querylib(WITH_XCOMPOSITE "pkg-config" xcb-composite libs dirs)
querylib(WITH_XDAMAGE "pkg-config" xcb-damage libs dirs)
querylib(WITH_XKB "pkg-config" xcb-xkb libs dirs)
querylib(WITH_XRANDR "pkg-config" xcb-randr libs dirs)
querylib(WITH_XRANDR_MONITORS "pkg-config" "xrandr>=1.5.0;randrproto>=1.5.0;xcb-proto>=1.12" libs dirs)
querylib(WITH_XRENDER "pkg-config" xcb-render libs dirs)
querylib(WITH_XRM "pkg-config" xcb-xrm libs dirs)
querylib(WITH_XSYNC "pkg-config" xcb-sync libs dirs)

41
cmake/05-summary.cmake Normal file
View File

@ -0,0 +1,41 @@
#
# Output build summary
#
string(TOUPPER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_UPPER)
message(STATUS " Build:")
message_colored(STATUS " Type: ${CMAKE_BUILD_TYPE}" "37;2")
message_colored(STATUS " CC: ${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_${CMAKE_BUILD_TYPE_UPPER}}" "37;2")
message_colored(STATUS " CXX: ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE_UPPER}}" "37;2")
message_colored(STATUS " LD: ${CMAKE_LINKER} ${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS_${CMAKE_BUILD_TYPE_UPPER}}" "37;2")
message(STATUS " Targets:")
colored_option(" polybar-msg" BUILD_IPC_MSG)
colored_option(" testsuite" BUILD_TESTS)
message(STATUS " Module supprt:")
colored_option(" alsa" ENABLE_ALSA)
colored_option(" curl" ENABLE_CURL)
colored_option(" i3" ENABLE_I3)
colored_option(" mpd" ENABLE_MPD)
colored_option(" network" ENABLE_NETWORK)
message(STATUS " X extensions:")
colored_option(" xcb-randr" WITH_XRANDR)
colored_option(" xcb-randr (monitor support)" WITH_XRANDR_MONITORS)
colored_option(" xcb-render" WITH_XRENDER)
colored_option(" xcb-damage" WITH_XDAMAGE)
colored_option(" xcb-sync" WITH_XSYNC)
colored_option(" xcb-composite" WITH_XCOMPOSITE)
colored_option(" xcb-xkb" WITH_XKB)
colored_option(" xcb-xrm" WITH_XRM)
if(DEBUG)
message(STATUS " Debug options:")
colored_option(" Trace logging" DEBUG_LOGGER)
colored_option(" Trace logging (verbose)" DEBUG_LOGGER_VERBOSE)
colored_option(" Draw clickable areas" DEBUG_HINTS)
colored_option(" Print fc-match details" DEBUG_FONTCONFIG)
colored_option(" Enable window shading" DEBUG_SHADED)
endif()

View File

@ -1,125 +0,0 @@
#
# Build options
#
# Default value for: ENABLE_ALSA {{{
find_package(ALSA QUIET)
if(NOT DEFINED ENABLE_ALSA AND NOT ALSA_FOUND)
set(ENABLE_ALSA OFF CACHE STRING "Module support for alsa-lib")
endif()
# }}}
# Default value for: ENABLE_NETWORK {{{
find_package(Libiw QUIET)
if(NOT DEFINED ENABLE_NETWORK AND NOT LIBIW_FOUND)
set(ENABLE_NETWORK OFF CACHE STRING "Module support for wireless_tools")
endif()
# }}}
# Default value for: ENABLE_MPD {{{
find_package(LibMPDClient QUIET)
if(NOT DEFINED ENABLE_MPD AND NOT LIBMPDCLIENT_FOUND)
set(ENABLE_MPD OFF CACHE STRING "Module support for libmpdclient")
endif()
# }}}
# Default value for: ENABLE_I3 {{{
find_program(I3_BINARY i3)
if(NOT DEFINED ENABLE_I3 AND NOT I3_BINARY)
set(ENABLE_I3 OFF CACHE STRING "Module support for i3wm")
endif()
# }}}
# Default value for: ENABLE_CURL {{{
find_package(CURL QUIET)
if(NOT DEFINED ENABLE_CURL AND NOT CURL_FOUND)
set(ENABLE_CURL OFF CACHE STRING "Module support for libcurl")
endif()
# }}}
# Default value for: WITH_XRM {{{
if(NOT DEFINED WITH_XRM)
pkg_check_modules(XRM QUIET xcb-xrm)
set(WITH_XRM ${XRM_FOUND} CACHE BOOL "Enable xcb-xrm support")
endif()
# }}}
# Define build options {{{
option(CXXLIB_CLANG "Link against libc++" OFF)
option(CXXLIB_GCC "Link against stdlibc++" OFF)
option(BUILD_IPC_MSG "Build ipc messager" ON)
option(BUILD_TESTS "Build testsuite" OFF)
if(DEBUG)
option(DEBUG_LOGGER "Debug logging" OFF)
option(DEBUG_LOGGER_VERBOSE "Debug logging (verbose)" OFF)
option(DEBUG_HINTS "Debug clickable areas" OFF)
option(DEBUG_WHITESPACE "Debug whitespace" OFF)
option(DEBUG_FONTCONFIG "Debug fontconfig" OFF)
endif()
option(ENABLE_CCACHE "Enable ccache support" OFF)
option(ENABLE_ALSA "Enable alsa support" ON)
option(ENABLE_CURL "Enable curl support" ON)
option(ENABLE_I3 "Enable i3 support" ON)
option(ENABLE_MPD "Enable mpd support" ON)
option(ENABLE_NETWORK "Enable network support" ON)
option(WITH_XRANDR "xcb-randr support" ON)
option(WITH_XRENDER "xcb-render support" OFF)
option(WITH_XDAMAGE "xcb-damage support" OFF)
option(WITH_XSYNC "xcb-sync support" OFF)
option(WITH_XCOMPOSITE "xcb-composite support" OFF)
option(WITH_XKB "xcb-xkb support" ON)
option(WITH_XRM "xcb-xrm support" ON)
if(NOT DEFINED ENABLE_XRANDR_MONITORS)
pkg_check_modules(XRANDR QUIET xrandr>=1.5.0 randrproto>=1.5.0 xcb-proto>=1.12)
if(NOT XRANDR_FOUND)
set(XRANDR_FOUND OFF)
endif()
set(ENABLE_XRANDR_MONITORS ${XRANDR_FOUND} CACHE BOOL "Enable XRandR monitor feature (requires version 1.5+)")
endif()
# }}}
# Set cache vars {{{
set(SETTING_ALSA_SOUNDCARD "default"
CACHE STRING "Name of the ALSA soundcard driver")
set(SETTING_BSPWM_SOCKET_PATH "/tmp/bspwm_0_0-socket"
CACHE STRING "Path to bspwm socket")
set(SETTING_BSPWM_STATUS_PREFIX "W"
CACHE STRING "Prefix prepended to the bspwm status line")
set(SETTING_CONNECTION_TEST_IP "8.8.8.8"
CACHE STRING "Address to ping when testing network connection")
set(SETTING_PATH_ADAPTER "/sys/class/power_supply/%adapter%"
CACHE STRING "Path to adapter")
set(SETTING_PATH_BACKLIGHT_MAX "/sys/class/backlight/%card%/max_brightness"
CACHE STRING "Path to file containing the maximum backlight value")
set(SETTING_PATH_BACKLIGHT_VAL "/sys/class/backlight/%card%/brightness"
CACHE STRING "Path to file containing the current backlight value")
set(SETTING_PATH_BATTERY "/sys/class/power_supply/%battery%"
CACHE STRING "Path to battery")
set(SETTING_PATH_CPU_INFO "/proc/stat"
CACHE STRING "Path to file containing cpu info")
set(SETTING_PATH_MEMORY_INFO "/proc/meminfo"
CACHE STRING "Path to file containing memory info")
set(SETTING_PATH_MESSAGING_FIFO "/tmp/polybar_mqueue.%pid%"
CACHE STRING "Path to file containing the current temperature")
set(SETTING_PATH_TEMPERATURE_INFO "/sys/class/thermal/thermal_zone%zone%/temp"
CACHE STRING "Path to file containing the current temperature")
set(DEBUG_HINTS_OFFSET_X 0 CACHE INTEGER "Debug hint offset x")
set(DEBUG_HINTS_OFFSET_Y 0 CACHE INTEGER "Debug hint offset y")
# }}}

View File

@ -1,82 +0,0 @@
#
# Output build summary
#
function(colored_option message_level text var color_on color_off)
string(ASCII 27 esc)
if(${var})
message(${message_level} "${esc}[${color_on}m${text}${esc}[0m")
else()
message(${message_level} "${esc}[${color_off}m${text}${esc}[0m")
endif()
endfunction()
message(STATUS " Build:")
if(CMAKE_BUILD_TYPE)
message_colored(STATUS " Type: ${CMAKE_BUILD_TYPE}" "37;2")
else()
message_colored(STATUS " Type: NONE" "33;1")
endif()
string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)
if(CMAKE_BUILD_TYPE_LOWER STREQUAL "debug")
if(NOT DEFINED ${DEBUG_LOGGER})
set(DEBUG_LOGGER ON)
endif()
if(NOT DEFINED ${ENABLE_CCACHE})
set(ENABLE_CCACHE ON)
endif()
message_colored(STATUS " CC: ${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_DEBUG}" "37;2")
message_colored(STATUS " CXX: ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_DEBUG}" "37;2")
message_colored(STATUS " LD: ${CMAKE_LINKER} ${CMAKE_EXE_LINKER_FLAGS}${CMAKE_EXE_LINKER_FLAGS_DEBUG}" "37;2")
elseif(CMAKE_BUILD_TYPE_LOWER STREQUAL "release")
message_colored(STATUS " CC: ${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_RELEASE}" "37;2")
message_colored(STATUS " CXX: ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELEASE}" "37;2")
message_colored(STATUS " LD: ${CMAKE_LINKER} ${CMAKE_EXE_LINKER_FLAGS}${CMAKE_EXE_LINKER_FLAGS_RELEASE}" "37;2")
elseif(CMAKE_BUILD_TYPE_LOWER STREQUAL "sanitize")
message_colored(STATUS " CC: ${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_SANITIZE}" "37;2")
message_colored(STATUS " CXX: ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_SANITIZE}" "37;2")
message_colored(STATUS " LD: ${CMAKE_LINKER} ${CMAKE_EXE_LINKER_FLAGS}${CMAKE_EXE_LINKER_FLAGS_SANITIZE}" "37;2")
elseif(CMAKE_BUILD_TYPE_LOWER STREQUAL "minsizerel")
message_colored(STATUS " CC: ${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_MINSIZEREL}" "37;2")
message_colored(STATUS " CXX: ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_MINSIZEREL}" "37;2")
message_colored(STATUS " LD: ${CMAKE_LINKER} ${CMAKE_EXE_LINKER_FLAGS}${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL}" "37;2")
elseif(CMAKE_BUILD_TYPE_LOWER STREQUAL "relwithdebinfo")
message_colored(STATUS " CC: ${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_RELWITHDEBINFO}" "37;2")
message_colored(STATUS " CXX: ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_RELWITHDEBINFO}" "37;2")
message_colored(STATUS " LD: ${CMAKE_LINKER} ${CMAKE_EXE_LINKER_FLAGS}${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO}" "37;2")
endif()
if(CMAKE_EXE_LINKER_FLAGS)
message_colored(STATUS " LD: ${CMAKE_EXE_LINKER_FLAGS}" "37;2")
endif()
message(STATUS " Targets:")
colored_option(STATUS " polybar-msg" BUILD_IPC_MSG "32;1" "37;2")
colored_option(STATUS " testsuite" BUILD_TESTS "32;1" "37;2")
message(STATUS " Module supprt:")
colored_option(STATUS " alsa" ENABLE_ALSA "32;1" "37;2")
colored_option(STATUS " curl" ENABLE_CURL "32;1" "37;2")
colored_option(STATUS " i3" ENABLE_I3 "32;1" "37;2")
colored_option(STATUS " mpd" ENABLE_MPD "32;1" "37;2")
colored_option(STATUS " network" ENABLE_NETWORK "32;1" "37;2")
message(STATUS " X extensions:")
colored_option(STATUS " xcb-randr" WITH_XRANDR "32;1" "37;2")
colored_option(STATUS " xcb-randr (monitor support)" ENABLE_XRANDR_MONITORS "32;1" "37;2")
colored_option(STATUS " xcb-render" WITH_XRENDER "32;1" "37;2")
colored_option(STATUS " xcb-damage" WITH_XDAMAGE "32;1" "37;2")
colored_option(STATUS " xcb-sync" WITH_XSYNC "32;1" "37;2")
colored_option(STATUS " xcb-composite" WITH_XCOMPOSITE "32;1" "37;2")
colored_option(STATUS " xcb-xkb" WITH_XKB "32;1" "37;2")
colored_option(STATUS " xcb-xrm" WITH_XRM "32;1" "37;2")
if(CMAKE_BUILD_TYPE_LOWER STREQUAL "debug")
message(STATUS " Debug options:")
colored_option(STATUS " Trace logging" DEBUG_LOGGER "32;1" "37;2")
colored_option(STATUS " Trace logging (verbose)" DEBUG_LOGGER_VERBOSE "32;1" "37;2")
colored_option(STATUS " Draw clickable areas" DEBUG_HINTS "32;1" "37;2")
colored_option(STATUS " Print fc-match details" DEBUG_FONTCONFIG "32;1" "37;2")
colored_option(STATUS " Enable window shading" DEBUG_SHADED "32;1" "37;2")
message(STATUS "--------------------------")
endif()

View File

@ -2,7 +2,7 @@
# Collection of cmake utility functions
#
# message_colored : Outputs a colorized message {{{
# message_colored {{{
function(message_colored message_level text color)
string(ASCII 27 esc)
@ -10,17 +10,19 @@ function(message_colored message_level text color)
endfunction()
# }}}
# require_binary : Locates binary by name and exports its path to BINPATH_${name} {{{
# colored_option {{{
function(require_binary binary_name)
find_program(BINPATH_${binary_name} ${binary_name})
if(NOT BINPATH_${binary_name})
message_colored(FATAL_ERROR "Failed to locate ${binary_name} binary" 31)
function(colored_option text flag)
if(${flag})
message_colored(STATUS "${text}" "32;1")
else()
message_colored(STATUS "${text}" "37;2")
endif()
endfunction()
# }}}
# make_executable : Builds an executable target {{{
# make_executable {{{
function(make_executable target_name)
set(zero_value_args)
@ -45,8 +47,7 @@ function(make_executable target_name)
add_executable(${target_name} ${BIN_SOURCES})
# set the output file basename the same for static and shared
set_target_properties(${target_name}
PROPERTIES OUTPUT_NAME ${target_name})
set_target_properties(${target_name} PROPERTIES OUTPUT_NAME ${target_name})
# link libraries from pkg-config imports
foreach(DEP ${BIN_PKG_DEPENDS})
@ -57,24 +58,27 @@ function(make_executable target_name)
# link libraries from cmake imports
foreach(DEP ${BIN_CMAKE_DEPENDS})
string(TOUPPER ${DEP} DEP)
target_link_libraries(${target_name} ${${DEP}_LIB}
${${DEP}_LIBRARY}
${${DEP}_LIBRARIES})
target_link_libraries(${target_name}
${${DEP}_LIB}
${${DEP}_LIBRARY}
${${DEP}_LIBRARIES})
endforeach()
# link libraries that are build as part of this project
target_link_libraries(${target_name} ${BIN_TARGET_DEPENDS} ${BIN_RAW_DEPENDS})
target_link_libraries(${target_name}
${BIN_TARGET_DEPENDS}
${BIN_RAW_DEPENDS})
# install targets
install(TARGETS ${target_name}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT runtime)
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT runtime)
endfunction()
# }}}
# make_library : Builds a library target {{{
# make_library {{{
function(make_library target_name)
set(zero_value_args SHARED STATIC)
@ -112,7 +116,9 @@ function(make_library target_name)
foreach(library_target_name ${library_targets})
message(STATUS "${library_target_name}")
add_library(${library_target_name} ${LIB_HEADERS_ABS} ${LIB_SOURCES})
add_library(${library_target_name}
${LIB_HEADERS_ABS}
${LIB_SOURCES})
# link libraries from pkg-config imports
foreach(DEP ${LIB_PKG_DEPENDS})
@ -123,9 +129,10 @@ function(make_library target_name)
# link libraries from cmake imports
foreach(DEP ${LIB_CMAKE_DEPENDS})
string(TOUPPER ${DEP} DEP)
target_link_libraries(${library_target_name} ${${DEP}_LIB}
${${DEP}_LIBRARY}
${${DEP}_LIBRARIES})
target_link_libraries(${library_target_name}
${${DEP}_LIB}
${${DEP}_LIBRARY}
${${DEP}_LIBRARIES})
endforeach()
# link libraries that are build as part of this project
@ -153,17 +160,18 @@ function(make_library target_name)
# install targets
install(TARGETS ${LIBRARY_TARGETS}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT library)
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
COMPONENT library)
endforeach()
endfunction()
# }}}
# find_font : Query fontconfig fonts {{{
function(font_query output_variable fontname)
# queryfont {{{
function(queryfont output_variable fontname)
set(multi_value_args FIELDS)
cmake_parse_arguments(ARG "" "" "${multi_value_args}" ${ARGN})
@ -189,12 +197,12 @@ function(font_query output_variable fontname)
foreach(match LISTS ${output})
if(${match} MATCHES ".*${fontname}.*$")
list(APPEND FONT_QUERY_MATCHES ${match})
list(APPEND matches ${match})
endif()
endforeach()
if(FONT_QUERY_MATCHES)
list(GET FONT_QUERY_MATCHES 0 output_variable)
if(matches)
list(GET matches 0 output_variable)
set(output_variable "${output_variable}" PARENT_SCOPE)
message(STATUS "Found font: ${output_variable}")
else()
@ -203,3 +211,57 @@ function(font_query output_variable fontname)
endfunction()
# }}}
# querybin {{{
function(querybin binary_name)
find_program(BIN_${binary_name} ${binary_name})
if(NOT BIN_${binary_name})
message_colored(FATAL_ERROR "Failed to locate ${binary_name} binary" 31)
endif()
endfunction()
# }}}
# querylib {{{
function(querylib flag type pkg out_library out_include_dirs)
if(${flag})
if(${type} STREQUAL "cmake")
find_package(${pkg} REQUIRED)
string(TOUPPER ${pkg} pkg_upper)
list(APPEND ${out_library} ${${pkg_upper}_LIBRARY})
list(APPEND ${out_include_dirs} ${${pkg_upper}_INCLUDE_DIR})
elseif(${type} STREQUAL "pkg-config")
find_package(PkgConfig REQUIRED)
pkg_check_modules(PKG_${flag} REQUIRED ${pkg})
list(APPEND ${out_library} ${PKG_${flag}_LIBRARIES})
list(APPEND ${out_include_dirs} ${PKG_${flag}_INCLUDE_DIRS})
else()
message(FATAL_ERROR "Invalid lookup type '${type}'")
endif()
set(${out_library} ${${out_library}} PARENT_SCOPE)
set(${out_include_dirs} ${${out_include_dirs}} PARENT_SCOPE)
endif()
endfunction()
# }}}
# checklib {{{
function(checklib flag type pkg)
if(NOT DEFINED ${flag})
if(${type} STREQUAL "cmake")
find_package(${pkg} QUIET)
set(${flag} ${${pkg}_FOUND} CACHE BOOL "")
elseif(${type} STREQUAL "pkg-config")
find_package(PkgConfig REQUIRED)
pkg_check_modules(PKG_${flag} QUIET ${pkg})
set(${flag} ${PKG_${flag}_FOUND} CACHE BOOL "")
elseif(${type} STREQUAL "binary")
find_program(BIN_${flag} ${pkg})
set(${flag} ${BIN_${flag}} CACHE BOOL "")
else()
message(FATAL_ERROR "Invalid lookup type '${type}'")
endif()
endif()
endfunction()
# }}}

View File

@ -1,31 +0,0 @@
# - Try to find LibMPDClient
# Once done, this will define
#
# LIBMPDCLIENT_FOUND - System has LibMPDClient
# LIBMPDCLIENT_INCLUDE_DIRS - The LibMPDClient include directories
# LIBMPDCLIENT_LIBRARIES - The libraries needed to use LibMPDClient
# LIBMPDCLIENT_DEFINITIONS - Compiler switches required for using LibMPDClient
find_package(PkgConfig)
pkg_check_modules(PC_LIBMPDCLIENT QUIET libmpdclient)
set(LIBMPDCLIENT_DEFINITIONS ${PC_LIBMPDCLIENT_CFLAGS_OTHER})
find_path(LIBMPDCLIENT_INCLUDE_DIR
NAMES mpd/player.h
HINTS ${PC_LIBMPDCLIENT_INCLUDEDIR} ${PC_LIBMPDCLIENT_INCLUDE_DIRS}
)
find_library(LIBMPDCLIENT_LIBRARY
NAMES mpdclient
HINTS ${PC_LIBMPDCLIENT_LIBDIR} ${PC_LIBMPDCLIENT_LIBRARY_DIRS}
)
set(LIBMPDCLIENT_LIBRARIES ${LIBMPDCLIENT_LIBRARY})
set(LIBMPDCLIENT_INCLUDE_DIRS ${LIBMPDCLIENT_INCLUDE_DIR})
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LibMPDClient DEFAULT_MSG
LIBMPDCLIENT_LIBRARY LIBMPDCLIENT_INCLUDE_DIR
)
mark_as_advanced(LIBMPDCLIENT_LIBRARY LIBMPDCLIENT_INCLUDE_DIR)

View File

@ -1,250 +0,0 @@
# Try to find XCB on a Unix system
#
# This will define:
#
# XCB_FOUND - True if xcb is available
# XCB_LIBRARIES - Link these to use xcb
# XCB_INCLUDE_DIRS - Include directory for xcb
# XCB_DEFINITIONS - Compiler flags for using xcb
#
# In addition the following more fine grained variables will be defined:
#
# XCB_XCB_FOUND XCB_XCB_INCLUDE_DIR XCB_XCB_LIBRARY
# XCB_UTIL_FOUND XCB_UTIL_INCLUDE_DIR XCB_UTIL_LIBRARY
# XCB_COMPOSITE_FOUND XCB_COMPOSITE_INCLUDE_DIR XCB_COMPOSITE_LIBRARY
# XCB_DAMAGE_FOUND XCB_DAMAGE_INCLUDE_DIR XCB_DAMAGE_LIBRARY
# XCB_XFIXES_FOUND XCB_XFIXES_INCLUDE_DIR XCB_XFIXES_LIBRARY
# XCB_RENDER_FOUND XCB_RENDER_INCLUDE_DIR XCB_RENDER_LIBRARY
# XCB_RANDR_FOUND XCB_RANDR_INCLUDE_DIR XCB_RANDR_LIBRARY
# XCB_SHAPE_FOUND XCB_SHAPE_INCLUDE_DIR XCB_SHAPE_LIBRARY
# XCB_DRI2_FOUND XCB_DRI2_INCLUDE_DIR XCB_DRI2_LIBRARY
# XCB_GLX_FOUND XCB_GLX_INCLUDE_DIR XCB_GLX_LIBRARY
# XCB_SHM_FOUND XCB_SHM_INCLUDE_DIR XCB_SHM_LIBRARY
# XCB_XV_FOUND XCB_XV_INCLUDE_DIR XCB_XV_LIBRARY
# XCB_SYNC_FOUND XCB_SYNC_INCLUDE_DIR XCB_SYNC_LIBRARY
# XCB_XTEST_FOUND XCB_XTEST_INCLUDE_DIR XCB_XTEST_LIBRARY
# XCB_ICCCM_FOUND XCB_ICCCM_INCLUDE_DIR XCB_ICCCM_LIBRARY
# XCB_EWMH_FOUND XCB_EWMH_INCLUDE_DIR XCB_EWMH_LIBRARY
# XCB_IMAGE_FOUND XCB_IMAGE_INCLUDE_DIR XCB_IMAGE_LIBRARY
# XCB_RENDERUTIL_FOUND XCB_RENDERUTIL_INCLUDE_DIR XCB_RENDERUTIL_LIBRARY
# XCB_KEYSYMS_FOUND XCB_KEYSYMS_INCLUDE_DIR XCB_KEYSYMS_LIBRARY
#
# Copyright (c) 2011 Fredrik Höglund <fredrik@kde.org>
# Copyright (c) 2013 Martin Gräßlin <mgraesslin@kde.org>
#
# Redistribution and use is allowed according to the terms of the BSD license.
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
set(knownComponents XCB
COMPOSITE
DAMAGE
DRI2
EWMH
GLX
ICCCM
IMAGE
KEYSYMS
RANDR
RENDER
RENDERUTIL
SHAPE
SHM
SYNC
UTIL
XFIXES
XTEST
XV
XINERAMA
XKB)
unset(unknownComponents)
set(pkgConfigModules)
set(requiredComponents)
if (XCB_FIND_COMPONENTS)
set(comps ${XCB_FIND_COMPONENTS})
else()
set(comps ${knownComponents})
endif()
# iterate through the list of requested components, and check that we know them all.
# If not, fail.
foreach(comp ${comps})
list(FIND knownComponents ${comp} index )
if("${index}" STREQUAL "-1")
list(APPEND unknownComponents "${comp}")
else()
if("${comp}" STREQUAL "XCB")
list(APPEND pkgConfigModules "xcb")
elseif("${comp}" STREQUAL "COMPOSITE")
list(APPEND pkgConfigModules "xcb-composite")
elseif("${comp}" STREQUAL "DAMAGE")
list(APPEND pkgConfigModules "xcb-damage")
elseif("${comp}" STREQUAL "DRI2")
list(APPEND pkgConfigModules "xcb-dri2")
elseif("${comp}" STREQUAL "EWMH")
list(APPEND pkgConfigModules "xcb-ewmh")
elseif("${comp}" STREQUAL "GLX")
list(APPEND pkgConfigModules "xcb-glx")
elseif("${comp}" STREQUAL "ICCCM")
list(APPEND pkgConfigModules "xcb-icccm")
elseif("${comp}" STREQUAL "IMAGE")
list(APPEND pkgConfigModules "xcb-image")
elseif("${comp}" STREQUAL "KEYSYMS")
list(APPEND pkgConfigModules "xcb-keysyms")
elseif("${comp}" STREQUAL "RANDR")
list(APPEND pkgConfigModules "xcb-randr")
elseif("${comp}" STREQUAL "RENDER")
list(APPEND pkgConfigModules "xcb-render")
elseif("${comp}" STREQUAL "RENDERUTIL")
list(APPEND pkgConfigModules "xcb-renderutil")
elseif("${comp}" STREQUAL "SHAPE")
list(APPEND pkgConfigModules "xcb-shape")
elseif("${comp}" STREQUAL "SHM")
list(APPEND pkgConfigModules "xcb-shm")
elseif("${comp}" STREQUAL "SYNC")
list(APPEND pkgConfigModules "xcb-sync")
elseif("${comp}" STREQUAL "UTIL")
list(APPEND pkgConfigModules "xcb-util")
elseif("${comp}" STREQUAL "XFIXES")
list(APPEND pkgConfigModules "xcb-xfixes")
elseif("${comp}" STREQUAL "XTEST")
list(APPEND pkgConfigModules "xcb-xtest")
elseif("${comp}" STREQUAL "XV")
list(APPEND pkgConfigModules "xcb-xv")
elseif("${comp}" STREQUAL "XINERAMA")
list(APPEND pkgConfigModules "xcb-xinerama")
elseif("${comp}" STREQUAL "XKB")
list(APPEND pkgConfigModules "xcb-xkb")
endif()
endif()
endforeach()
if(DEFINED unknownComponents)
set(msgType STATUS)
if(XCB_FIND_REQUIRED)
set(msgType FATAL_ERROR)
endif()
if(NOT XCB_FIND_QUIETLY)
message(${msgType} "XCB: requested unknown components ${unknownComponents}")
endif()
return()
endif()
macro(_XCB_HANDLE_COMPONENT _comp)
set(_header )
set(_lib )
if("${_comp}" STREQUAL "XCB")
set(_header "xcb/xcb.h")
set(_lib "xcb")
elseif("${_comp}" STREQUAL "COMPOSITE")
set(_header "xcb/composite.h")
set(_lib "xcb-composite")
elseif("${_comp}" STREQUAL "DAMAGE")
set(_header "xcb/damage.h")
set(_lib "xcb-damage")
elseif("${_comp}" STREQUAL "DRI2")
set(_header "xcb/dri2.h")
set(_lib "xcb-dri2")
elseif("${_comp}" STREQUAL "EWMH")
set(_header "xcb/xcb_ewmh.h")
set(_lib "xcb-ewmh")
elseif("${_comp}" STREQUAL "GLX")
set(_header "xcb/glx.h")
set(_lib "xcb-glx")
elseif("${_comp}" STREQUAL "ICCCM")
set(_header "xcb/xcb_icccm.h")
set(_lib "xcb-icccm")
elseif("${_comp}" STREQUAL "IMAGE")
set(_header "xcb/xcb_image.h")
set(_lib "xcb-image")
elseif("${_comp}" STREQUAL "KEYSYMS")
set(_header "xcb/xcb_keysyms.h")
set(_lib "xcb-keysyms")
elseif("${_comp}" STREQUAL "RANDR")
set(_header "xcb/randr.h")
set(_lib "xcb-randr")
elseif("${_comp}" STREQUAL "RENDER")
set(_header "xcb/render.h")
set(_lib "xcb-render")
elseif("${_comp}" STREQUAL "RENDERUTIL")
set(_header "xcb/xcb_renderutil.h")
set(_lib "xcb-render-util")
elseif("${_comp}" STREQUAL "SHAPE")
set(_header "xcb/shape.h")
set(_lib "xcb-shape")
elseif("${_comp}" STREQUAL "SHM")
set(_header "xcb/shm.h")
set(_lib "xcb-shm")
elseif("${_comp}" STREQUAL "SYNC")
set(_header "xcb/sync.h")
set(_lib "xcb-sync")
elseif("${_comp}" STREQUAL "UTIL")
set(_header "xcb/xcb_util.h")
set(_lib "xcb-util")
elseif("${_comp}" STREQUAL "XFIXES")
set(_header "xcb/xfixes.h")
set(_lib "xcb-xfixes")
elseif("${_comp}" STREQUAL "XTEST")
set(_header "xcb/xtest.h")
set(_lib "xcb-xtest")
elseif("${_comp}" STREQUAL "XV")
set(_header "xcb/xv.h")
set(_lib "xcb-xv")
elseif("${_comp}" STREQUAL "XINERAMA")
set(_header "xcb/xinerama.h")
set(_lib "xcb-xinerama")
elseif("${_comp}" STREQUAL "XKB")
set(_header "xcb/xkb.h")
set(_lib "xcb-xkb")
endif()
find_path(XCB_${_comp}_INCLUDE_DIR NAMES ${_header} HINTS ${PKG_XCB_INCLUDE_DIRS})
find_library(XCB_${_comp}_LIBRARY NAMES ${_lib} HINTS ${PKG_XCB_LIBRARY_DIRS})
if(XCB_${_comp}_INCLUDE_DIR AND XCB_${_comp}_LIBRARY)
list(APPEND XCB_INCLUDE_DIRS ${XCB_${_comp}_INCLUDE_DIR})
list(APPEND XCB_LIBRARIES ${XCB_${_comp}_LIBRARY})
if (NOT XCB_FIND_QUIETLY)
message(STATUS "XCB[${_comp}]: Found component ${_comp}")
endif()
endif()
if(XCB_FIND_REQUIRED_${_comp})
list(APPEND requiredComponents XCB_${_comp}_FOUND)
endif()
find_package_handle_standard_args(XCB_${_comp} DEFAULT_MSG XCB_${_comp}_LIBRARY XCB_${_comp}_INCLUDE_DIR)
mark_as_advanced(XCB_${_comp}_LIBRARY XCB_${_comp}_INCLUDE_DIR)
# compatibility for old variable naming
set(XCB_${_comp}_INCLUDE_DIRS ${XCB_${_comp}_INCLUDE_DIR})
set(XCB_${_comp}_LIBRARIES ${XCB_${_comp}_LIBRARY})
endmacro()
IF (NOT WIN32)
include(FindPackageHandleStandardArgs)
# Use pkg-config to get the directories and then use these values
# in the FIND_PATH() and FIND_LIBRARY() calls
find_package(PkgConfig)
pkg_check_modules(PKG_XCB QUIET ${pkgConfigModules})
set(XCB_DEFINITIONS ${PKG_XCB_CFLAGS})
foreach(comp ${comps})
_xcb_handle_component(${comp})
endforeach()
if(XCB_INCLUDE_DIRS)
list(REMOVE_DUPLICATES XCB_INCLUDE_DIRS)
endif()
find_package_handle_standard_args(XCB DEFAULT_MSG XCB_LIBRARIES XCB_INCLUDE_DIRS ${requiredComponents})
# compatibility for old variable naming
set(XCB_INCLUDE_DIR ${XCB_INCLUDE_DIRS})
ENDIF (NOT WIN32)

View File

@ -4,15 +4,15 @@
set(MODULES_LEFT "bspwm i3")
set(MODULES_CENTER "mpd")
set(MODULES_RIGHT "xbacklight volume xkeyboard memory cpu wlan eth battery temperature date powermenu")
set(MODULES_RIGHT "filesystem xbacklight volume xkeyboard memory cpu wlan eth battery temperature date powermenu")
set(FONT_FIXED "fixed:pixelsize=10")
set(FONT_UNIFONT "unifont:fontformat=truetype")
set(FONT_SIJI "siji:pixelsize=10")
font_query(FONT_FIXED "${FONT_FIXED}" FIELDS family pixelsize)
font_query(FONT_UNIFONT "${FONT_UNIFONT}" FIELDS family fontformat)
font_query(FONT_SIJI "${FONT_SIJI}" FIELDS family pixelsize)
queryfont(FONT_FIXED ${FONT_FIXED} FIELDS family pixelsize)
queryfont(FONT_UNIFONT ${FONT_UNIFONT} FIELDS family fontformat)
queryfont(FONT_SIJI ${FONT_SIJI} FIELDS family pixelsize)
# Strip disabled modules {{{

View File

@ -91,12 +91,9 @@ type = internal/fs
interval = 25
mount-0 = /
mount-1 = /home
mount-2 = /invalid/mountpoint
label-mounted = %mountpoint%: %percentage_free%%
label-unmounted = %mountpoint%: not mounted
label-mounted = %{F#0a81f5}%mountpoint%%{F-}: %percentage_used%%
label-unmounted = %mountpoint% not mounted
label-unmounted-foreground = ${colors.foreground-alt}
[module/bspwm]

38
include/CMakeLists.txt Normal file
View File

@ -0,0 +1,38 @@
#
# Generate settings.hpp
#
list(APPEND dirs ${CMAKE_CURRENT_LIST_DIR})
if(WITH_XRANDR)
list(APPEND XPP_EXTENSION_LIST xpp::randr::extension)
endif()
if(WITH_XRENDER)
list(APPEND XPP_EXTENSION_LIST xpp::render::extension)
endif()
if(WITH_XDAMAGE)
list(APPEND XPP_EXTENSION_LIST xpp::damage::extension)
endif()
if(WITH_XSYNC)
list(APPEND XPP_EXTENSION_LIST xpp::sync::extension)
endif()
if(WITH_XCOMPOSITE)
list(APPEND XPP_EXTENSION_LIST xpp::composite::extension)
endif()
if(WITH_XKB)
list(APPEND XPP_EXTENSION_LIST xpp::xkb::extension)
endif()
string(REPLACE ";" ", " XPP_EXTENSION_LIST "${XPP_EXTENSION_LIST}")
execute_process(COMMAND git describe --tags --dirty=-git
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE APP_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
configure_file(
settings.hpp.cmake
settings.hpp
ESCAPE_QUOTES @ONLY)
set(libs ${libs} PARENT_SCOPE)
set(dirs ${dirs} PARENT_SCOPE)

View File

@ -9,7 +9,7 @@
#include "utils/env.hpp"
#include "utils/file.hpp"
#include "utils/string.hpp"
#ifdef WITH_XRM
#if WITH_XRM
#include "x11/xresources.hpp"
#endif
@ -284,12 +284,12 @@ class config {
template <typename T>
T dereference_xrdb(string var) const {
size_t pos;
#ifndef WITH_XRM
#if not WITH_XRM
m_log.warn("No built-in support for xrdb (requires xcb-util-xrm). Using default value for `%s`", var);
if ((pos = var.find(":")) != string::npos) {
return var.substr(pos + 1);
return convert<T>(var.substr(pos + 1));
}
return fallback;
return convert<T>("");
#else
if (!m_xrm) {
throw application_error("xrm is not initialized");
@ -346,7 +346,7 @@ class config {
string m_file;
string m_barname;
sectionmap_t m_sections{};
#ifdef WITH_XRM
#if WITH_XRM
unique_ptr<xresource_manager> m_xrm;
#endif
};

View File

@ -28,13 +28,13 @@
#cmakedefine01 WITH_XRM
#if WITH_XRANDR
#cmakedefine01 ENABLE_XRANDR_MONITORS
#cmakedefine01 WITH_XRANDR_MONITORS
#else
#define ENABLE_XRANDR_MONITORS 0
#define WITH_XRANDR_MONITORS 0
#endif
#if WITH_XKB
#define ENABLE_XKEYBOARD 1
#cmakedefine01 ENABLE_XKEYBOARD
#else
#define ENABLE_XKEYBOARD 0
#endif
@ -104,7 +104,7 @@ const auto print_build_info = [](bool extended = false) {
printf("\n");
printf("X extensions: %crandr (%cmonitors) %crender %cdamage %csync %ccomposite %cxkb %cxrm\n",
(WITH_XRANDR ? '+' : '-'),
(ENABLE_XRANDR_MONITORS ? '+' : '-'),
(WITH_XRANDR_MONITORS ? '+' : '-'),
(WITH_XRENDER ? '+' : '-'),
(WITH_XDAMAGE ? '+' : '-'),
(WITH_XSYNC ? '+' : '-'),

47
lib/CMakeLists.txt Normal file
View File

@ -0,0 +1,47 @@
#
# Configure libs
#
# Library: concurrentqueue {{{
list(APPEND dirs ${CMAKE_CURRENT_LIST_DIR}/concurrentqueue/include)
# }}}
# Library: xpp {{{
if(WITH_XRANDR)
list(APPEND XCB_PROTOS randr)
endif()
if(WITH_XRENDER)
list(APPEND XCB_PROTOS render)
endif()
if(WITH_XDAMAGE)
list(APPEND XCB_PROTOS damage)
endif()
if(WITH_XSYNC)
list(APPEND XCB_PROTOS sync)
endif()
if(WITH_XCOMPOSITE)
list(APPEND XCB_PROTOS composite)
endif()
if(WITH_XKB)
list(APPEND XCB_PROTOS xkb)
endif()
add_subdirectory(xpp)
list(APPEND libs ${XPP_LIBRARIES})
list(APPEND dirs ${XPP_INCLUDE_DIRS})
# }}}
# Library: i3ipcpp {{{
if(ENABLE_I3)
add_subdirectory(i3ipcpp)
list(APPEND libs ${I3IPCPP_LIBRARIES})
list(APPEND dirs ${I3IPCPP_INCLUDE_DIRS})
endif()
# }}}
set(libs ${libs} PARENT_SCOPE)
set(dirs ${dirs} PARENT_SCOPE)

View File

@ -1,171 +1,83 @@
#
# Create executable
# Configure src
#
file(GLOB_RECURSE SOURCES RELATIVE ${PROJECT_SOURCE_DIR}/src *.c[p]*)
list(REMOVE_ITEM SOURCES ipc.cpp)
# Source tree {{{
# Locate dependencies {{{
file(GLOB_RECURSE files RELATIVE ${CMAKE_CURRENT_LIST_DIR} *.c[p]*)
list(REMOVE_ITEM files ipc.cpp)
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(PkgConfig)
find_package(Threads REQUIRED)
pkg_check_modules(CAIRO REQUIRED cairo-fc)
set(APP_LIBRARIES ${APP_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT})
set(APP_LIBRARIES ${APP_LIBRARIES} ${CAIRO_LIBRARIES})
set(APP_INCLUDE_DIRS ${APP_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/include)
set(APP_INCLUDE_DIRS ${APP_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/lib/concurrentqueue/include)
set(APP_INCLUDE_DIRS ${APP_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR})
set(APP_INCLUDE_DIRS ${APP_INCLUDE_DIRS} ${CAIRO_INCLUDE_DIRS})
# xpp library
set(XCB_PROTOS xproto)
if(WITH_XRANDR)
if(ENABLE_XRANDR_MONITORS)
pkg_check_modules(XRANDR REQUIRED xrandr>=1.5.0 randrproto>=1.5.0 xcb-proto>=1.12)
endif()
set(XCB_PROTOS "${XCB_PROTOS}" randr)
set(XPP_EXTENSION_LIST ${XPP_EXTENSION_LIST} xpp::randr::extension)
else()
list(REMOVE_ITEM SOURCES x11/extensions/randr.cpp)
if(NOT ENABLE_ALSA)
list(REMOVE_ITEM files modules/volume.cpp)
list(REMOVE_ITEM files adapters/alsa/control.cpp)
list(REMOVE_ITEM files adapters/alsa/mixer.cpp)
endif()
if(WITH_XRENDER)
set(XCB_PROTOS "${XCB_PROTOS}" render)
set(XPP_EXTENSION_LIST ${XPP_EXTENSION_LIST} xpp::render::extension)
else()
list(REMOVE_ITEM SOURCES x11/extensions/render.cpp)
if(NOT ENABLE_CURL)
list(REMOVE_ITEM files modules/github.cpp)
list(REMOVE_ITEM files utils/http.cpp)
endif()
if(WITH_XDAMAGE)
set(XCB_PROTOS "${XCB_PROTOS}" damage)
set(XPP_EXTENSION_LIST ${XPP_EXTENSION_LIST} xpp::damage::extension)
else()
list(REMOVE_ITEM SOURCES x11/extensions/damage.cpp)
if(NOT ENABLE_MPD)
list(REMOVE_ITEM files modules/mpd.cpp)
list(REMOVE_ITEM files adapters/mpd.cpp)
endif()
if(WITH_XSYNC)
set(XCB_PROTOS "${XCB_PROTOS}" sync)
set(XPP_EXTENSION_LIST ${XPP_EXTENSION_LIST} xpp::sync::extension)
else()
list(REMOVE_ITEM SOURCES x11/extensions/sync.cpp)
if(NOT ENABLE_NETWORK)
list(REMOVE_ITEM files modules/network.cpp)
list(REMOVE_ITEM files adapters/net.cpp)
endif()
if(WITH_XCOMPOSITE)
set(XCB_PROTOS "${XCB_PROTOS}" composite)
set(XPP_EXTENSION_LIST ${XPP_EXTENSION_LIST} xpp::composite::extension)
else()
list(REMOVE_ITEM SOURCES x11/extensions/composite.cpp)
if(NOT ENABLE_I3)
list(REMOVE_ITEM files modules/i3.cpp)
list(REMOVE_ITEM files utils/i3.cpp)
endif()
if(WITH_XKB)
set(XCB_PROTOS "${XCB_PROTOS}" xkb)
set(XPP_EXTENSION_LIST ${XPP_EXTENSION_LIST} xpp::xkb::extension)
else()
list(REMOVE_ITEM SOURCES x11/extensions/xkb.cpp modules/xkeyboard.cpp)
if(NOT WITH_XRANDR)
list(REMOVE_ITEM files x11/extensions/randr.cpp)
endif()
if(WITH_XRM)
pkg_check_modules(XCB_UTIL_XRM REQUIRED xcb-xrm)
set(APP_LIBRARIES ${APP_LIBRARIES} ${XCB_UTIL_XRM_LIBRARIES})
set(APP_INCLUDE_DIRS ${APP_INCLUDE_DIRS} ${XCB_UTIL_XRM_INCLUDE_DIRS})
if(NOT WITH_XRENDER)
list(REMOVE_ITEM files x11/extensions/render.cpp)
endif()
string(REPLACE ";" ", " XPP_EXTENSION_LIST "${XPP_EXTENSION_LIST}")
add_subdirectory(${PROJECT_SOURCE_DIR}/lib/xpp ${PROJECT_BINARY_DIR}/lib/xpp)
set(APP_LIBRARIES ${APP_LIBRARIES} ${XPP_LIBRARIES})
set(APP_INCLUDE_DIRS ${APP_INCLUDE_DIRS} ${XPP_INCLUDE_DIRS})
# }}}
# Optional dependency: alsalib {{{
if(ENABLE_ALSA)
find_package(ALSA REQUIRED)
set(APP_LIBRARIES ${APP_LIBRARIES} ${ALSA_LIBRARY})
set(APP_INCLUDE_DIRS ${APP_INCLUDE_DIRS} ${ALSA_INCLUDE_DIR})
else()
list(REMOVE_ITEM SOURCES adapters/alsa/mixer.cpp adapters/alsa/control.cpp modules/volume.cpp)
if(NOT WITH_XDAMAGE)
list(REMOVE_ITEM files x11/extensions/damage.cpp)
endif()
# }}}
# Optional dependency: libmpdclient {{{
if(ENABLE_MPD)
find_package(LibMPDClient REQUIRED)
set(APP_LIBRARIES ${APP_LIBRARIES} ${LIBMPDCLIENT_LIBRARY})
set(APP_INCLUDE_DIRS ${APP_INCLUDE_DIRS} ${LIBMPDCLIENT_INCLUDE_DIR})
else()
list(REMOVE_ITEM SOURCES adapters/mpd.cpp modules/mpd.cpp)
if(NOT WITH_XSYNC)
list(REMOVE_ITEM files x11/extensions/sync.cpp)
endif()
# }}}
# Optional dependency: libiw {{{
if(ENABLE_NETWORK)
find_package(Libiw REQUIRED)
set(APP_LIBRARIES ${APP_LIBRARIES} ${LIBIW_LIBRARY})
set(APP_INCLUDE_DIRS ${APP_INCLUDE_DIRS} ${LIBIW_INCLUDE_DIR})
else()
list(REMOVE_ITEM SOURCES adapters/net.cpp modules/network.cpp)
if(NOT WITH_XCOMPOSITE)
list(REMOVE_ITEM files x11/extensions/composite.cpp)
endif()
# }}}
# Optional dependency: i3ipcpp {{{
if(ENABLE_I3)
add_subdirectory(${PROJECT_SOURCE_DIR}/lib/i3ipcpp ${PROJECT_BINARY_DIR}/lib/i3ipcpp)
set(APP_LIBRARIES ${APP_LIBRARIES} ${I3IPCPP_LIBRARIES})
set(APP_INCLUDE_DIRS ${APP_INCLUDE_DIRS} ${I3IPCPP_INCLUDE_DIRS})
else()
list(REMOVE_ITEM SOURCES modules/i3.cpp utils/i3.cpp)
if(NOT WITH_XKB)
list(REMOVE_ITEM files x11/extensions/xkb.cpp)
endif()
# }}}
# Optional dependency: libcurl {{{
if(ENABLE_CURL)
find_package(CURL REQUIRED)
set(APP_LIBRARIES ${APP_LIBRARIES} ${CURL_LIBRARY})
set(APP_INCLUDE_DIRS ${APP_INCLUDE_DIRS} ${CURL_INCLUDE_DIR})
else()
list(REMOVE_ITEM SOURCES utils/http.cpp modules/github.cpp)
if(NOT WITH_XRM)
list(REMOVE_ITEM files x11/xresources.cpp)
endif()
# }}}
# Create executable target {{{
# Target: polybar {{{
make_executable(${PROJECT_NAME} SOURCES
${SOURCES}
make_executable(polybar
SOURCES
${files}
INCLUDE_DIRS
${APP_INCLUDE_DIRS}
${dirs}
RAW_DEPENDS
${APP_LIBRARIES})
${libs}
Threads::Threads)
target_link_libraries(${PROJECT_NAME} Threads::Threads)
target_compile_options(${PROJECT_NAME} PUBLIC
$<$<CXX_COMPILER_ID:GNU>:$<$<CONFIG:MinSizeRel>:-flto>>)
target_compile_options(polybar PUBLIC $<$<CXX_COMPILER_ID:GNU>:$<$<CONFIG:MinSizeRel>:-flto>>)
# }}}
# Create executable target: ipc messager {{{
# Target: polybar-msg {{{
if(BUILD_IPC_MSG)
make_executable(${PROJECT_NAME}-msg SOURCES ipc.cpp utils/env.cpp utils/file.cpp)
target_compile_options(${PROJECT_NAME}-msg PUBLIC
$<$<CXX_COMPILER_ID:GNU>:$<$<CONFIG:MinSizeRel>:-flto>>)
make_executable(polybar-msg
SOURCES
ipc.cpp
utils/env.cpp
utils/file.cpp)
target_compile_options(polybar-msg PUBLIC $<$<CXX_COMPILER_ID:GNU>:$<$<CONFIG:MinSizeRel>:-flto>>)
endif()
# }}}
set(APP_BINARY ${PROJECT_SOURCE_DIR}/bin/${PROJECT_NAME} PARENT_SCOPE)
set(APP_LIBRARIES ${APP_LIBRARIES} PARENT_SCOPE)
set(APP_INCLUDE_DIRS ${APP_INCLUDE_DIRS} PARENT_SCOPE)
execute_process(COMMAND git describe --tags --dirty=-git
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE APP_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET)
configure_file(
${PROJECT_SOURCE_DIR}/include/settings.hpp.cmake
${CMAKE_SOURCE_DIR}/include/settings.hpp
ESCAPE_QUOTES @ONLY)
set(libs ${libs} PARENT_SCOPE)
set(dirs ${dirs} PARENT_SCOPE)

View File

@ -123,7 +123,7 @@ void config::parse_file() {
}
}
#ifdef WITH_XRM
#if WITH_XRM
// Initialize the xresource manage if there are any xrdb refs
// present in the configuration
if (!m_xrm && value.find("${xrdb") != string::npos) {

View File

@ -79,7 +79,7 @@ int main(int argc, char** argv) {
//==================================================
if (cli->has("list-monitors")) {
for (auto&& mon : randr_util::get_monitors(conn, conn.root(), true)) {
if (ENABLE_XRANDR_MONITORS && mon->output == XCB_NONE) {
if (WITH_XRANDR_MONITORS && mon->output == XCB_NONE) {
printf("%s: %ix%i+%i+%i (XRandR monitor)\n", mon->name.c_str(), mon->w, mon->h, mon->x, mon->y);
} else {
printf("%s: %ix%i+%i+%i\n", mon->name.c_str(), mon->w, mon->h, mon->x, mon->y);

View File

@ -55,7 +55,7 @@ namespace randr_util {
* Check for XRandR monitor support
*/
bool check_monitor_support() {
return ENABLE_XRANDR_MONITORS && g_major_version >= 1 && g_minor_version >= 5;
return WITH_XRANDR_MONITORS && g_major_version >= 1 && g_minor_version >= 5;
}
/**
@ -85,7 +85,7 @@ namespace randr_util {
return monitors;
}
#if ENABLE_XRANDR_MONITORS
#if WITH_XRANDR_MONITORS
if (check_monitor_support()) {
for (auto&& mon : conn.get_monitors(root, true).monitors()) {
try {
@ -110,7 +110,7 @@ namespace randr_util {
auto name_iter = info.name();
string name{name_iter.begin(), name_iter.end()};
#if ENABLE_XRANDR_MONITORS
#if WITH_XRANDR_MONITORS
if (check_monitor_support()) {
auto mon = std::find_if(
monitors.begin(), monitors.end(), [&name](const monitor_t& mon) { return mon->name == name; });

View File

@ -9,15 +9,12 @@
#include "utils/math.hpp"
#include "utils/memory.hpp"
#include "utils/process.hpp"
#include "x11/atoms.hpp"
#include "x11/connection.hpp"
#include "x11/ewmh.hpp"
#include "x11/icccm.hpp"
#include "x11/tray_manager.hpp"
#include "x11/window.hpp"
#include "x11/winspec.hpp"
#include "x11/xembed.hpp"
#include "x11/xresources.hpp"
// ====================================================================================================
//

View File

@ -3,25 +3,22 @@
#
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -include common/test.hpp")
include_directories(
${APP_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}/src
${CMAKE_CURRENT_LIST_DIR}
${CMAKE_CURRENT_BINARY_DIR})
link_libraries(${APP_LIBRARIES})
link_libraries(${libs})
include_directories(${dirs})
include_directories(${PROJECT_SOURCE_DIR}/src)
include_directories(${CMAKE_CURRENT_LIST_DIR})
function(unit_test file)
string(REPLACE "/" "_" testname ${file})
add_executable(unit_test.${testname} ${CMAKE_CURRENT_LIST_DIR}/unit_tests/${file}.cpp ${SOURCE_DEPS})
add_executable(unit_test.${testname} unit_tests/${file}.cpp)
add_test(unit_test.${testname} unit_test.${testname})
endfunction()
unit_test("utils/color")
unit_test("utils/math")
unit_test("utils/memory")
unit_test("utils/string")
unit_test("components/command_line")
#unit_test("x11/color")
unit_test(utils/color)
unit_test(utils/math)
unit_test(utils/memory)
unit_test(utils/string)
unit_test(components/command_line)
# XXX: Requires mocked xcb connection
#unit_test("x11/connection")

View File

@ -1,50 +0,0 @@
#include <csignal>
#include "utils/color.hpp"
#include "x11/color.cpp"
int main() {
using namespace polybar;
"color"_test = [] {
color test{"#33990022"};
expect(color_util::hex<unsigned char>(test) == "#1E0006");
expect(color_util::hex<unsigned short int>(test) == "#33990022");
};
"channels"_test = [] {
color test{"#eefb9281"};
expect(color_util::alpha_channel<unsigned char>(test) == 0xee);
expect(color_util::red_channel<unsigned char>(test) == 0xfb);
expect(color_util::green_channel<unsigned char>(test) == 0x92);
expect(color_util::blue_channel<unsigned char>(test) == 0x81);
};
"base"_test = [] {
color test{"#eefb9281"};
auto hex = color_util::hex<unsigned char>(test);
expect(std::strtoul(&hex[0], 0, 16) == 0x0);
};
"cache"_test = [] {
expect(g_colorstore.size() == size_t{0});
auto c1 = color::parse("#100");
expect(g_colorstore.size() == size_t{1});
auto c2 = color::parse("#200");
expect(g_colorstore.size() == size_t{2});
auto c3 = color::parse("#200");
expect(g_colorstore.size() == size_t{2});
expect((unsigned int)g_colorstore.find("#100")->second == (unsigned int)c1);
};
"predefined"_test = [] {
expect(color_util::hex<unsigned short int>(g_colorblack) == "#FF000000");
expect(color_util::hex<unsigned short int>(g_colorwhite) == "#FFFFFFFF");
};
"parse"_test = [] {
expect(color_util::hex<unsigned short int>(color::parse("#ff9900", g_colorblack)) == "#FFFF9900");
expect(color_util::hex<unsigned short int>(color::parse("invalid", g_colorwhite)) == "#FFFFFFFF");
expect(color_util::hex<unsigned char>(color::parse("33990022", g_colorwhite)) == "#1E0006");
};
}