From 31fafa86f7a787a6c8f5a75c304067943f92b8d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20BOULMIER?= Date: Sat, 15 Jun 2019 11:12:57 -0400 Subject: [PATCH] feat(cmake): removing globs and using imported targets --- cmake/03-libs.cmake | 63 ++++++--- cmake/modules/FindCairoFC.cmake | 31 +++++ cmake/modules/FindLibInotify.cmake | 26 ++++ cmake/modules/FindLibMPDClient.cmake | 22 +++ cmake/modules/FindLibNlGenl3.cmake | 17 +++ cmake/modules/FindLibPulse.cmake | 23 ++++ cmake/modules/FindLibiw.cmake | 9 +- cmake/modules/FindXcb.cmake | 53 ++++++++ lib/CMakeLists.txt | 7 +- src/CMakeLists.txt | 195 +++++++++++++++++++-------- 10 files changed, 368 insertions(+), 78 deletions(-) create mode 100644 cmake/modules/FindCairoFC.cmake create mode 100644 cmake/modules/FindLibInotify.cmake create mode 100644 cmake/modules/FindLibMPDClient.cmake create mode 100644 cmake/modules/FindLibNlGenl3.cmake create mode 100644 cmake/modules/FindLibPulse.cmake create mode 100644 cmake/modules/FindXcb.cmake diff --git a/cmake/03-libs.cmake b/cmake/03-libs.cmake index 1d620e90..31aff535 100644 --- a/cmake/03-libs.cmake +++ b/cmake/03-libs.cmake @@ -3,28 +3,55 @@ # find_package(Threads REQUIRED) -list(APPEND libs ${CMAKE_THREAD_LIBS_INIT}) +find_package(CairoFC REQUIRED) -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) -if(WITH_LIBNL) - querylib(ENABLE_NETWORK "pkg-config" libnl-genl-3.0 libs dirs) -else() - querylib(ENABLE_NETWORK "cmake" Libiw libs dirs) +if (ENABLE_ALSA) + find_package(ALSA REQUIRED) endif() -querylib(ENABLE_PULSEAUDIO "pkg-config" libpulse libs dirs) -querylib(WITH_XCOMPOSITE "pkg-config" xcb-composite 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" "xcb-randr>=1.12" libs dirs) -querylib(WITH_XRM "pkg-config" xcb-xrm libs dirs) -querylib(WITH_XCURSOR "pkg-config" xcb-cursor libs dirs) +if (ENABLE_CURL) + find_package(CURL REQUIRED) +endif() + +if (ENABLE_MPD) + find_package(LibMPDClient REQUIRED) +endif() + +if (ENABLE_NETWORK) + if(WITH_LIBNL) + find_package(LibNlGenl3 REQUIRED) + else() + find_package(Libiw REQUIRED) + endif() +endif() + +if (ENABLE_PULSEAUDIO) + find_package(LibPulse REQUIRED) +endif() + +# Randr is required +set(XORG_EXTENSIONS RANDR) +if (WITH_XCOMPOSITE) + set(XORG_EXTENSIONS ${XORG_EXTENSIONS} COMPOSITE) +endif() +if (WITH_XKB) + set(XORG_EXTENSIONS ${XORG_EXTENSIONS} XKB) +endif() +if (WITH_XCURSOR) + set(XORG_EXTENSIONS ${XORG_EXTENSIONS} CURSOR) +endif() +if (WITH_XRM) + set(XORG_EXTENSIONS ${XORG_EXTENSIONS} XRM) +endif() + +set(XCB_VERSION "") +if (WITH_XRANDR_MONITOR) + set(XCB_VERSION "1.12") +endif() + +find_package(Xcb ${XCB_VERSION} REQUIRED COMPONENTS ${XORG_EXTENSIONS}) # FreeBSD Support if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") - querylib(TRUE "pkg-config" libinotify libs dirs) + find_package(LibInotify REQUIRED) endif() diff --git a/cmake/modules/FindCairoFC.cmake b/cmake/modules/FindCairoFC.cmake new file mode 100644 index 00000000..f18d7626 --- /dev/null +++ b/cmake/modules/FindCairoFC.cmake @@ -0,0 +1,31 @@ +find_package(PkgConfig REQUIRED) +include(CMakeFindDependencyMacro) + +pkg_check_modules(PC_CairoFC QUIET cairo-fc) + +set(CairoFC_INCLUDE_DIR ${PC_CairoFC_INCLUDE_DIRS}) +set(CairoFC_LIBRARY ${PC_CairoFC_LIBRARIES}) + +include(FindPackageHandleStandardArgs) +# handle the QUIETLY and REQUIRED arguments and set CairoFC_FOUND to TRUE +# if all listed variables are TRUE +find_package_handle_standard_args(CairoFC + REQUIRED_VARS + CairoFC_INCLUDE_DIR + CairoFC_LIBRARY + VERSION_VAR + PC_CairoFC_VERSION) +message(STATUS "${CairoFC}") + +mark_as_advanced(CairoFC_INCLUDE_DIR CairoFC_LIBRARY) + +set(CairoFC_LIBRARIES ${CairoFC_LIBRARY}) +set(CairoFC_INCLUDE_DIRS ${CairoFC_INCLUDE_DIR}) + +if(CairoFC_FOUND AND NOT TARGET Cairo::CairoFC) + add_library(Cairo::CairoFC INTERFACE IMPORTED) + set_target_properties(Cairo::CairoFC PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${CairoFC_INCLUDE_DIRS}" + INTERFACE_LINK_LIBRARIES "${CairoFC_LIBRARIES}" + ) +endif() diff --git a/cmake/modules/FindLibInotify.cmake b/cmake/modules/FindLibInotify.cmake new file mode 100644 index 00000000..038a1c8b --- /dev/null +++ b/cmake/modules/FindLibInotify.cmake @@ -0,0 +1,26 @@ +function(libinotify) + find_package(PkgConfig REQUIRED) + pkg_check_modules(PC_LibInotify QUIET libinotify) + + include(FindPackageHandleStandardArgs) + + find_path(LibInotify_INCLUDES + NAMES netlink/version.h + HINTS ${PC_LibInotify_INCLUDEDIR} ${PC_LibInotify_INCLUDE_DIRS} + ) + + find_package_handle_standard_args(LibInotify + REQUIRED_VARS PC_LibInotify_INCLUDE_DIRS + VERSION_VAR PC_LibInotify_VERSION + ) + + if(LibInotify_FOUND AND NOT TARGET LibInotify::LibInotify) + add_library(LibInotify::LibInotify INTERFACE IMPORTED) + set_target_properties(LibInotify::LibInotify PROPERTIES + INTERFACE_LINK_LIBRARIES "${PC_LibInotify_LIBRARIES}") + + target_include_directories(LibInotify::LibInotify SYSTEM INTERFACE ${LibInotify_INCLUDES}) + endif() +endfunction() + +libinotify() diff --git a/cmake/modules/FindLibMPDClient.cmake b/cmake/modules/FindLibMPDClient.cmake new file mode 100644 index 00000000..1599a4fe --- /dev/null +++ b/cmake/modules/FindLibMPDClient.cmake @@ -0,0 +1,22 @@ +find_package(PkgConfig REQUIRED) +pkg_check_modules(PC_LibMPDClient QUIET libmpdclient) + +include(FindPackageHandleStandardArgs) + +find_path(LibMPDClient_INCLUDES + NAMES mpd/player.h + HINTS ${PC_LibMPDClient_INCLUDEDIR} ${PC_LibMPDClient_INCLUDE_DIRS} + ) + +find_package_handle_standard_args(LibMPDClient + REQUIRED_VARS LibMPDClient_INCLUDES + VERSION_VAR PC_LibMPDClient_VERSION + ) + +if(LibMPDClient_FOUND AND NOT TARGET LibMPDClient::LibMPDClient) + add_library(LibMPDClient::LibMPDClient INTERFACE IMPORTED) + set_target_properties(LibMPDClient::LibMPDClient PROPERTIES + INTERFACE_LINK_LIBRARIES "${PC_LibMPDClient_LIBRARIES}") + + target_include_directories(LibMPDClient::LibMPDClient SYSTEM INTERFACE ${LibMPDClient_INCLUDES}) +endif() diff --git a/cmake/modules/FindLibNlGenl3.cmake b/cmake/modules/FindLibNlGenl3.cmake new file mode 100644 index 00000000..1a86972c --- /dev/null +++ b/cmake/modules/FindLibNlGenl3.cmake @@ -0,0 +1,17 @@ +find_package(PkgConfig REQUIRED) +pkg_check_modules(PC_LibNlGenl3 QUIET libnl-genl-3.0) + +include(FindPackageHandleStandardArgs) + +find_package_handle_standard_args(LibNlGenl3 + REQUIRED_VARS PC_LibNlGenl3_INCLUDE_DIRS + VERSION_VAR PC_LibNlGenl3_VERSION +) + +if(LibNlGenl3_FOUND AND NOT TARGET LibNlGenl3::LibNlGenl3) + add_library(LibNlGenl3::LibNlGenl3 INTERFACE IMPORTED) + + set_target_properties(LibNlGenl3::LibNlGenl3 PROPERTIES + INTERFACE_LINK_LIBRARIES "${PC_LibNlGenl3_LIBRARIES}") + target_include_directories(LibNlGenl3::LibNlGenl3 SYSTEM INTERFACE ${PC_LibNlGenl3_INCLUDE_DIRS}) +endif() diff --git a/cmake/modules/FindLibPulse.cmake b/cmake/modules/FindLibPulse.cmake new file mode 100644 index 00000000..a15ac00f --- /dev/null +++ b/cmake/modules/FindLibPulse.cmake @@ -0,0 +1,23 @@ + +find_package(PkgConfig REQUIRED) +pkg_check_modules(PC_LibPulse QUIET libpulse) + +include(FindPackageHandleStandardArgs) + +find_path(LibPulse_INCLUDES + NAMES pulse/version.h + HINTS ${PC_LibPulse_INCLUDEDIR} ${PC_LibPulse_INCLUDE_DIRS} +) + +find_package_handle_standard_args(LibPulse + REQUIRED_VARS LibPulse_INCLUDES + VERSION_VAR PC_LibPulse_VERSION +) + +if(LibPulse_FOUND AND NOT TARGET LibPulse::LibPulse) + add_library(LibPulse::LibPulse INTERFACE IMPORTED) + set_target_properties(LibPulse::LibPulse PROPERTIES + INTERFACE_LINK_LIBRARIES "${PC_LibPulse_LIBRARIES}") + + target_include_directories(LibPulse::LibPulse SYSTEM INTERFACE ${LibPulse_INCLUDES}) +endif() diff --git a/cmake/modules/FindLibiw.cmake b/cmake/modules/FindLibiw.cmake index c69b941d..bab2adb9 100644 --- a/cmake/modules/FindLibiw.cmake +++ b/cmake/modules/FindLibiw.cmake @@ -6,7 +6,7 @@ find_library(LIBIW_LIBRARY iw) if(LIBIW_LIBRARY) - set(LIBIW_LIBRARIES ${LIBIW_LIBRARY}) + set(LIBIW_LIBRARIES ${LIBIW_LIBRARY}) endif(LIBIW_LIBRARY) find_path(LIBIW_INCLUDE_DIR NAMES iwlib.h) @@ -15,3 +15,10 @@ include(FindPackageHandleStandardArgs) find_package_handle_standard_args(Libiw DEFAULT_MSG LIBIW_LIBRARY LIBIW_INCLUDE_DIR) mark_as_advanced(LIBIW_INCLUDE_DIR LIBIW_LIBRARY) + +if(Libiw_FOUND AND NOT TARGET Libiw::Libiw) + add_library(Libiw::Libiw INTERFACE IMPORTED) + set_target_properties(Libiw::Libiw PROPERTIES + INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${LIBIW_INCLUDE_DIR}" + INTERFACE_LINK_LIBRARIES "${LIBIW_LIBRARY}") +endif() diff --git a/cmake/modules/FindXcb.cmake b/cmake/modules/FindXcb.cmake new file mode 100644 index 00000000..b04e3158 --- /dev/null +++ b/cmake/modules/FindXcb.cmake @@ -0,0 +1,53 @@ +cmake_policy(PUSH) +cmake_policy(SET CMP0057 NEW) + +set(XCB_known_components + XCB + RANDR + COMPOSITE + XKB + XRM + CURSOR) + +foreach(_comp ${XCB_known_components}) + string(TOLOWER "${_comp}" _lc_comp) + set(XCB_${_comp}_pkg_config "xcb-${_lc_comp}") + set(XCB_${_comp}_header "xcb/${_lc_comp}.h") +endforeach() +set(XCB_XRM_header "xcb/xcb_xrm.h") +set(XCB_CURSOR_header "xcb/xcb_cursor.h") + +find_package(PkgConfig REQUIRED) +include(FindPackageHandleStandardArgs) + +foreach(_comp ${Xcb_FIND_COMPONENTS}) + if (NOT ${_comp} IN_LIST XCB_known_components) + cmake_policy(POP) + message(FATAL_ERROR "Unknow component ${_comp} for XCB") + endif() + + pkg_check_modules(PC_${_comp} QUIET ${XCB_${_comp}_pkg_config}) + + find_path(${_comp}_INCLUDES_DIRS + NAMES "${XCB_${_comp}_header}" + HINTS ${PC_${_comp}_INCLUDEDIR} ${PC_${_comp}_INCLUDE_DIRS} + ) + + find_package_handle_standard_args(Xcb_${_comp} + REQUIRED_VARS ${_comp}_INCLUDES_DIRS + VERSION_VAR PC_${_comp}_VERSION + HANDLE_COMPONENTS + ) + + if(Xcb_${_comp}_FOUND AND NOT TARGET Xcb::${_comp}) + add_library(Xcb::${_comp} INTERFACE IMPORTED) + set_target_properties(Xcb::${_comp} PROPERTIES + INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${_comp}_INCLUDES" + INTERFACE_LINK_LIBRARIES "${PC_${_comp}_LIBRARIES}" + ) + elseif(NOT Xcb_${_comp}_FOUND AND Xcb_FIND_REQUIRED) + message(FATAL_ERROR "Xcb: Required component \"${component}\" is not found") + endif() +endforeach() + +cmake_policy(POP) diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index b74af3bc..a49f37ab 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -4,10 +4,8 @@ # Library: concurrentqueue {{{ -add_library(concurrentqueue INTERFACE) -target_include_directories(concurrentqueue INTERFACE - $) -list(APPEND libs concurrentqueue) +add_library(moodycamel INTERFACE) +target_include_directories(moodycamel SYSTEM INTERFACE ${CMAKE_CURRENT_LIST_DIR}/concurrentqueue/include) # }}} # Library: xpp {{{ @@ -25,7 +23,6 @@ if(WITH_XKB) endif() add_subdirectory(xpp) -list(APPEND libs xpp) # }}} # Library: i3ipcpp {{{ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 342e2e53..70d07b4f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,71 +4,158 @@ # Source tree {{{ -file(GLOB_RECURSE files RELATIVE ${CMAKE_CURRENT_LIST_DIR} *.c[p]*) -list(REMOVE_ITEM files main.cpp ipc.cpp) +get_filename_component(generated_sources_dir ${CMAKE_BINARY_DIR}/generated-sources ABSOLUTE) +get_filename_component(include_dir ${CMAKE_SOURCE_DIR}/include ABSOLUTE) +get_filename_component(src_dir ${CMAKE_CURRENT_SOURCE_DIR} ABSOLUTE) + +set(ALSA_SOURCES + ${src_dir}/adapters/alsa/control.cpp + ${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(I3_SOURCES + ${src_dir}/modules/i3.cpp + ${src_dir}/utils/i3.cpp +) + +set(MPD_SOURCES + ${src_dir}/adapters/mpd.cpp + ${src_dir}/modules/mpd.cpp +) + +set(NETWORK_SOURCES + ${src_dir}/adapters/net.cpp + ${src_dir}/modules/network.cpp + $,${src_dir}/adapters/net_nl.cpp,${src_dir}/adapters/net_iw.cpp> +) + + +set(PULSEAUDIO_SOURCES + ${src_dir}/adapters/pulseaudio.cpp + ${src_dir}/modules/pulseaudio.cpp +) + +set(XCOMPOSITE_SOURCES ${src_dir}/x11/extensions/composite.cpp) + +set(XCURSOR_SOURCES ${src_dir}/x11/cursor.cpp) + +set(XKB_SOURCES + ${src_dir}/modules/xkeyboard.cpp + ${src_dir}/x11/extensions/xkb.cpp +) + +set(XRM_SOURCES ${src_dir}/x11/xresources.cpp) configure_file( ${CMAKE_CURRENT_LIST_DIR}/settings.cpp.cmake ${CMAKE_BINARY_DIR}/generated-sources/settings.cpp ESCAPE_QUOTES) -list(APPEND files ${CMAKE_BINARY_DIR}/generated-sources/settings.cpp) +set(POLY_SOURCES + ${CMAKE_BINARY_DIR}/generated-sources/settings.cpp + ${src_dir}/cairo/utils.cpp + ${src_dir}/components/bar.cpp + ${src_dir}/components/builder.cpp + ${src_dir}/components/command_line.cpp + ${src_dir}/components/config.cpp + ${src_dir}/components/controller.cpp + ${src_dir}/components/ipc.cpp + ${src_dir}/components/logger.cpp + ${src_dir}/components/parser.cpp + ${src_dir}/components/renderer.cpp + ${src_dir}/components/screen.cpp + ${src_dir}/components/taskqueue.cpp + ${src_dir}/drawtypes/animation.cpp + ${src_dir}/drawtypes/iconset.cpp + ${src_dir}/drawtypes/label.cpp + ${src_dir}/drawtypes/progressbar.cpp + ${src_dir}/drawtypes/ramp.cpp + ${src_dir}/events/signal_emitter.cpp + ${src_dir}/events/signal_receiver.cpp + ${src_dir}/modules/backlight.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/bspwm.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}/x11/background_manager.cpp + ${src_dir}/x11/connection.cpp + ${src_dir}/x11/ewmh.cpp + ${src_dir}/x11/extensions/randr.cpp + ${src_dir}/x11/icccm.cpp + ${src_dir}/x11/registry.cpp + ${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 + + $<$:${ALSA_SOURCES}> + $<$:${GITHUB_SOURCES}> + $<$:${I3_SOURCES}> + $<$:${MPD_SOURCES}> + $<$:${NETWORK_SOURCES}> + $<$:${PULSEAUDIO_SOURCES}> + $<$:${XCOMPOSITE_SOURCES}> + $<$:${XCURSOR_SOURCES}> + $<$:${XKB_SOURCES}> + $<$:${XRM_SOURCES}> +) -if(NOT ENABLE_ALSA) - list(REMOVE_ITEM files modules/alsa.cpp) - list(REMOVE_ITEM files adapters/alsa/control.cpp) - list(REMOVE_ITEM files adapters/alsa/mixer.cpp) -endif() -if(NOT ENABLE_CURL) - list(REMOVE_ITEM files modules/github.cpp) - list(REMOVE_ITEM files utils/http.cpp) -endif() -if(NOT ENABLE_MPD) - list(REMOVE_ITEM files modules/mpd.cpp) - list(REMOVE_ITEM files adapters/mpd.cpp) -endif() -if(NOT ENABLE_NETWORK) - list(REMOVE_ITEM files modules/network.cpp) - list(REMOVE_ITEM files adapters/net.cpp) - list(REMOVE_ITEM files adapters/net_iw.cpp) - list(REMOVE_ITEM files adapters/net_nl.cpp) -endif() -if(WITH_LIBNL) - list(REMOVE_ITEM files adapters/net_iw.cpp) -else() - list(REMOVE_ITEM files adapters/net_nl.cpp) -endif() -if(NOT ENABLE_I3) - list(REMOVE_ITEM files modules/i3.cpp) - list(REMOVE_ITEM files utils/i3.cpp) -endif() -if(NOT ENABLE_PULSEAUDIO) - list(REMOVE_ITEM files modules/pulseaudio.cpp) - list(REMOVE_ITEM files adapters/pulseaudio.cpp) -endif() -if(NOT WITH_XRANDR) - list(REMOVE_ITEM files x11/extensions/randr.cpp) -endif() -if(NOT WITH_XCOMPOSITE) - list(REMOVE_ITEM files x11/extensions/composite.cpp) -endif() -if(NOT WITH_XKB) - list(REMOVE_ITEM files x11/extensions/xkb.cpp) - list(REMOVE_ITEM files modules/xkeyboard.cpp) -endif() -if(NOT WITH_XRM) - list(REMOVE_ITEM files x11/xresources.cpp) -endif() -if(NOT WITH_XCURSOR) - list(REMOVE_ITEM files x11/cursor.cpp) -endif() # }}} # Target: polybar {{{ -add_library(poly STATIC ${files}) -target_include_directories(poly PUBLIC ${dirs}) -target_link_libraries(poly ${libs} Threads::Threads) +add_library(poly STATIC ${POLY_SOURCES}) +target_include_directories(poly PUBLIC ${include_dir} ${generated_sources_dir}) +target_link_libraries(poly PUBLIC + Threads::Threads + Cairo::CairoFC + moodycamel + xpp + $<$:i3ipc++> + $<$:ALSA::ALSA> + $<$:CURL::libcurl> + $<$:LibMPDClient::LibMPDClient> + $<$:LibNlGenl3::LibNlGenl3> + $<$:Libiw::Libiw> + $<$:LibPulse::LibPulse> + $<$:Xcb::RANDR> + $<$:Xcb::COMPOSITE> + $<$:Xcb::XKB> + $<$:Xcb::CURSOR> + $<$:Xcb::XRM> + $<$:LibInotify::LibInotify> +) + target_compile_options(poly PUBLIC $<$:$<$:-flto>>) add_executable(polybar main.cpp)