cmake: Add option to enable/disable sample config

This commit is contained in:
patrick96 2020-12-24 00:56:31 +01:00 committed by Patrick Ziegler
parent ddfec6fc8f
commit 9d47b83697
9 changed files with 112 additions and 107 deletions

1
.gitignore vendored
View File

@ -1,7 +1,6 @@
/build /build
/tags /tags
/compile_commands.json /compile_commands.json
/config
*.bak *.bak
*.pyc *.pyc
*.swp *.swp

View File

@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `BUILD_POLYBAR=ON` - Builds the `polybar` executable - `BUILD_POLYBAR=ON` - Builds the `polybar` executable
- `BUILD_POLYBAR_MSG=ON` - Builds the `polybar-msg` executable - `BUILD_POLYBAR_MSG=ON` - Builds the `polybar-msg` executable
- `BUILD_TESTS=OFF` - Builds the test suite - `BUILD_TESTS=OFF` - Builds the test suite
- `BUILD_CONFIG=ON` - Generate sample config
- `BUILD_DOC=ON` - Builds the documentation - `BUILD_DOC=ON` - Builds the documentation
- `BUILD_DOC_HTML=BUILD_DOC` - Builds the html documentation (depends on `BUILD_DOC`) - `BUILD_DOC_HTML=BUILD_DOC` - Builds the html documentation (depends on `BUILD_DOC`)
- `BUILD_DOC_MAN=BUILD_DOC` - Builds the manpages (depends on `BUILD_DOC`) - `BUILD_DOC_MAN=BUILD_DOC` - Builds the manpages (depends on `BUILD_DOC`)
@ -81,4 +82,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Empty color values are no longer treated as invalid and no longer produce an error. - Empty color values are no longer treated as invalid and no longer produce an error.
[Unreleased]: https://github.com/polybar/polybar/compare/3.5.3...HEAD [Unreleased]: https://github.com/polybar/polybar/compare/3.5.3...HEAD
[3.5.3]: https://github.com/polybar/polybar/releases/tag/3.5.3 [3.5.3]: https://github.com/polybar/polybar/releases/tag/3.5.3

View File

@ -59,96 +59,8 @@ if(BUILD_TESTS)
add_subdirectory(tests) add_subdirectory(tests)
endif() endif()
if (BUILD_CONFIG)
add_subdirectory(config)
endif()
include(05-summary) include(05-summary)
#
# Generate configuration file
#
set(MODULES_LEFT "bspwm i3")
set(MODULES_CENTER "mpd")
set(MODULES_RIGHT "filesystem backlight-acpi alsa pulseaudio 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")
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 {{{
if(NOT ENABLE_PULSEAUDIO)
string(REPLACE " pulseaudio" "" MODULES_RIGHT ${MODULES_RIGHT})
endif()
if(NOT ENABLE_ALSA)
string(REPLACE " alsa" "" MODULES_RIGHT ${MODULES_RIGHT})
endif()
if(NOT ENABLE_I3)
string(REPLACE " i3" "" MODULES_LEFT ${MODULES_LEFT})
endif()
if(NOT ENABLE_MPD)
string(REPLACE "mpd" "" MODULES_CENTER ${MODULES_CENTER})
endif()
if(NOT ENABLE_NETWORK)
string(REPLACE " wlan eth" "" MODULES_RIGHT ${MODULES_RIGHT})
endif()
if(NOT WITH_XKB)
string(REPLACE "xkeyboard " "" MODULES_RIGHT ${MODULES_RIGHT})
endif()
# }}}
# Get battery/adapter name {{{
string(REGEX REPLACE /%battery%.* "" PATH_BAT ${SETTING_PATH_BATTERY})
string(REGEX REPLACE /%adapter%.* "" PATH_ADP ${SETTING_PATH_ADAPTER})
file(GLOB BAT_LIST RELATIVE ${PATH_BAT} ${PATH_ADP}/B*)
file(GLOB ADP_LIST RELATIVE ${PATH_ADP} ${PATH_ADP}/A*)
if(BAT_LIST)
list(GET BAT_LIST 0 BATTERY)
else()
set(BATTERY BAT0)
endif()
if(ADP_LIST)
list(GET ADP_LIST 0 ADAPTER)
else()
set(ADAPTER ADP1)
endif()
# }}}
# Get network interfaces {{{
if(ENABLE_NETWORK)
file(GLOB IFLIST RELATIVE /sys/class/net /sys/class/net/*)
foreach(INTERFACE ${IFLIST})
if(NOT ${INTERFACE} STREQUAL "lo")
file(GLOB IS_WIRELESS /sys/class/net/${INTERFACE}/wireless)
if(IS_WIRELESS)
set(INTERFACE_WLAN ${INTERFACE})
else()
set(INTERFACE_ETH ${INTERFACE})
endif()
endif()
endforeach()
if(NOT INTERFACE_ETH)
set(INTERFACE_ETH net0)
endif()
if(NOT INTERFACE_WLAN)
set(INTERFACE_WLAN net1)
endif()
endif()
# }}}
# Configure and install {{{
configure_file(
${CMAKE_CURRENT_LIST_DIR}/config.cmake
${CMAKE_CURRENT_LIST_DIR}/config
ESCAPE_QUOTES @ONLY)
install(FILES config
DESTINATION ${CMAKE_INSTALL_DOCDIR}
COMPONENT config)
# }}}

View File

@ -15,6 +15,7 @@ option(BUILD_POLYBAR "Build the main polybar executable" ${DEFAULT_ON})
option(BUILD_POLYBAR_MSG "Build polybar-msg" ${DEFAULT_ON}) option(BUILD_POLYBAR_MSG "Build polybar-msg" ${DEFAULT_ON})
option(BUILD_TESTS "Build testsuite" OFF) option(BUILD_TESTS "Build testsuite" OFF)
option(BUILD_DOC "Build documentation" ${DEFAULT_ON}) option(BUILD_DOC "Build documentation" ${DEFAULT_ON})
option(BUILD_CONFIG "Generate sample configuration" ${DEFAULT_ON})
include(CMakeDependentOption) include(CMakeDependentOption)
CMAKE_DEPENDENT_OPTION(BUILD_DOC_HTML "Build HTML documentation" ON "BUILD_DOC" OFF) CMAKE_DEPENDENT_OPTION(BUILD_DOC_HTML "Build HTML documentation" ON "BUILD_DOC" OFF)

View File

@ -2,18 +2,6 @@
# Custom targets # Custom targets
# #
# Target: userconfig {{{
configure_file(
${PROJECT_SOURCE_DIR}/cmake/templates/userconfig.cmake.in
${PROJECT_BINARY_DIR}/cmake/userconfig.cmake
ESCAPE_QUOTES @ONLY)
add_custom_target(userconfig
DEPENDS ${PROJECT_NAME}
COMMAND ${CMAKE_COMMAND} -P ${PROJECT_BINARY_DIR}/cmake/userconfig.cmake)
# }}}
# Target: uninstall {{{ # Target: uninstall {{{
configure_file( configure_file(

View File

@ -27,6 +27,7 @@ colored_option(" testsuite" BUILD_TESTS)
colored_option(" documentation" BUILD_DOC) colored_option(" documentation" BUILD_DOC)
colored_option(" html" BUILD_DOC_HTML) colored_option(" html" BUILD_DOC_HTML)
colored_option(" man" BUILD_DOC_MAN) colored_option(" man" BUILD_DOC_MAN)
colored_option(" sample config" BUILD_CONFIG)
if (BUILD_LIBPOLY) if (BUILD_LIBPOLY)
message(STATUS " Module support:") message(STATUS " Module support:")

View File

@ -4,5 +4,5 @@ if(NOT USER_CONFIG_HOME)
endif() endif()
set(USER_CONFIG_HOME "${USER_CONFIG_HOME}/polybar") set(USER_CONFIG_HOME "${USER_CONFIG_HOME}/polybar")
file(INSTALL "@CMAKE_SOURCE_DIR@/config" file(INSTALL "@CMAKE_BINARY_DIR@/generated-sources/config"
DESTINATION "${USER_CONFIG_HOME}") DESTINATION "${USER_CONFIG_HOME}")

103
config/CMakeLists.txt Normal file
View File

@ -0,0 +1,103 @@
#
# Generate configuration file
#
set(MODULES_LEFT "bspwm i3")
set(MODULES_CENTER "mpd")
set(MODULES_RIGHT "filesystem backlight-acpi alsa pulseaudio 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")
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 {{{
if(NOT ENABLE_PULSEAUDIO)
string(REPLACE " pulseaudio" "" MODULES_RIGHT ${MODULES_RIGHT})
endif()
if(NOT ENABLE_ALSA)
string(REPLACE " alsa" "" MODULES_RIGHT ${MODULES_RIGHT})
endif()
if(NOT ENABLE_I3)
string(REPLACE " i3" "" MODULES_LEFT ${MODULES_LEFT})
endif()
if(NOT ENABLE_MPD)
string(REPLACE "mpd" "" MODULES_CENTER ${MODULES_CENTER})
endif()
if(NOT ENABLE_NETWORK)
string(REPLACE " wlan eth" "" MODULES_RIGHT ${MODULES_RIGHT})
endif()
if(NOT WITH_XKB)
string(REPLACE "xkeyboard " "" MODULES_RIGHT ${MODULES_RIGHT})
endif()
# }}}
# Get battery/adapter name {{{
string(REGEX REPLACE /%battery%.* "" PATH_BAT ${SETTING_PATH_BATTERY})
string(REGEX REPLACE /%adapter%.* "" PATH_ADP ${SETTING_PATH_ADAPTER})
file(GLOB BAT_LIST RELATIVE ${PATH_BAT} ${PATH_ADP}/B*)
file(GLOB ADP_LIST RELATIVE ${PATH_ADP} ${PATH_ADP}/A*)
if(BAT_LIST)
list(GET BAT_LIST 0 BATTERY)
else()
set(BATTERY BAT0)
endif()
if(ADP_LIST)
list(GET ADP_LIST 0 ADAPTER)
else()
set(ADAPTER ADP1)
endif()
# }}}
# Get network interfaces {{{
if(ENABLE_NETWORK)
file(GLOB IFLIST RELATIVE /sys/class/net /sys/class/net/*)
foreach(INTERFACE ${IFLIST})
if(NOT ${INTERFACE} STREQUAL "lo")
file(GLOB IS_WIRELESS /sys/class/net/${INTERFACE}/wireless)
if(IS_WIRELESS)
set(INTERFACE_WLAN ${INTERFACE})
else()
set(INTERFACE_ETH ${INTERFACE})
endif()
endif()
endforeach()
if(NOT INTERFACE_ETH)
set(INTERFACE_ETH net0)
endif()
if(NOT INTERFACE_WLAN)
set(INTERFACE_WLAN net1)
endif()
endif()
# }}}
# Configure and install {{{
configure_file(
${CMAKE_CURRENT_LIST_DIR}/config.cmake
${CMAKE_BINARY_DIR}/generated-sources/config
ESCAPE_QUOTES @ONLY)
install(FILES ${CMAKE_BINARY_DIR}/generated-sources/config
DESTINATION ${CMAKE_INSTALL_DOCDIR}
COMPONENT config)
# }}}
# Target: userconfig {{{
configure_file(
${PROJECT_SOURCE_DIR}/cmake/templates/userconfig.cmake.in
${PROJECT_BINARY_DIR}/cmake/userconfig.cmake
ESCAPE_QUOTES @ONLY)
add_custom_target(userconfig
COMMAND ${CMAKE_COMMAND} -P ${PROJECT_BINARY_DIR}/cmake/userconfig.cmake)
# }}}