refactor(cmake): Allow targets to be enabled individually

Each major target of polybar can now be enabled/disabled while
configuring (even polybar itself).

The cmake code specific to each target will only run if the target is
enabled.

This allows us to for example just build the documentation without
having to run all the cmake code related to compilation or having the
polybar dependencies installed (other than sphinx).
This commit is contained in:
patrick96 2020-12-22 03:43:06 +01:00 committed by Patrick Ziegler
parent 771154742c
commit c24a6999a4
14 changed files with 357 additions and 327 deletions

View File

@ -21,9 +21,9 @@ jobs:
run: sudo apt-get install -y python3-sphinx run: sudo apt-get install -y python3-sphinx
- name: Build Documentation - name: Build Documentation
run: | run: |
mkdir -p doc/build mkdir -p build
cd doc/build cd build
cmake .. cmake -DDISABLE_ALL=ON -DBUILD_DOC=ON ..
make doc make doc
build: build:

View File

@ -20,6 +20,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Build ### Build
- Bump the minimum cmake version to 3.5 - Bump the minimum cmake version to 3.5
- The `BUILD_IPC_MSG` option has been renamed to `BUILD_POLYBAR_MSG`
- Building the documentation is now enabled by default and not just when
`sphinx-build` is found.
- Users can control exactly which targets should be available with the following
cmake options (together with their default value):
- `BUILD_POLYBAR=ON` - Builds the `polybar` executable
- `BUILD_POLYBAR_MSG=ON` - Builds the `polybar-msg` executable
- `BUILD_TESTS=OFF` - Builds the test suite
- `BUILD_DOC=ON` - Builds the documentation
- `DISABLE_ALL=OFF` - Disables all above targets by default. Individual
targets can still be enabled explicitly.
- The documentation can no longer be built by directly configuring the `doc`
directory.
### Added ### Added
- Warn states for the cpu, memory, fs, and battery modules. - Warn states for the cpu, memory, fs, and battery modules.

View File

@ -4,22 +4,6 @@
cmake_minimum_required(VERSION 3.5.0 FATAL_ERROR) cmake_minimum_required(VERSION 3.5.0 FATAL_ERROR)
project(polybar CXX) project(polybar CXX)
option(ENABLE_CCACHE "Enable ccache support" ON)
if(ENABLE_CCACHE)
message(STATUS "Trying to enable ccache")
find_program(BIN_CCACHE ccache)
mark_as_advanced(BIN_CCACHE)
string(ASCII 27 esc)
if(NOT BIN_CCACHE)
message(STATUS "${esc}[33mCouldn't locate ccache, disabling ccache...${esc}[0m")
else()
# Enable only if the binary is found
message(STATUS "${esc}[32mUsing compiler cache ${BIN_CCACHE}${esc}[0m")
set(CMAKE_CXX_COMPILER_LAUNCHER ${BIN_CCACHE} CACHE STRING "")
endif()
endif()
# Extract version information from version.txt. The first line that looks like # Extract version information from version.txt. The first line that looks like
# a version string is used, so the file supports comments # a version string is used, so the file supports comments
file(STRINGS version.txt version_txt REGEX "^[0-9]+\\.[0-9]+\\.[0-9]+.*$" LIMIT_COUNT 1) file(STRINGS version.txt version_txt REGEX "^[0-9]+\\.[0-9]+\\.[0-9]+.*$" LIMIT_COUNT 1)
@ -46,20 +30,26 @@ set(CMAKE_MODULE_PATH
include(GNUInstallDirs) include(GNUInstallDirs)
include(utils) include(utils)
include(01-core) include(00-components)
include(02-opts) include(02-opts)
if (HAS_CXX_COMPILATION)
include(01-core)
endif()
include(03-libs) include(03-libs)
include(04-targets) include(04-targets)
include(05-summary)
if(BUILD_DOC) if(BUILD_DOC)
add_subdirectory(doc) add_subdirectory(doc)
endif() endif()
add_subdirectory(contrib/bash) add_subdirectory(contrib/bash)
add_subdirectory(contrib/zsh) add_subdirectory(contrib/zsh)
add_subdirectory(include) if (BUILD_LIBPOLY)
add_subdirectory(lib) add_subdirectory(include)
add_subdirectory(src bin) add_subdirectory(lib)
endif()
if (HAS_CXX_COMPILATION)
add_subdirectory(src bin)
endif()
# We need to enable testing in the root folder so that 'ctest' and 'make test' # We need to enable testing in the root folder so that 'ctest' and 'make test'
# can be run in the build directory # can be run in the build directory
@ -68,6 +58,7 @@ if(BUILD_TESTS)
add_subdirectory(tests) add_subdirectory(tests)
endif() endif()
include(05-summary)
# #
# Generate configuration file # Generate configuration file

View File

@ -149,7 +149,7 @@ set_build_opts() {
read -r -p "$(msg "Build \"polybar-msg\" used to send ipc messages ------------------ [y/N]: ")" -n 1 p && echo read -r -p "$(msg "Build \"polybar-msg\" used to send ipc messages ------------------ [y/N]: ")" -n 1 p && echo
[[ "${p^^}" != "Y" ]] && ENABLE_IPC_MSG="OFF" || ENABLE_IPC_MSG="ON" [[ "${p^^}" != "Y" ]] && ENABLE_IPC_MSG="OFF" || ENABLE_IPC_MSG="ON"
fi fi
if [[ -z "$JOB_COUNT" ]]; then if [[ -z "$JOB_COUNT" ]]; then
read -r -p "$(msg "Parallelize the build using make -j$(nproc) --------------------------- [y/N]: ")" -n 1 p && echo read -r -p "$(msg "Parallelize the build using make -j$(nproc) --------------------------- [y/N]: ")" -n 1 p && echo
[[ "${p^^}" != "Y" ]] && JOB_COUNT=1 || JOB_COUNT=$(nproc) [[ "${p^^}" != "Y" ]] && JOB_COUNT=1 || JOB_COUNT=$(nproc)
@ -200,7 +200,7 @@ main() {
-DENABLE_MPD:BOOL="${ENABLE_MPD}" \ -DENABLE_MPD:BOOL="${ENABLE_MPD}" \
-DENABLE_NETWORK:BOOL="${ENABLE_NETWORK}" \ -DENABLE_NETWORK:BOOL="${ENABLE_NETWORK}" \
-DENABLE_CURL:BOOL="${ENABLE_CURL}" \ -DENABLE_CURL:BOOL="${ENABLE_CURL}" \
-DBUILD_IPC_MSG:BOOL="${ENABLE_IPC_MSG}" \ -DBUILD_POLYBAR_MSG:BOOL="${ENABLE_IPC_MSG}" \
.. || msg_err "Failed to generate build... read output to get a hint of what went wrong" .. || msg_err "Failed to generate build... read output to get a hint of what went wrong"
msg "Building project" msg "Building project"

26
cmake/00-components.cmake Normal file
View File

@ -0,0 +1,26 @@
option(DISABLE_ALL "Set this to ON disable all targets. Individual targets can be enabled explicitly." OFF)
# If all targets are disabled, we set the default value for options that are on
# by default to OFF
if (DISABLE_ALL)
set(DEFAULT_ON OFF)
else()
set(DEFAULT_ON ON)
endif()
option(BUILD_POLYBAR "Build the main polybar executable" ${DEFAULT_ON})
option(BUILD_POLYBAR_MSG "Build polybar-msg" ${DEFAULT_ON})
option(BUILD_TESTS "Build testsuite" OFF)
option(BUILD_DOC "Build documentation" ${DEFAULT_ON})
if (BUILD_POLYBAR OR BUILD_TESTS)
set(BUILD_LIBPOLY ON)
else()
set(BUILD_LIBPOLY OFF)
endif()
if (BUILD_LIBPOLY OR BUILD_POLYBAR_MSG)
set(HAS_CXX_COMPILATION ON)
else()
set(HAS_CXX_COMPILATION OFF)
endif()

View File

@ -1,59 +1,66 @@
# set(SPHINX_FLAGS "" CACHE STRING "Flags to pass to sphinx-build")
# Build options
#
set(SPHINX_BUILD "sphinx-build" CACHE STRING "Name/Path of the sphinx-build executable to use.") set(SPHINX_BUILD "sphinx-build" CACHE STRING "Name/Path of the sphinx-build executable to use.")
checklib(BUILD_DOC "binary" "${SPHINX_BUILD}")
checklib(ENABLE_ALSA "pkg-config" alsa) if (HAS_CXX_COMPILATION)
checklib(ENABLE_CURL "pkg-config" libcurl) option(ENABLE_CCACHE "Enable ccache support" ON)
checklib(ENABLE_I3 "binary" i3) if(ENABLE_CCACHE)
checklib(ENABLE_MPD "pkg-config" libmpdclient) find_program(BIN_CCACHE ccache)
checklib(WITH_LIBNL "pkg-config" libnl-genl-3.0) mark_as_advanced(BIN_CCACHE)
if(WITH_LIBNL)
checklib(ENABLE_NETWORK "pkg-config" libnl-genl-3.0)
set(WIRELESS_LIB "libnl")
else()
checklib(ENABLE_NETWORK "cmake" Libiw)
set(WIRELESS_LIB "wireless-tools")
endif()
checklib(ENABLE_PULSEAUDIO "pkg-config" libpulse)
checklib(WITH_XKB "pkg-config" xcb-xkb)
checklib(WITH_XRM "pkg-config" xcb-xrm)
checklib(WITH_XRANDR_MONITORS "pkg-config" "xcb-randr>=1.12")
checklib(WITH_XCURSOR "pkg-config" "xcb-cursor")
if(NOT DEFINED ENABLE_CCACHE AND CMAKE_BUILD_TYPE_UPPER MATCHES DEBUG) if(NOT BIN_CCACHE)
set(ENABLE_CCACHE ON) message_colored(STATUS "Couldn't locate ccache, disabling ccache..." "33")
else()
# Enable only if the binary is found
message_colored(STATUS "Using compiler cache ${BIN_CCACHE}" "32")
set(CMAKE_CXX_COMPILER_LAUNCHER ${BIN_CCACHE} CACHE STRING "")
endif()
endif()
option(CXXLIB_CLANG "Link against libc++" OFF)
option(CXXLIB_GCC "Link against stdlibc++" OFF)
endif() endif()
option(CXXLIB_CLANG "Link against libc++" OFF) if (BUILD_LIBPOLY)
option(CXXLIB_GCC "Link against stdlibc++" OFF) checklib(ENABLE_ALSA "pkg-config" alsa)
checklib(ENABLE_CURL "pkg-config" libcurl)
checklib(ENABLE_I3 "binary" i3)
checklib(ENABLE_MPD "pkg-config" libmpdclient)
checklib(WITH_LIBNL "pkg-config" libnl-genl-3.0)
if(WITH_LIBNL)
checklib(ENABLE_NETWORK "pkg-config" libnl-genl-3.0)
set(WIRELESS_LIB "libnl")
else()
checklib(ENABLE_NETWORK "cmake" Libiw)
set(WIRELESS_LIB "wireless-tools")
endif()
checklib(ENABLE_PULSEAUDIO "pkg-config" libpulse)
checklib(WITH_XKB "pkg-config" xcb-xkb)
checklib(WITH_XRM "pkg-config" xcb-xrm)
checklib(WITH_XRANDR_MONITORS "pkg-config" "xcb-randr>=1.12")
checklib(WITH_XCURSOR "pkg-config" "xcb-cursor")
option(BUILD_IPC_MSG "Build ipc messager" ON) option(ENABLE_ALSA "Enable alsa support" ON)
option(BUILD_TESTS "Build testsuite" OFF) option(ENABLE_CURL "Enable curl support" ON)
option(BUILD_DOC "Build documentation" ON) option(ENABLE_I3 "Enable i3 support" ON)
option(ENABLE_MPD "Enable mpd support" ON)
option(WITH_LIBNL "Use netlink interface for wireless" ON)
option(ENABLE_NETWORK "Enable network support" ON)
option(ENABLE_XKEYBOARD "Enable xkeyboard support" ON)
option(ENABLE_PULSEAUDIO "Enable PulseAudio support" ON)
option(ENABLE_ALSA "Enable alsa support" ON) option(WITH_XRANDR_MONITORS "xcb-randr monitor support" ON)
option(ENABLE_CURL "Enable curl support" ON) option(WITH_XKB "xcb-xkb support" ON)
option(ENABLE_I3 "Enable i3 support" ON) option(WITH_XRM "xcb-xrm support" ON)
option(ENABLE_MPD "Enable mpd support" ON) option(WITH_XCURSOR "xcb-cursor support" ON)
option(WITH_LIBNL "Use netlink interface for wireless" ON)
option(ENABLE_NETWORK "Enable network support" ON)
option(ENABLE_XKEYBOARD "Enable xkeyboard support" ON)
option(ENABLE_PULSEAUDIO "Enable PulseAudio support" ON)
option(WITH_XRANDR_MONITORS "xcb-randr monitor support" ON) option(DEBUG_LOGGER "Trace logging" ON)
option(WITH_XKB "xcb-xkb support" ON)
option(WITH_XRM "xcb-xrm support" ON)
option(WITH_XCURSOR "xcb-cursor support" ON)
option(DEBUG_LOGGER "Trace logging" ON) if(CMAKE_BUILD_TYPE_UPPER MATCHES DEBUG)
option(DEBUG_LOGGER_VERBOSE "Trace logging (verbose)" OFF)
if(CMAKE_BUILD_TYPE_UPPER MATCHES DEBUG) option(DEBUG_HINTS "Debug clickable areas" OFF)
option(DEBUG_LOGGER_VERBOSE "Trace logging (verbose)" OFF) option(DEBUG_WHITESPACE "Debug whitespace" OFF)
option(DEBUG_HINTS "Debug clickable areas" OFF) option(DEBUG_FONTCONFIG "Debug fontconfig" OFF)
option(DEBUG_WHITESPACE "Debug whitespace" OFF) endif()
option(DEBUG_FONTCONFIG "Debug fontconfig" OFF)
endif() endif()
set(SETTING_ALSA_SOUNDCARD "default" set(SETTING_ALSA_SOUNDCARD "default"

View File

@ -2,62 +2,72 @@
# Check libraries # Check libraries
# #
find_package(Threads REQUIRED) if (BUILD_DOC)
find_package(CairoFC REQUIRED) find_program(BIN_SPHINX "${SPHINX_BUILD}")
if (ENABLE_ALSA) if (NOT BIN_SPHINX)
find_package(ALSA REQUIRED) message(FATAL_ERROR "sphinx-build executable '${SPHINX_BUILD}' not found.")
set(ALSA_VERSION ${ALSA_VERSION_STRING})
endif()
if (ENABLE_CURL)
find_package(CURL REQUIRED)
set(CURL_VERSION ${CURL_VERSION_STRING})
endif()
if (ENABLE_MPD)
find_package(LibMPDClient REQUIRED)
set(MPD_VERSION ${LibMPDClient_VERSION})
endif()
if (ENABLE_NETWORK)
if(WITH_LIBNL)
find_package(LibNlGenl3 REQUIRED)
set(NETWORK_LIBRARY_VERSION ${LibNlGenl3_VERSION})
else()
find_package(Libiw REQUIRED)
endif() endif()
endif() endif()
if (ENABLE_PULSEAUDIO) if (BUILD_LIBPOLY)
find_package(LibPulse REQUIRED) find_package(Threads REQUIRED)
set(PULSEAUDIO_VERSION ${LibPulse_VERSION}) find_package(CairoFC REQUIRED)
endif()
# xcomposite is required if (ENABLE_ALSA)
list(APPEND XORG_EXTENSIONS COMPOSITE) find_package(ALSA REQUIRED)
if (WITH_XKB) set(ALSA_VERSION ${ALSA_VERSION_STRING})
list(APPEND XORG_EXTENSIONS XKB) endif()
endif()
if (WITH_XCURSOR)
list(APPEND XORG_EXTENSIONS CURSOR)
endif()
if (WITH_XRM)
list(APPEND XORG_EXTENSIONS XRM)
endif()
# Set min xrandr version required if (ENABLE_CURL)
if (WITH_XRANDR_MONITORS) find_package(CURL REQUIRED)
set(XRANDR_VERSION "1.12") set(CURL_VERSION ${CURL_VERSION_STRING})
else () endif()
set(XRANDR_VERSION "")
endif()
# Randr is required if (ENABLE_MPD)
find_package(Xcb ${XRANDR_VERSION} REQUIRED COMPONENTS RANDR) find_package(LibMPDClient REQUIRED)
find_package(Xcb REQUIRED COMPONENTS ${XORG_EXTENSIONS}) set(MPD_VERSION ${LibMPDClient_VERSION})
endif()
# FreeBSD Support if (ENABLE_NETWORK)
if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") if(WITH_LIBNL)
find_package(LibInotify REQUIRED) find_package(LibNlGenl3 REQUIRED)
set(NETWORK_LIBRARY_VERSION ${LibNlGenl3_VERSION})
else()
find_package(Libiw REQUIRED)
endif()
endif()
if (ENABLE_PULSEAUDIO)
find_package(LibPulse REQUIRED)
set(PULSEAUDIO_VERSION ${LibPulse_VERSION})
endif()
# xcomposite is required
list(APPEND XORG_EXTENSIONS COMPOSITE)
if (WITH_XKB)
list(APPEND XORG_EXTENSIONS XKB)
endif()
if (WITH_XCURSOR)
list(APPEND XORG_EXTENSIONS CURSOR)
endif()
if (WITH_XRM)
list(APPEND XORG_EXTENSIONS XRM)
endif()
# Set min xrandr version required
if (WITH_XRANDR_MONITORS)
set(XRANDR_VERSION "1.12")
else ()
set(XRANDR_VERSION "")
endif()
# Randr is required
find_package(Xcb ${XRANDR_VERSION} REQUIRED COMPONENTS RANDR)
find_package(Xcb REQUIRED COMPONENTS ${XORG_EXTENSIONS})
# FreeBSD Support
if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
find_package(LibInotify REQUIRED)
endif()
endif() endif()

View File

@ -5,8 +5,13 @@
message(STATUS " Build:") message(STATUS " Build:")
message_colored(STATUS " Version: ${APP_VERSION}" "32;1") message_colored(STATUS " Version: ${APP_VERSION}" "32;1")
message_colored(STATUS " Type: ${CMAKE_BUILD_TYPE}" "37;2") message_colored(STATUS " Type: ${CMAKE_BUILD_TYPE}" "37;2")
message_colored(STATUS " CXX: ${CMAKE_CXX_COMPILER} ${CMAKE_CXX_FLAGS} ${CMAKE_CXX_FLAGS_${CMAKE_BUILD_TYPE_UPPER}}" "37;2") if (HAS_CXX_COMPILATION)
message_colored(STATUS " LD: ${CMAKE_LINKER} ${CMAKE_EXE_LINKER_FLAGS} ${CMAKE_EXE_LINKER_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")
endif()
if (BUILD_DOC)
message_colored(STATUS " sphinx-build: ${BIN_SPHINX} ${SPHINX_FLAGS}" "37;2")
endif()
message(STATUS " Install Paths:") message(STATUS " Install Paths:")
message_colored(STATUS " PREFIX: ${CMAKE_INSTALL_PREFIX}" "32") message_colored(STATUS " PREFIX: ${CMAKE_INSTALL_PREFIX}" "32")
@ -16,34 +21,37 @@ message_colored(STATUS " DOCDIR: ${CMAKE_INSTALL_FULL_DOCDIR}" "32")
message_colored(STATUS " MANDIR: ${CMAKE_INSTALL_FULL_MANDIR}" "32") message_colored(STATUS " MANDIR: ${CMAKE_INSTALL_FULL_MANDIR}" "32")
message(STATUS " Targets:") message(STATUS " Targets:")
colored_option(" polybar-msg" BUILD_IPC_MSG) colored_option(" polybar" BUILD_POLYBAR)
colored_option(" polybar-msg" BUILD_POLYBAR_MSG)
colored_option(" testsuite" BUILD_TESTS) colored_option(" testsuite" BUILD_TESTS)
colored_option(" documentation" BUILD_DOC) colored_option(" documentation" BUILD_DOC)
message(STATUS " Module support:") if (BUILD_LIBPOLY)
colored_option(" alsa" ENABLE_ALSA ALSA_VERSION) message(STATUS " Module support:")
colored_option(" curl" ENABLE_CURL CURL_VERSION) colored_option(" alsa" ENABLE_ALSA ALSA_VERSION)
colored_option(" i3" ENABLE_I3) colored_option(" curl" ENABLE_CURL CURL_VERSION)
colored_option(" mpd" ENABLE_MPD MPD_VERSION) colored_option(" i3" ENABLE_I3)
colored_option(" network (${WIRELESS_LIB})" ENABLE_NETWORK NETWORK_LIBRARY_VERSION) colored_option(" mpd" ENABLE_MPD MPD_VERSION)
colored_option(" pulseaudio" ENABLE_PULSEAUDIO PULSEAUDIO_VERSION) colored_option(" network (${WIRELESS_LIB})" ENABLE_NETWORK NETWORK_LIBRARY_VERSION)
colored_option(" xkeyboard" WITH_XKB Xcb_XKB_VERSION) colored_option(" pulseaudio" ENABLE_PULSEAUDIO PULSEAUDIO_VERSION)
colored_option(" xkeyboard" WITH_XKB Xcb_XKB_VERSION)
message(STATUS " X extensions:") message(STATUS " X extensions:")
colored_option(" xcb-randr" Xcb_RANDR_FOUND Xcb_RANDR_VERSION) colored_option(" xcb-randr" Xcb_RANDR_FOUND Xcb_RANDR_VERSION)
colored_option(" xcb-randr (monitor support)" WITH_XRANDR_MONITORS Xcb_RANDR_VERSION) colored_option(" xcb-randr (monitor support)" WITH_XRANDR_MONITORS Xcb_RANDR_VERSION)
colored_option(" xcb-composite" Xcb_COMPOSITE_FOUND Xcb_COMPOSITE_VERSION) colored_option(" xcb-composite" Xcb_COMPOSITE_FOUND Xcb_COMPOSITE_VERSION)
colored_option(" xcb-xkb" WITH_XKB Xcb_XKB_VERSION) colored_option(" xcb-xkb" WITH_XKB Xcb_XKB_VERSION)
colored_option(" xcb-xrm" WITH_XRM Xcb_XRM_VERSION) colored_option(" xcb-xrm" WITH_XRM Xcb_XRM_VERSION)
colored_option(" xcb-cursor" WITH_XCURSOR Xcb_CURSOR_VERSION) colored_option(" xcb-cursor" WITH_XCURSOR Xcb_CURSOR_VERSION)
message(STATUS " Log options:") message(STATUS " Log options:")
colored_option(" Trace logging" DEBUG_LOGGER) colored_option(" Trace logging" DEBUG_LOGGER)
if(CMAKE_BUILD_TYPE_UPPER MATCHES DEBUG) if(CMAKE_BUILD_TYPE_UPPER MATCHES DEBUG)
message(STATUS " Debug options:") message(STATUS " Debug options:")
colored_option(" Trace logging (verbose)" DEBUG_LOGGER_VERBOSE) colored_option(" Trace logging (verbose)" DEBUG_LOGGER_VERBOSE)
colored_option(" Draw clickable areas" DEBUG_HINTS) colored_option(" Draw clickable areas" DEBUG_HINTS)
colored_option(" Print fc-match details" DEBUG_FONTCONFIG) colored_option(" Print fc-match details" DEBUG_FONTCONFIG)
colored_option(" Enable window shading" DEBUG_SHADED) colored_option(" Enable window shading" DEBUG_SHADED)
endif()
endif() endif()

View File

@ -31,7 +31,7 @@ cmake \
-DCMAKE_CXX_FLAGS="${CXXFLAGS} -Werror" \ -DCMAKE_CXX_FLAGS="${CXXFLAGS} -Werror" \
-DCMAKE_BUILD_TYPE="${BUILD_TYPE}" \ -DCMAKE_BUILD_TYPE="${BUILD_TYPE}" \
-DBUILD_TESTS:BOOL="${BUILD_TESTS:-OFF}" \ -DBUILD_TESTS:BOOL="${BUILD_TESTS:-OFF}" \
-DBUILD_DOC:BOOL="${BUILD_DOC:-OFF}" \ -DBUILD_DOC:BOOL=OFF \
-DENABLE_PULSEAUDIO="${ENABLE_PULSEAUDIO:-OFF}" \ -DENABLE_PULSEAUDIO="${ENABLE_PULSEAUDIO:-OFF}" \
-DENABLE_NETWORK="${ENABLE_NETWORK:-OFF}" \ -DENABLE_NETWORK="${ENABLE_NETWORK:-OFF}" \
-DENABLE_MPD="${ENABLE_MPD:-OFF}" \ -DENABLE_MPD="${ENABLE_MPD:-OFF}" \

View File

@ -1,13 +1,3 @@
cmake_minimum_required(VERSION 3.5.0 FATAL_ERROR)
# Only used if documentation is built on its own
project(polybar-doc NONE)
if(NOT SPHINX_BUILD)
set(SPHINX_BUILD "sphinx-build")
endif()
set(SPHINX_FLAGS "" CACHE STRING "Flags to pass to sphinx-build")
separate_arguments(sphinx_flags UNIX_COMMAND "${SPHINX_FLAGS}") separate_arguments(sphinx_flags UNIX_COMMAND "${SPHINX_FLAGS}")
set(doc_path "${CMAKE_CURRENT_SOURCE_DIR}") set(doc_path "${CMAKE_CURRENT_SOURCE_DIR}")
@ -25,7 +15,7 @@ foreach(builder ${doc_builders})
set(doc_target "doc_${builder}") set(doc_target "doc_${builder}")
set(builder_log "builder-${builder}.log") set(builder_log "builder-${builder}.log")
add_custom_target(${doc_target} add_custom_target(${doc_target}
COMMAND ${SPHINX_BUILD} COMMAND ${BIN_SPHINX}
-b ${builder} -b ${builder}
# conf.py dir # conf.py dir
-c "${CMAKE_CURRENT_BINARY_DIR}" -c "${CMAKE_CURRENT_BINARY_DIR}"
@ -43,19 +33,6 @@ endforeach()
# Dummy target that depends on all documentation targets # Dummy target that depends on all documentation targets
add_custom_target(doc ALL DEPENDS ${doc_targets}) add_custom_target(doc ALL DEPENDS ${doc_targets})
# This is needed for the case where only the doc target is built
# CMAKE_INSTALL_DOCDIR uses PROJECT_NAME which is now polybar-doc, to be
# consistent with a regular install we temporarily override it with "polybar"
# before including GNUInstallDirs
# Also since no language is set and GNUInstallDirs cannot set
# CMAKE_INSTALL_LIBDIR, so we set it to a dummy value to suppress a warning
if(${CMAKE_PROJECT_NAME} STREQUAL "polybar-doc")
set(PROJECT_NAME "polybar")
set(CMAKE_INSTALL_LIBDIR "")
include(GNUInstallDirs)
set(PROJECT_NAME "polybar-doc")
endif()
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html/ install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html/
DESTINATION ${CMAKE_INSTALL_DOCDIR} DESTINATION ${CMAKE_INSTALL_DOCDIR}
COMPONENT doc) COMPONENT doc)

View File

@ -13,9 +13,6 @@ have that installed.
If you build polybar normally while having Sphinx installed during configuration, the documentation will be enabled and If you build polybar normally while having Sphinx installed during configuration, the documentation will be enabled and
built as well. Building the documentation can be disabled by passing `-DBUILD_DOC=OFF` to `cmake`. built as well. Building the documentation can be disabled by passing `-DBUILD_DOC=OFF` to `cmake`.
Alternatively the documentation can be built without the rest of polybar, for that run `cmake` only on the `doc`
directory. For example, create a `build` directory in `doc` and then run `cmake ..` in there.
Once configured, all of the documentation can be generated with `make doc` or use `make doc_html` or `make doc_man` to Once configured, all of the documentation can be generated with `make doc` or use `make doc_html` or `make doc_man` to
only generate the html documentation or the man pages respectively. only generate the html documentation or the man pages respectively.

View File

@ -13,5 +13,3 @@ configure_file(
${CMAKE_CURRENT_LIST_DIR}/settings.hpp.cmake ${CMAKE_CURRENT_LIST_DIR}/settings.hpp.cmake
${CMAKE_BINARY_DIR}/generated-sources/settings.hpp ${CMAKE_BINARY_DIR}/generated-sources/settings.hpp
ESCAPE_QUOTES) ESCAPE_QUOTES)
set(APP_VERSION ${APP_VERSION} PARENT_SCOPE)

View File

@ -2,183 +2,187 @@
# Configure src # Configure src
# #
# Source tree {{{
get_include_dirs(includes_dir) get_include_dirs(includes_dir)
get_sources_dirs(src_dir) get_sources_dirs(src_dir)
set(ALSA_SOURCES if (BUILD_LIBPOLY)
${src_dir}/adapters/alsa/control.cpp # Source tree {{{
${src_dir}/adapters/alsa/mixer.cpp
${src_dir}/modules/alsa.cpp
)
set(GITHUB_SOURCES ${src_dir}/modules/github.cpp ${src_dir}/utils/http.cpp) set(ALSA_SOURCES
${src_dir}/adapters/alsa/control.cpp
${src_dir}/adapters/alsa/mixer.cpp
${src_dir}/modules/alsa.cpp
)
set(I3_SOURCES set(GITHUB_SOURCES ${src_dir}/modules/github.cpp ${src_dir}/utils/http.cpp)
${src_dir}/modules/i3.cpp
${src_dir}/utils/i3.cpp
)
set(MPD_SOURCES set(I3_SOURCES
${src_dir}/adapters/mpd.cpp ${src_dir}/modules/i3.cpp
${src_dir}/modules/mpd.cpp ${src_dir}/utils/i3.cpp
) )
set(NETWORK_SOURCES set(MPD_SOURCES
${src_dir}/adapters/net.cpp ${src_dir}/adapters/mpd.cpp
${src_dir}/modules/network.cpp ${src_dir}/modules/mpd.cpp
$<IF:$<BOOL:${WITH_LIBNL}>,${src_dir}/adapters/net_nl.cpp,${src_dir}/adapters/net_iw.cpp> )
)
set(PULSEAUDIO_SOURCES set(NETWORK_SOURCES
${src_dir}/adapters/pulseaudio.cpp ${src_dir}/adapters/net.cpp
${src_dir}/modules/pulseaudio.cpp ${src_dir}/modules/network.cpp
) $<IF:$<BOOL:${WITH_LIBNL}>,${src_dir}/adapters/net_nl.cpp,${src_dir}/adapters/net_iw.cpp>
)
set(XCURSOR_SOURCES ${src_dir}/x11/cursor.cpp) set(PULSEAUDIO_SOURCES
${src_dir}/adapters/pulseaudio.cpp
${src_dir}/modules/pulseaudio.cpp
)
set(XKB_SOURCES set(XCURSOR_SOURCES ${src_dir}/x11/cursor.cpp)
${src_dir}/modules/xkeyboard.cpp
${src_dir}/x11/extensions/xkb.cpp
)
set(XRM_SOURCES ${src_dir}/x11/xresources.cpp) set(XKB_SOURCES
${src_dir}/modules/xkeyboard.cpp
${src_dir}/x11/extensions/xkb.cpp
)
configure_file( set(XRM_SOURCES ${src_dir}/x11/xresources.cpp)
${CMAKE_CURRENT_LIST_DIR}/settings.cpp.cmake
${CMAKE_BINARY_DIR}/generated-sources/settings.cpp
ESCAPE_QUOTES)
set(POLY_SOURCES configure_file(
${CMAKE_BINARY_DIR}/generated-sources/settings.cpp ${CMAKE_CURRENT_LIST_DIR}/settings.cpp.cmake
${CMAKE_BINARY_DIR}/generated-sources/settings.cpp
ESCAPE_QUOTES)
${src_dir}/cairo/utils.cpp set(POLY_SOURCES
${CMAKE_BINARY_DIR}/generated-sources/settings.cpp
${src_dir}/components/bar.cpp ${src_dir}/cairo/utils.cpp
${src_dir}/components/builder.cpp
${src_dir}/components/command_line.cpp
${src_dir}/components/config.cpp
${src_dir}/components/config_parser.cpp
${src_dir}/components/controller.cpp
${src_dir}/components/ipc.cpp
${src_dir}/components/logger.cpp
${src_dir}/components/renderer.cpp
${src_dir}/components/screen.cpp
${src_dir}/components/taskqueue.cpp
${src_dir}/drawtypes/animation.cpp ${src_dir}/components/bar.cpp
${src_dir}/drawtypes/iconset.cpp ${src_dir}/components/builder.cpp
${src_dir}/drawtypes/label.cpp ${src_dir}/components/command_line.cpp
${src_dir}/drawtypes/progressbar.cpp ${src_dir}/components/config.cpp
${src_dir}/drawtypes/ramp.cpp ${src_dir}/components/config_parser.cpp
${src_dir}/components/controller.cpp
${src_dir}/components/ipc.cpp
${src_dir}/components/logger.cpp
${src_dir}/components/renderer.cpp
${src_dir}/components/screen.cpp
${src_dir}/components/taskqueue.cpp
${src_dir}/events/signal_emitter.cpp ${src_dir}/drawtypes/animation.cpp
${src_dir}/events/signal_receiver.cpp ${src_dir}/drawtypes/iconset.cpp
${src_dir}/drawtypes/label.cpp
${src_dir}/drawtypes/progressbar.cpp
${src_dir}/drawtypes/ramp.cpp
${src_dir}/modules/backlight.cpp ${src_dir}/events/signal_emitter.cpp
${src_dir}/modules/battery.cpp ${src_dir}/events/signal_receiver.cpp
${src_dir}/modules/bspwm.cpp
${src_dir}/modules/counter.cpp
${src_dir}/modules/cpu.cpp
${src_dir}/modules/date.cpp
${src_dir}/modules/fs.cpp
${src_dir}/modules/ipc.cpp
${src_dir}/modules/memory.cpp
${src_dir}/modules/menu.cpp
${src_dir}/modules/meta/base.cpp
${src_dir}/modules/script.cpp
${src_dir}/modules/systray.cpp
${src_dir}/modules/temperature.cpp
${src_dir}/modules/text.cpp
${src_dir}/modules/xbacklight.cpp
${src_dir}/modules/xwindow.cpp
${src_dir}/modules/xworkspaces.cpp
${src_dir}/tags/dispatch.cpp ${src_dir}/modules/backlight.cpp
${src_dir}/tags/parser.cpp ${src_dir}/modules/battery.cpp
${src_dir}/modules/bspwm.cpp
${src_dir}/modules/counter.cpp
${src_dir}/modules/cpu.cpp
${src_dir}/modules/date.cpp
${src_dir}/modules/fs.cpp
${src_dir}/modules/ipc.cpp
${src_dir}/modules/memory.cpp
${src_dir}/modules/menu.cpp
${src_dir}/modules/meta/base.cpp
${src_dir}/modules/script.cpp
${src_dir}/modules/systray.cpp
${src_dir}/modules/temperature.cpp
${src_dir}/modules/text.cpp
${src_dir}/modules/xbacklight.cpp
${src_dir}/modules/xwindow.cpp
${src_dir}/modules/xworkspaces.cpp
${src_dir}/utils/actions.cpp ${src_dir}/tags/dispatch.cpp
${src_dir}/utils/bspwm.cpp ${src_dir}/tags/parser.cpp
${src_dir}/utils/color.cpp
${src_dir}/utils/command.cpp
${src_dir}/utils/concurrency.cpp
${src_dir}/utils/env.cpp
${src_dir}/utils/factory.cpp
${src_dir}/utils/file.cpp
${src_dir}/utils/inotify.cpp
${src_dir}/utils/io.cpp
${src_dir}/utils/process.cpp
${src_dir}/utils/socket.cpp
${src_dir}/utils/string.cpp
${src_dir}/utils/throttle.cpp
${src_dir}/x11/atoms.cpp ${src_dir}/utils/actions.cpp
${src_dir}/x11/background_manager.cpp ${src_dir}/utils/bspwm.cpp
${src_dir}/x11/connection.cpp ${src_dir}/utils/color.cpp
${src_dir}/x11/ewmh.cpp ${src_dir}/utils/command.cpp
${src_dir}/x11/extensions/composite.cpp ${src_dir}/utils/concurrency.cpp
${src_dir}/x11/extensions/randr.cpp ${src_dir}/utils/env.cpp
${src_dir}/x11/icccm.cpp ${src_dir}/utils/factory.cpp
${src_dir}/x11/registry.cpp ${src_dir}/utils/file.cpp
${src_dir}/x11/tray_client.cpp ${src_dir}/utils/inotify.cpp
${src_dir}/x11/tray_manager.cpp ${src_dir}/utils/io.cpp
${src_dir}/x11/window.cpp ${src_dir}/utils/process.cpp
${src_dir}/x11/winspec.cpp ${src_dir}/utils/socket.cpp
${src_dir}/x11/xembed.cpp ${src_dir}/utils/string.cpp
${src_dir}/utils/throttle.cpp
$<$<BOOL:${ENABLE_ALSA}>:${ALSA_SOURCES}> ${src_dir}/x11/atoms.cpp
$<$<BOOL:${ENABLE_CURL}>:${GITHUB_SOURCES}> ${src_dir}/x11/background_manager.cpp
$<$<BOOL:${ENABLE_I3}>:${I3_SOURCES}> ${src_dir}/x11/connection.cpp
$<$<BOOL:${ENABLE_MPD}>:${MPD_SOURCES}> ${src_dir}/x11/ewmh.cpp
$<$<BOOL:${ENABLE_NETWORK}>:${NETWORK_SOURCES}> ${src_dir}/x11/extensions/composite.cpp
$<$<BOOL:${ENABLE_PULSEAUDIO}>:${PULSEAUDIO_SOURCES}> ${src_dir}/x11/extensions/randr.cpp
$<$<BOOL:${WITH_XCURSOR}>:${XCURSOR_SOURCES}> ${src_dir}/x11/icccm.cpp
$<$<BOOL:${WITH_XKB}>:${XKB_SOURCES}> ${src_dir}/x11/registry.cpp
$<$<BOOL:${WITH_XRM}>:${XRM_SOURCES}> ${src_dir}/x11/tray_client.cpp
) ${src_dir}/x11/tray_manager.cpp
${src_dir}/x11/window.cpp
${src_dir}/x11/winspec.cpp
${src_dir}/x11/xembed.cpp
# }}} $<$<BOOL:${ENABLE_ALSA}>:${ALSA_SOURCES}>
$<$<BOOL:${ENABLE_CURL}>:${GITHUB_SOURCES}>
$<$<BOOL:${ENABLE_I3}>:${I3_SOURCES}>
$<$<BOOL:${ENABLE_MPD}>:${MPD_SOURCES}>
$<$<BOOL:${ENABLE_NETWORK}>:${NETWORK_SOURCES}>
$<$<BOOL:${ENABLE_PULSEAUDIO}>:${PULSEAUDIO_SOURCES}>
$<$<BOOL:${WITH_XCURSOR}>:${XCURSOR_SOURCES}>
$<$<BOOL:${WITH_XKB}>:${XKB_SOURCES}>
$<$<BOOL:${WITH_XRM}>:${XRM_SOURCES}>
)
# Target: polybar {{{ # }}}
add_library(poly STATIC ${POLY_SOURCES}) # Target poly {{{
target_include_directories(poly PUBLIC ${includes_dir}) add_library(poly STATIC EXCLUDE_FROM_ALL ${POLY_SOURCES})
target_link_libraries(poly PUBLIC target_include_directories(poly PUBLIC ${includes_dir})
Threads::Threads target_link_libraries(poly PUBLIC
Cairo::CairoFC Threads::Threads
moodycamel Cairo::CairoFC
xpp moodycamel
$<$<TARGET_EXISTS:i3ipc++>:i3ipc++> xpp
$<$<TARGET_EXISTS:ALSA::ALSA>:ALSA::ALSA> $<$<TARGET_EXISTS:i3ipc++>:i3ipc++>
$<$<TARGET_EXISTS:CURL::libcurl>:CURL::libcurl> $<$<TARGET_EXISTS:ALSA::ALSA>:ALSA::ALSA>
$<$<TARGET_EXISTS:LibMPDClient::LibMPDClient>:LibMPDClient::LibMPDClient> $<$<TARGET_EXISTS:CURL::libcurl>:CURL::libcurl>
$<$<TARGET_EXISTS:LibNlGenl3::LibNlGenl3>:LibNlGenl3::LibNlGenl3> $<$<TARGET_EXISTS:LibMPDClient::LibMPDClient>:LibMPDClient::LibMPDClient>
$<$<TARGET_EXISTS:Libiw::Libiw>:Libiw::Libiw> $<$<TARGET_EXISTS:LibNlGenl3::LibNlGenl3>:LibNlGenl3::LibNlGenl3>
$<$<TARGET_EXISTS:LibPulse::LibPulse>:LibPulse::LibPulse> $<$<TARGET_EXISTS:Libiw::Libiw>:Libiw::Libiw>
$<$<TARGET_EXISTS:Xcb::RANDR>:Xcb::RANDR> $<$<TARGET_EXISTS:LibPulse::LibPulse>:LibPulse::LibPulse>
$<$<TARGET_EXISTS:Xcb::COMPOSITE>:Xcb::COMPOSITE> $<$<TARGET_EXISTS:Xcb::RANDR>:Xcb::RANDR>
$<$<TARGET_EXISTS:Xcb::XKB>:Xcb::XKB> $<$<TARGET_EXISTS:Xcb::COMPOSITE>:Xcb::COMPOSITE>
$<$<TARGET_EXISTS:Xcb::CURSOR>:Xcb::CURSOR> $<$<TARGET_EXISTS:Xcb::XKB>:Xcb::XKB>
$<$<TARGET_EXISTS:Xcb::XRM>:Xcb::XRM> $<$<TARGET_EXISTS:Xcb::CURSOR>:Xcb::CURSOR>
$<$<TARGET_EXISTS:LibInotify::LibInotify>:LibInotify::LibInotify> $<$<TARGET_EXISTS:Xcb::XRM>:Xcb::XRM>
) $<$<TARGET_EXISTS:LibInotify::LibInotify>:LibInotify::LibInotify>
)
target_compile_options(poly PUBLIC $<$<CXX_COMPILER_ID:GNU>:$<$<CONFIG:MinSizeRel>:-flto>>) target_compile_options(poly PUBLIC $<$<CXX_COMPILER_ID:GNU>:$<$<CONFIG:MinSizeRel>:-flto>>)
set_target_properties(poly PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/libs) set_target_properties(poly PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/libs)
# }}}
add_executable(polybar main.cpp) # Target: polybar {{{
target_link_libraries(polybar poly) if (BUILD_POLYBAR)
set_target_properties(poly PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) add_executable(polybar main.cpp)
target_link_libraries(polybar poly)
set_target_properties(poly PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
install(TARGETS polybar install(TARGETS polybar
DESTINATION ${CMAKE_INSTALL_BINDIR} DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT runtime) COMPONENT runtime)
endif()
# }}}
endif()
# }}}
# Target: polybar-msg {{{ # Target: polybar-msg {{{
if(BUILD_POLYBAR_MSG)
if(BUILD_IPC_MSG)
add_executable(polybar-msg add_executable(polybar-msg
ipc.cpp ipc.cpp
utils/env.cpp utils/env.cpp

View File

@ -6,7 +6,6 @@
#include "common.hpp" #include "common.hpp"
#include "utils/file.hpp" #include "utils/file.hpp"
#include "utils/io.hpp"
using namespace polybar; using namespace polybar;
using namespace std; using namespace std;