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:
parent
771154742c
commit
c24a6999a4
6
.github/workflows/ci.yml
vendored
6
.github/workflows/ci.yml
vendored
@ -21,9 +21,9 @@ jobs:
|
||||
run: sudo apt-get install -y python3-sphinx
|
||||
- name: Build Documentation
|
||||
run: |
|
||||
mkdir -p doc/build
|
||||
cd doc/build
|
||||
cmake ..
|
||||
mkdir -p build
|
||||
cd build
|
||||
cmake -DDISABLE_ALL=ON -DBUILD_DOC=ON ..
|
||||
make doc
|
||||
|
||||
build:
|
||||
|
13
CHANGELOG.md
13
CHANGELOG.md
@ -20,6 +20,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Build
|
||||
- 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
|
||||
- Warn states for the cpu, memory, fs, and battery modules.
|
||||
|
@ -4,22 +4,6 @@
|
||||
cmake_minimum_required(VERSION 3.5.0 FATAL_ERROR)
|
||||
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
|
||||
# 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)
|
||||
@ -46,20 +30,26 @@ set(CMAKE_MODULE_PATH
|
||||
|
||||
include(GNUInstallDirs)
|
||||
include(utils)
|
||||
include(01-core)
|
||||
include(00-components)
|
||||
include(02-opts)
|
||||
if (HAS_CXX_COMPILATION)
|
||||
include(01-core)
|
||||
endif()
|
||||
include(03-libs)
|
||||
include(04-targets)
|
||||
include(05-summary)
|
||||
|
||||
if(BUILD_DOC)
|
||||
add_subdirectory(doc)
|
||||
endif()
|
||||
add_subdirectory(contrib/bash)
|
||||
add_subdirectory(contrib/zsh)
|
||||
if (BUILD_LIBPOLY)
|
||||
add_subdirectory(include)
|
||||
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'
|
||||
# can be run in the build directory
|
||||
@ -68,6 +58,7 @@ if(BUILD_TESTS)
|
||||
add_subdirectory(tests)
|
||||
endif()
|
||||
|
||||
include(05-summary)
|
||||
|
||||
#
|
||||
# Generate configuration file
|
||||
|
2
build.sh
2
build.sh
@ -200,7 +200,7 @@ main() {
|
||||
-DENABLE_MPD:BOOL="${ENABLE_MPD}" \
|
||||
-DENABLE_NETWORK:BOOL="${ENABLE_NETWORK}" \
|
||||
-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 "Building project"
|
||||
|
26
cmake/00-components.cmake
Normal file
26
cmake/00-components.cmake
Normal 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()
|
@ -1,9 +1,26 @@
|
||||
#
|
||||
# Build options
|
||||
#
|
||||
set(SPHINX_FLAGS "" CACHE STRING "Flags to pass to sphinx-build")
|
||||
set(SPHINX_BUILD "sphinx-build" CACHE STRING "Name/Path of the sphinx-build executable to use.")
|
||||
checklib(BUILD_DOC "binary" "${SPHINX_BUILD}")
|
||||
|
||||
if (HAS_CXX_COMPILATION)
|
||||
option(ENABLE_CCACHE "Enable ccache support" ON)
|
||||
if(ENABLE_CCACHE)
|
||||
find_program(BIN_CCACHE ccache)
|
||||
mark_as_advanced(BIN_CCACHE)
|
||||
|
||||
if(NOT BIN_CCACHE)
|
||||
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()
|
||||
|
||||
if (BUILD_LIBPOLY)
|
||||
checklib(ENABLE_ALSA "pkg-config" alsa)
|
||||
checklib(ENABLE_CURL "pkg-config" libcurl)
|
||||
checklib(ENABLE_I3 "binary" i3)
|
||||
@ -22,17 +39,6 @@ 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)
|
||||
set(ENABLE_CCACHE ON)
|
||||
endif()
|
||||
|
||||
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(BUILD_DOC "Build documentation" ON)
|
||||
|
||||
option(ENABLE_ALSA "Enable alsa support" ON)
|
||||
option(ENABLE_CURL "Enable curl support" ON)
|
||||
option(ENABLE_I3 "Enable i3 support" ON)
|
||||
@ -55,6 +61,7 @@ if(CMAKE_BUILD_TYPE_UPPER MATCHES DEBUG)
|
||||
option(DEBUG_WHITESPACE "Debug whitespace" OFF)
|
||||
option(DEBUG_FONTCONFIG "Debug fontconfig" OFF)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
set(SETTING_ALSA_SOUNDCARD "default"
|
||||
CACHE STRING "Name of the ALSA soundcard driver")
|
||||
|
@ -2,6 +2,15 @@
|
||||
# Check libraries
|
||||
#
|
||||
|
||||
if (BUILD_DOC)
|
||||
find_program(BIN_SPHINX "${SPHINX_BUILD}")
|
||||
|
||||
if (NOT BIN_SPHINX)
|
||||
message(FATAL_ERROR "sphinx-build executable '${SPHINX_BUILD}' not found.")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (BUILD_LIBPOLY)
|
||||
find_package(Threads REQUIRED)
|
||||
find_package(CairoFC REQUIRED)
|
||||
|
||||
@ -61,3 +70,4 @@ find_package(Xcb REQUIRED COMPONENTS ${XORG_EXTENSIONS})
|
||||
if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
|
||||
find_package(LibInotify REQUIRED)
|
||||
endif()
|
||||
endif()
|
||||
|
@ -5,8 +5,13 @@
|
||||
message(STATUS " Build:")
|
||||
message_colored(STATUS " Version: ${APP_VERSION}" "32;1")
|
||||
message_colored(STATUS " Type: ${CMAKE_BUILD_TYPE}" "37;2")
|
||||
if (HAS_CXX_COMPILATION)
|
||||
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_colored(STATUS " PREFIX: ${CMAKE_INSTALL_PREFIX}" "32")
|
||||
@ -16,10 +21,12 @@ message_colored(STATUS " DOCDIR: ${CMAKE_INSTALL_FULL_DOCDIR}" "32")
|
||||
message_colored(STATUS " MANDIR: ${CMAKE_INSTALL_FULL_MANDIR}" "32")
|
||||
|
||||
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(" documentation" BUILD_DOC)
|
||||
|
||||
if (BUILD_LIBPOLY)
|
||||
message(STATUS " Module support:")
|
||||
colored_option(" alsa" ENABLE_ALSA ALSA_VERSION)
|
||||
colored_option(" curl" ENABLE_CURL CURL_VERSION)
|
||||
@ -47,3 +54,4 @@ if(CMAKE_BUILD_TYPE_UPPER MATCHES DEBUG)
|
||||
colored_option(" Print fc-match details" DEBUG_FONTCONFIG)
|
||||
colored_option(" Enable window shading" DEBUG_SHADED)
|
||||
endif()
|
||||
endif()
|
||||
|
@ -31,7 +31,7 @@ cmake \
|
||||
-DCMAKE_CXX_FLAGS="${CXXFLAGS} -Werror" \
|
||||
-DCMAKE_BUILD_TYPE="${BUILD_TYPE}" \
|
||||
-DBUILD_TESTS:BOOL="${BUILD_TESTS:-OFF}" \
|
||||
-DBUILD_DOC:BOOL="${BUILD_DOC:-OFF}" \
|
||||
-DBUILD_DOC:BOOL=OFF \
|
||||
-DENABLE_PULSEAUDIO="${ENABLE_PULSEAUDIO:-OFF}" \
|
||||
-DENABLE_NETWORK="${ENABLE_NETWORK:-OFF}" \
|
||||
-DENABLE_MPD="${ENABLE_MPD:-OFF}" \
|
||||
|
@ -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}")
|
||||
|
||||
set(doc_path "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
@ -25,7 +15,7 @@ foreach(builder ${doc_builders})
|
||||
set(doc_target "doc_${builder}")
|
||||
set(builder_log "builder-${builder}.log")
|
||||
add_custom_target(${doc_target}
|
||||
COMMAND ${SPHINX_BUILD}
|
||||
COMMAND ${BIN_SPHINX}
|
||||
-b ${builder}
|
||||
# conf.py dir
|
||||
-c "${CMAKE_CURRENT_BINARY_DIR}"
|
||||
@ -43,19 +33,6 @@ endforeach()
|
||||
# Dummy target that depends on all documentation 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/
|
||||
DESTINATION ${CMAKE_INSTALL_DOCDIR}
|
||||
COMPONENT doc)
|
||||
|
@ -13,9 +13,6 @@ have that installed.
|
||||
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`.
|
||||
|
||||
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
|
||||
only generate the html documentation or the man pages respectively.
|
||||
|
||||
|
@ -13,5 +13,3 @@ configure_file(
|
||||
${CMAKE_CURRENT_LIST_DIR}/settings.hpp.cmake
|
||||
${CMAKE_BINARY_DIR}/generated-sources/settings.hpp
|
||||
ESCAPE_QUOTES)
|
||||
|
||||
set(APP_VERSION ${APP_VERSION} PARENT_SCOPE)
|
||||
|
@ -2,11 +2,12 @@
|
||||
# Configure src
|
||||
#
|
||||
|
||||
# Source tree {{{
|
||||
|
||||
get_include_dirs(includes_dir)
|
||||
get_sources_dirs(src_dir)
|
||||
|
||||
if (BUILD_LIBPOLY)
|
||||
# Source tree {{{
|
||||
|
||||
set(ALSA_SOURCES
|
||||
${src_dir}/adapters/alsa/control.cpp
|
||||
${src_dir}/adapters/alsa/mixer.cpp
|
||||
@ -140,9 +141,8 @@ set(POLY_SOURCES
|
||||
|
||||
# }}}
|
||||
|
||||
# Target: polybar {{{
|
||||
|
||||
add_library(poly STATIC ${POLY_SOURCES})
|
||||
# Target poly {{{
|
||||
add_library(poly STATIC EXCLUDE_FROM_ALL ${POLY_SOURCES})
|
||||
target_include_directories(poly PUBLIC ${includes_dir})
|
||||
target_link_libraries(poly PUBLIC
|
||||
Threads::Threads
|
||||
@ -166,7 +166,10 @@ target_link_libraries(poly PUBLIC
|
||||
|
||||
target_compile_options(poly PUBLIC $<$<CXX_COMPILER_ID:GNU>:$<$<CONFIG:MinSizeRel>:-flto>>)
|
||||
set_target_properties(poly PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/libs)
|
||||
# }}}
|
||||
|
||||
# Target: polybar {{{
|
||||
if (BUILD_POLYBAR)
|
||||
add_executable(polybar main.cpp)
|
||||
target_link_libraries(polybar poly)
|
||||
set_target_properties(poly PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
@ -174,11 +177,12 @@ set_target_properties(poly PROPERTIES RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DI
|
||||
install(TARGETS polybar
|
||||
DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||
COMPONENT runtime)
|
||||
|
||||
endif()
|
||||
# }}}
|
||||
# Target: polybar-msg {{{
|
||||
endif()
|
||||
|
||||
if(BUILD_IPC_MSG)
|
||||
# Target: polybar-msg {{{
|
||||
if(BUILD_POLYBAR_MSG)
|
||||
add_executable(polybar-msg
|
||||
ipc.cpp
|
||||
utils/env.cpp
|
||||
|
@ -6,7 +6,6 @@
|
||||
|
||||
#include "common.hpp"
|
||||
#include "utils/file.hpp"
|
||||
#include "utils/io.hpp"
|
||||
|
||||
using namespace polybar;
|
||||
using namespace std;
|
||||
|
Loading…
Reference in New Issue
Block a user