From cce9c338c07e889aa82db806f0dddf2f997edbb6 Mon Sep 17 00:00:00 2001 From: Christoph Gysin Date: Wed, 2 Dec 2015 07:57:53 +0200 Subject: [PATCH] cmake: build common code only once This creates (static) libraries for protocols/, common/, and wayland/. --- CMakeLists.txt | 14 +++++++++++++- common/CMakeLists.txt | 7 +++++++ protocols/CMakeLists.txt | 22 ++++++++++++++++++++++ sway/CMakeLists.txt | 38 +++++++++++++++++++------------------- swaybar/CMakeLists.txt | 28 ++++------------------------ swaybg/CMakeLists.txt | 28 ++++------------------------ swaygrab/CMakeLists.txt | 7 ++----- swaymsg/CMakeLists.txt | 10 +++++----- wayland/CMakeLists.txt | 17 +++++++++++++++++ 9 files changed, 93 insertions(+), 78 deletions(-) create mode 100644 common/CMakeLists.txt create mode 100644 protocols/CMakeLists.txt create mode 100644 wayland/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index b9a2e37dd..75c61c2a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,7 +41,19 @@ add_definitions(-DSWAY_GIT_BRANCH=\"${GIT_BRANCH}\") string(TIMESTAMP CURRENT_DATE "%Y-%m-%d" UTC) add_definitions(-DSWAY_VERSION_DATE=\"${CURRENT_DATE}\") -include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) +find_package(Cairo REQUIRED) +find_package(JsonC REQUIRED) +find_package(PCRE REQUIRED) +find_package(Pango REQUIRED) +find_package(WLC REQUIRED) +find_package(Wayland REQUIRED) +find_package(XKBCommon REQUIRED) + +include_directories(include) + +add_subdirectory(protocols) +add_subdirectory(common) +add_subdirectory(wayland) add_subdirectory(sway) add_subdirectory(swaybg) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt new file mode 100644 index 000000000..f7d44ec54 --- /dev/null +++ b/common/CMakeLists.txt @@ -0,0 +1,7 @@ +add_library(sway-common + ipc-client.c + list.c + log.c + readline.c + stringop.c + ) diff --git a/protocols/CMakeLists.txt b/protocols/CMakeLists.txt new file mode 100644 index 000000000..07becc367 --- /dev/null +++ b/protocols/CMakeLists.txt @@ -0,0 +1,22 @@ +include(Wayland) + +WAYLAND_ADD_PROTOCOL_CLIENT(proto-client-xdg-shell + xdg-shell.xml + xdg-shell +) +WAYLAND_ADD_PROTOCOL_CLIENT(proto-client-desktop-shell + desktop-shell.xml + desktop-shell +) +WAYLAND_ADD_PROTOCOL_SERVER(proto-server-desktop-shell + desktop-shell.xml + desktop-shell +) + +add_library(sway-protocols + ${proto-client-xdg-shell} + ${proto-client-desktop-shell} + ${proto-server-desktop-shell} + ) + +set(PROTOCOLS_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/protocols PARENT_SCOPE) diff --git a/sway/CMakeLists.txt b/sway/CMakeLists.txt index 92392354b..49ed24e7d 100644 --- a/sway/CMakeLists.txt +++ b/sway/CMakeLists.txt @@ -1,33 +1,33 @@ -find_package(XKBCommon REQUIRED) -find_package(WLC REQUIRED) -find_package(PCRE REQUIRED) -find_package(Wayland REQUIRED) -find_package(JsonC REQUIRED) - -include(Wayland) -WAYLAND_ADD_PROTOCOL_SERVER(proto-desktop-shell - ${PROJECT_SOURCE_DIR}/protocols/desktop-shell.xml - desktop-shell -) - -file(GLOB sources ${PROJECT_SOURCE_DIR}/sway/*.c) -file(GLOB common ${PROJECT_SOURCE_DIR}/common/*.c) - include_directories( + ${PROTOCOLS_INCLUDE_DIRS} ${WLC_INCLUDE_DIRS} ${PCRE_INCLUDE_DIRS} ${JSONC_INCLUDE_DIRS} ${XKBCOMMON_INCLUDE_DIRS} - ${CMAKE_CURRENT_BINARY_DIR} ) add_executable(sway - ${sources} - ${common} - ${proto-desktop-shell} + commands.c + config.c + container.c + criteria.c + debug_log.c + extensions.c + focus.c + handlers.c + input_state.c + ipc-server.c + layout.c + main.c + output.c + resize.c + util.c + workspace.c ) target_link_libraries(sway + sway-common + sway-protocols ${WLC_LIBRARIES} ${XKBCOMMON_LIBRARIES} ${PCRE_LIBRARIES} diff --git a/swaybar/CMakeLists.txt b/swaybar/CMakeLists.txt index c14b5f758..a2ff9f5a0 100644 --- a/swaybar/CMakeLists.txt +++ b/swaybar/CMakeLists.txt @@ -1,37 +1,17 @@ -find_package(Wayland REQUIRED) -find_package(Cairo REQUIRED) -find_package(Pango REQUIRED) - -include(Wayland) -WAYLAND_ADD_PROTOCOL_CLIENT(proto-xdg-shell - ../protocols/xdg-shell.xml - xdg-shell -) -WAYLAND_ADD_PROTOCOL_CLIENT(proto-desktop-shell - ../protocols/desktop-shell.xml - desktop-shell -) - include_directories( + ${PROTOCOLS_INCLUDE_DIRS} ${WAYLAND_CLIENT_INCLUDE_DIR} ${CAIRO_INCLUDE_DIRS} ${PANGO_INCLUDE_DIRS} - ${CMAKE_CURRENT_BINARY_DIR} ) -file(GLOB sources *.c) -file(GLOB common ../common/*.c) -file(GLOB wl_sources ../wayland/*.c) - add_executable(swaybar - ${sources} - ${wl_sources} - ${common} - ${proto-xdg-shell} - ${proto-desktop-shell} + main.c ) target_link_libraries(swaybar + sway-common + sway-wayland ${WAYLAND_CLIENT_LIBRARIES} ${WAYLAND_CURSOR_LIBRARIES} ${CAIRO_LIBRARIES} diff --git a/swaybg/CMakeLists.txt b/swaybg/CMakeLists.txt index 9d3cc5478..71363d791 100644 --- a/swaybg/CMakeLists.txt +++ b/swaybg/CMakeLists.txt @@ -1,37 +1,17 @@ -find_package(Wayland REQUIRED) -find_package(Cairo REQUIRED) -find_package(Pango REQUIRED) - -include(Wayland) -WAYLAND_ADD_PROTOCOL_CLIENT(proto-xdg-shell - ../protocols/xdg-shell.xml - xdg-shell -) -WAYLAND_ADD_PROTOCOL_CLIENT(proto-desktop-shell - ../protocols/desktop-shell.xml - desktop-shell -) - include_directories( + ${PROTOCOLS_INCLUDE_DIRS} ${WAYLAND_CLIENT_INCLUDE_DIR} ${CAIRO_INCLUDE_DIRS} ${PANGO_INCLUDE_DIRS} - ${CMAKE_CURRENT_BINARY_DIR} ) -file(GLOB sources *.c) -file(GLOB common ../common/*.c) -file(GLOB wl_sources ../wayland/*.c) - add_executable(swaybg - ${sources} - ${wl_sources} - ${common} - ${proto-xdg-shell} - ${proto-desktop-shell} + main.c ) target_link_libraries(swaybg + sway-common + sway-wayland ${WAYLAND_CLIENT_LIBRARIES} ${WAYLAND_CURSOR_LIBRARIES} ${CAIRO_LIBRARIES} diff --git a/swaygrab/CMakeLists.txt b/swaygrab/CMakeLists.txt index 77d96412d..d5468cdae 100644 --- a/swaygrab/CMakeLists.txt +++ b/swaygrab/CMakeLists.txt @@ -1,12 +1,9 @@ -file(GLOB sources *.c) -file(GLOB common ../common/*.c) - add_executable(swaygrab - ${sources} - ${common} + main.c ) target_link_libraries(swaygrab + sway-common rt ) diff --git a/swaymsg/CMakeLists.txt b/swaymsg/CMakeLists.txt index 7616d9423..2481b280c 100644 --- a/swaymsg/CMakeLists.txt +++ b/swaymsg/CMakeLists.txt @@ -1,11 +1,11 @@ -file(GLOB sources *.c) -file(GLOB common ../common/*.c) - add_executable(swaymsg - ${sources} - ${common} + main.c ) +target_link_libraries(swaymsg + sway-common + ) + install( TARGETS swaymsg RUNTIME diff --git a/wayland/CMakeLists.txt b/wayland/CMakeLists.txt new file mode 100644 index 000000000..5633dd6e7 --- /dev/null +++ b/wayland/CMakeLists.txt @@ -0,0 +1,17 @@ +include_directories( + ${PROTOCOLS_INCLUDE_DIRS} + ${PANGO_INCLUDE_DIRS} +) + +add_library(sway-wayland + buffers.c + pango.c + registry.c + window.c + ) + +target_link_libraries(sway-wayland + sway-common + sway-protocols + ${PANGO_LIBRARIES} + )