From ce6ac7869e7e09261be7d10f31cf9c14bbf967e3 Mon Sep 17 00:00:00 2001 From: Chase Geigle Date: Mon, 3 Sep 2018 14:05:39 -0500 Subject: [PATCH] refactor(cmake): Use a source list instead of static libs --- cmake/common/utils.cmake | 10 ++++++++++ src/CMakeLists.txt | 19 +++---------------- src/cairo/CMakeLists.txt | 11 +---------- src/components/CMakeLists.txt | 12 ++++++++++++ src/drawtypes/CMakeLists.txt | 11 ++--------- src/events/CMakeLists.txt | 9 ++------- src/modules/CMakeLists.txt | 3 +-- src/utils/CMakeLists.txt | 22 +++------------------- src/x11/CMakeLists.txt | 28 +++++++++------------------- tests/CMakeLists.txt | 5 +++-- 10 files changed, 46 insertions(+), 84 deletions(-) create mode 100644 src/components/CMakeLists.txt diff --git a/cmake/common/utils.cmake b/cmake/common/utils.cmake index 660385f7..317d92c3 100644 --- a/cmake/common/utils.cmake +++ b/cmake/common/utils.cmake @@ -191,6 +191,16 @@ endfunction() # }}} +# add_sources {{{ +macro(add_sources varname) + foreach(SRC ${ARGN}) + list(APPEND ${varname} ${CMAKE_CURRENT_SOURCE_DIR}/${SRC}) + endforeach() + set(${varname} ${${varname}} PARENT_SCOPE) +endmacro() + +# }}} + # queryfont {{{ function(queryfont output_variable fontname) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a5f71495..7d4add6b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -6,6 +6,7 @@ # Source tree {{{ add_subdirectory(cairo) +add_subdirectory(components) add_subdirectory(drawtypes) add_subdirectory(events) add_subdirectory(modules) @@ -19,28 +20,14 @@ add_subdirectory(x11) make_executable(polybar SOURCES main.cpp - components/bar.cpp - components/builder.cpp - components/command_line.cpp - components/config.cpp - components/controller.cpp - components/ipc.cpp - components/logger.cpp - components/parser.cpp - components/renderer.cpp - components/screen.cpp - components/taskqueue.cpp + ${files} INCLUDE_DIRS ${dirs} TARGET_DEPENDS polybar-modules-internal_shared - polybar-cairo_static - polybar-drawtypes_static - polybar-events_static - polybar-utils_static - polybar-x11_static RAW_DEPENDS ${libs} + ${CMAKE_DL_LIBS} Threads::Threads) target_compile_options(polybar PUBLIC $<$:$<$:-flto>>) diff --git a/src/cairo/CMakeLists.txt b/src/cairo/CMakeLists.txt index 590e3b52..59594f0d 100644 --- a/src/cairo/CMakeLists.txt +++ b/src/cairo/CMakeLists.txt @@ -1,10 +1 @@ -make_library(polybar-cairo - STATIC - INTERNAL - SOURCES - utils.cpp - INCLUDE_DIRS - ${dirs} - ${cairo-dirs} - RAW_DEPENDS - ${cairo-libs}) +add_sources(files utils.cpp) diff --git a/src/components/CMakeLists.txt b/src/components/CMakeLists.txt new file mode 100644 index 00000000..d730c201 --- /dev/null +++ b/src/components/CMakeLists.txt @@ -0,0 +1,12 @@ +add_sources(files + bar.cpp + builder.cpp + command_line.cpp + config.cpp + controller.cpp + ipc.cpp + logger.cpp + parser.cpp + renderer.cpp + screen.cpp + taskqueue.cpp) diff --git a/src/drawtypes/CMakeLists.txt b/src/drawtypes/CMakeLists.txt index 3305308d..ccc4f834 100644 --- a/src/drawtypes/CMakeLists.txt +++ b/src/drawtypes/CMakeLists.txt @@ -1,13 +1,6 @@ -make_library(polybar-drawtypes - STATIC - INTERNAL - SOURCES +add_sources(files animation.cpp iconset.cpp label.cpp progressbar.cpp - ramp.cpp - INCLUDE_DIRS - ${dirs} - RAW_DEPENDS - ${libs}) + ramp.cpp) diff --git a/src/events/CMakeLists.txt b/src/events/CMakeLists.txt index 5a3c1d25..edb10ace 100644 --- a/src/events/CMakeLists.txt +++ b/src/events/CMakeLists.txt @@ -1,8 +1,3 @@ -make_library(polybar-events - STATIC - INTERNAL - SOURCES +add_sources(files signal_emitter.cpp - signal_receiver.cpp - INCLUDE_DIRS - ${dirs}) + signal_receiver.cpp) diff --git a/src/modules/CMakeLists.txt b/src/modules/CMakeLists.txt index 64e31dff..ec7cf83f 100644 --- a/src/modules/CMakeLists.txt +++ b/src/modules/CMakeLists.txt @@ -120,5 +120,4 @@ make_library(polybar-modules-internal INCLUDE_DIRS ${dirs} RAW_DEPENDS - ${libs} - polybar-utils-bspwm_shared) + ${libs}) diff --git a/src/utils/CMakeLists.txt b/src/utils/CMakeLists.txt index 7a8a2bfd..c965988b 100644 --- a/src/utils/CMakeLists.txt +++ b/src/utils/CMakeLists.txt @@ -1,7 +1,5 @@ -make_library(polybar-utils - STATIC - INTERNAL - SOURCES +add_sources(files + bspwm.cpp command.cpp concurrency.cpp env.cpp @@ -14,21 +12,7 @@ make_library(polybar-utils restack.cpp socket.cpp string.cpp - throttle.cpp - INCLUDE_DIRS - ${dirs} - RAW_DEPENDS - ${libs} - ${CMAKE_DL_LIBS}) - -make_library(polybar-utils-bspwm - SHARED - SOURCES - bspwm.cpp - INCLUDE_DIRS - ${dirs} - RAW_DEPENDS - ${libs}) + throttle.cpp) if(ENABLE_I3) make_library(polybar-utils-i3 diff --git a/src/x11/CMakeLists.txt b/src/x11/CMakeLists.txt index c5044844..02b83b0b 100644 --- a/src/x11/CMakeLists.txt +++ b/src/x11/CMakeLists.txt @@ -1,4 +1,4 @@ -list(APPEND x11-sources +add_sources(files atoms.cpp connection.cpp ewmh.cpp @@ -11,36 +11,26 @@ list(APPEND x11-sources xembed.cpp) if(WITH_XRANDR) - list(APPEND x11-sources extensions/randr.cpp) + add_sources(files extensions/randr.cpp) endif() if(WITH_XRENDER) - list(APPEND x11-sources extensions/render.cpp) + add_sources(files extensions/render.cpp) endif() if(WITH_XDAMAGE) - list(APPEND x11-sources extensions/damage.cpp) + add_sources(files extensions/damage.cpp) endif() if(WITH_XSYNC) - list(APPEND x11-sources extensions/sync.cpp) + add_sources(files extensions/sync.cpp) endif() if(WITH_XCOMPOSITE) - list(APPEND x11-sources extensions/composite.cpp) + add_sources(files extensions/composite.cpp) endif() if(WITH_XKB) - list(APPEND x11-sources extensions/xkb.cpp) + add_sources(files extensions/xkb.cpp) endif() if(WITH_XRM) - list(APPEND x11-sources xresources.cpp) + add_sources(files xresources.cpp) endif() if(WITH_XCURSOR) - list(APPEND x11-sources cursor.cpp) + add_sources(files cursor.cpp) endif() - -make_library(polybar-x11 - STATIC - INTERNAL - SOURCES - ${x11-sources} - INCLUDE_DIRS - ${dirs} - RAW_DEPENDS - ${libs}) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b3efec93..4261b390 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -47,9 +47,10 @@ function(unit_test file tests) # unit_test function become cleaner SET(sources "") FOREACH(f ${BIN_SOURCES}) - # Do not add main.cpp, because it will override the main function - if(NOT "${f}" STREQUAL "main.cpp") + if(NOT IS_ABSOLUTE ${f}) LIST(APPEND sources "../src/${f}") + else() + LIST(APPEND sources ${f}) endif() ENDFOREACH(f)