From f002baed7ad74cceb5d4478f29310d537dfff6dc Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 12 Nov 2015 21:30:50 -0500 Subject: [PATCH 1/9] cmake: bump requirement to 3.1.0 CMAKE_C_STANDARD was introduced in 3.1.0. --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b75e87378..8f7d747ec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,7 @@ -cmake_minimum_required(VERSION 2.8.5) +cmake_minimum_required(VERSION 3.1.0) + project(sway C) + set(CMAKE_C_FLAGS "-g") set(CMAKE_C_STANDARD 99) SET(CMAKE_C_EXTENSIONS OFF) From c8599dba0247929ae0d48a0b41486f45321b4190 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 12 Nov 2015 21:28:41 -0500 Subject: [PATCH 2/9] cmake: use string(TIMESTAMP) --- CMakeLists.txt | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f7d747ec..528e64041 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,14 +30,8 @@ add_definitions("${VERSION_GIT_COMMIT_FLAG}") SET(VERSION_GIT_BRANCH_FLAG "-DSWAY_GIT_BRANCH=\"${GIT_BRANCH}\"") add_definitions("${VERSION_GIT_BRANCH_FLAG}") -execute_process( - COMMAND date +"%Y-%m-%d" - OUTPUT_VARIABLE CURRENT_DATE - OUTPUT_STRIP_TRAILING_WHITESPACE -) - -SET(VERSION_DATE_FLAG "-DSWAY_VERSION_DATE=${CURRENT_DATE}") -add_definitions("${VERSION_DATE_FLAG}") +string(TIMESTAMP CURRENT_DATE "%Y-%m-%d" UTC) +add_definitions("-DSWAY_VERSION_DATE=${CURRENT_DATE}") find_package(XKBCommon REQUIRED) find_package(WLC REQUIRED) From 4714262c3d6a07d1d48a7fab44316280094e9589 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 12 Nov 2015 21:29:25 -0500 Subject: [PATCH 3/9] cmake: simplify manpage generation --- CMakeLists.txt | 45 ++++++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 528e64041..acf09e86a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,31 +72,34 @@ INSTALL( DESTINATION /etc/sway/ ) -ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/sway.1 - COMMAND ${A2X_COMMAND} --no-xmllint --doctype manpage --format manpage - -D ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${CMAKE_CURRENT_SOURCE_DIR}/sway.1.txt - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/sway.1.txt -) +add_custom_target(man ALL) -ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/sway.5 - COMMAND ${A2X_COMMAND} --no-xmllint --doctype manpage --format manpage - -D ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} ${CMAKE_CURRENT_SOURCE_DIR}/sway.5.txt - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/sway.5.txt -) +function (add_manpage name section) + add_custom_command( + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${name}.${section}" + COMMAND "${A2X_COMMAND}" + --no-xmllint + --doctype manpage + --format manpage + -D "${CMAKE_CURRENT_BINARY_DIR}" + "${CMAKE_CURRENT_SOURCE_DIR}/${name}.${section}.txt" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${name}.${section}.txt" + COMMENT "Generating manpage for ${name}.${section}") -ADD_CUSTOM_TARGET(man ALL - DEPENDS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/sway.1 - DEPENDS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/sway.5) + add_custom_target("man-${name}.${section}" + DEPENDS + "${CMAKE_CURRENT_BINARY_DIR}/${name}.${section}") + add_dependencies(man + "man-${name}.${section}") -INSTALL( - FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/sway.1 - DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man1 -) + install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/${name}.${section}" + DESTINATION "share/man/man${section}" + COMPONENT documentation) +endfunction () -INSTALL( - FILES ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/sway.5 - DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man5 -) +add_manpage(sway 1) +add_manpage(sway 5) INSTALL( FILES ${PROJECT_SOURCE_DIR}/sway.desktop From 2e9183e4de8fb5b5bcb2c6e2416a6b0b4a48682d Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 12 Nov 2015 21:32:36 -0500 Subject: [PATCH 4/9] cmake: set the output directory once --- CMakeLists.txt | 2 +- swaybg/CMakeLists.txt | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index acf09e86a..c5f86189c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,7 @@ project(sway C) set(CMAKE_C_FLAGS "-g") set(CMAKE_C_STANDARD 99) SET(CMAKE_C_EXTENSIONS OFF) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "bin/") +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin") add_definitions("-Wall -Wextra -Wno-unused-parameter -D_GNU_SOURCE") set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/CMake) diff --git a/swaybg/CMakeLists.txt b/swaybg/CMakeLists.txt index 9351441af..20aff980f 100644 --- a/swaybg/CMakeLists.txt +++ b/swaybg/CMakeLists.txt @@ -7,7 +7,6 @@ find_package(Pango REQUIRED) include(Wayland) WAYLAND_ADD_PROTOCOL_CLIENT(proto-xdg-shell "xdg-shell.xml" xdg-shell) -set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "../bin/") include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/../include ${WAYLAND_CLIENT_INCLUDE_DIR} From 28f1e9842c65adbb30ca22004c780fe6c263c116 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 12 Nov 2015 21:36:48 -0500 Subject: [PATCH 5/9] cmake: manipulate CMAKE_MODULE_PATH as a list Also prefer local modules. --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c5f86189c..000010a2a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,8 @@ set(CMAKE_C_STANDARD 99) SET(CMAKE_C_EXTENSIONS OFF) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/bin") add_definitions("-Wall -Wextra -Wno-unused-parameter -D_GNU_SOURCE") -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/CMake) +list(INSERT CMAKE_MODULE_PATH 0 + "${CMAKE_CURRENT_SOURCE_DIR}/CMake") add_subdirectory(swaybg swaybg) From f8ae8cb820eecff1db514e15a354c03648b85f34 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 12 Nov 2015 21:37:18 -0500 Subject: [PATCH 6/9] cmake: clean up definition settings --- CMakeLists.txt | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 000010a2a..236a36673 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,11 +25,8 @@ if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git") ) endif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git") -SET(VERSION_GIT_COMMIT_FLAG "-DSWAY_GIT_VERSION=\"g${GIT_COMMIT_HASH}\"") -add_definitions("${VERSION_GIT_COMMIT_FLAG}") - -SET(VERSION_GIT_BRANCH_FLAG "-DSWAY_GIT_BRANCH=\"${GIT_BRANCH}\"") -add_definitions("${VERSION_GIT_BRANCH_FLAG}") +add_definitions("-DSWAY_GIT_VERSION=\"g${GIT_COMMIT_HASH}\"") +add_definitions("-DSWAY_GIT_BRANCH=\"${GIT_BRANCH}\"") string(TIMESTAMP CURRENT_DATE "%Y-%m-%d" UTC) add_definitions("-DSWAY_VERSION_DATE=${CURRENT_DATE}") From 98678dea5d395e08de5bf28d3c9b4f48ea6f6589 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 12 Nov 2015 21:37:35 -0500 Subject: [PATCH 7/9] cmake: clean up installation rules --- CMakeLists.txt | 32 ++++++++++++++++---------------- swaybg/CMakeLists.txt | 8 ++++---- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 236a36673..3f33a3f8a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,15 +60,14 @@ target_link_libraries(sway ${JSONC_LIBRARIES} ) -INSTALL( - TARGETS sway - RUNTIME DESTINATION bin -) - -INSTALL( - FILES ${PROJECT_SOURCE_DIR}/config - DESTINATION /etc/sway/ -) +install( + TARGETS sway + RUNTIME DESTINATION bin + COMPONENT runtime) +install( + FILES "${CMAKE_CURRENT_SOURCE_DIR}/config" + DESTINATION /etc/sway/ + COMPONENT configuration) add_custom_target(man ALL) @@ -99,10 +98,11 @@ endfunction () add_manpage(sway 1) add_manpage(sway 5) -INSTALL( - FILES ${PROJECT_SOURCE_DIR}/sway.desktop - DESTINATION ${CMAKE_INSTALL_PREFIX}/share/wayland-sessions/) - -INSTALL( - FILES ${PROJECT_SOURCE_DIR}/sway-xorg.desktop - DESTINATION ${CMAKE_INSTALL_PREFIX}/share/xsessions/) +install( + FILES "${CMAKE_CURRENT_SOURCE_DIR}/sway.desktop" + DESTINATION share/wayland-sessions + COMPONENT data) +install( + FILES "${CMAKE_CURRENT_SOURCE_DIR}/sway-xorg.desktop" + DESTINATION share/xsessions + COMPONENT data) diff --git a/swaybg/CMakeLists.txt b/swaybg/CMakeLists.txt index 20aff980f..e86cf6566 100644 --- a/swaybg/CMakeLists.txt +++ b/swaybg/CMakeLists.txt @@ -26,7 +26,7 @@ add_executable(swaybg TARGET_LINK_LIBRARIES(swaybg ${WAYLAND_CLIENT_LIBRARIES} ${CAIRO_LIBRARIES} ${PANGO_LIBRARIES}) -INSTALL( - TARGETS swaybg - RUNTIME DESTINATION bin -) +install( + TARGETS swaybg + RUNTIME DESTINATION bin + COMPONENT runtime) From ec013d1f1a5e0345353009f97dc506420995db6b Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 12 Nov 2015 21:42:37 -0500 Subject: [PATCH 8/9] common: create a static library --- CMakeLists.txt | 9 +++++---- common/CMakeLists.txt | 3 +++ swaybg/CMakeLists.txt | 4 +--- 3 files changed, 9 insertions(+), 7 deletions(-) create mode 100644 common/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 3f33a3f8a..00e8de6ed 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,8 +10,6 @@ add_definitions("-Wall -Wextra -Wno-unused-parameter -D_GNU_SOURCE") list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}/CMake") -add_subdirectory(swaybg swaybg) - if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git") execute_process( COMMAND git describe --always @@ -31,6 +29,10 @@ 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") +add_subdirectory(common) +add_subdirectory(swaybg) + find_package(XKBCommon REQUIRED) find_package(WLC REQUIRED) find_package(A2X REQUIRED) @@ -38,14 +40,12 @@ find_package(PCRE REQUIRED) find_package(JsonC REQUIRED) FILE(GLOB sources ${PROJECT_SOURCE_DIR}/sway/*.c) -FILE(GLOB common ${PROJECT_SOURCE_DIR}/common/*.c) include_directories( ${WLC_INCLUDE_DIRS} ${PCRE_INCLUDE_DIRS} ${JSONC_INCLUDE_DIRS} ${XKBCOMMON_INCLUDE_DIRS} - include/ ) add_executable(sway @@ -58,6 +58,7 @@ target_link_libraries(sway ${XKBCOMMON_LIBRARIES} ${PCRE_LIBRARIES} ${JSONC_LIBRARIES} + sway_common ) install( diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt new file mode 100644 index 000000000..f3a00626e --- /dev/null +++ b/common/CMakeLists.txt @@ -0,0 +1,3 @@ +add_library(sway_common STATIC + list.c + log.c) diff --git a/swaybg/CMakeLists.txt b/swaybg/CMakeLists.txt index e86cf6566..1ad433240 100644 --- a/swaybg/CMakeLists.txt +++ b/swaybg/CMakeLists.txt @@ -8,7 +8,6 @@ include(Wayland) WAYLAND_ADD_PROTOCOL_CLIENT(proto-xdg-shell "xdg-shell.xml" xdg-shell) include_directories( - ${CMAKE_CURRENT_SOURCE_DIR}/../include ${WAYLAND_CLIENT_INCLUDE_DIR} ${CAIRO_INCLUDE_DIRS} ${PANGO_INCLUDE_DIRS} @@ -16,7 +15,6 @@ include_directories( FILE(GLOB sources ${PROJECT_SOURCE_DIR}/*.c) FILE(GLOB wl_sources ${PROJECT_SOURCE_DIR}/../wayland/*.c) -FILE(GLOB common ${PROJECT_SOURCE_DIR}/../common/*.c) add_executable(swaybg ${sources} @@ -24,7 +22,7 @@ add_executable(swaybg ${common} ) -TARGET_LINK_LIBRARIES(swaybg ${WAYLAND_CLIENT_LIBRARIES} ${CAIRO_LIBRARIES} ${PANGO_LIBRARIES}) +TARGET_LINK_LIBRARIES(swaybg ${WAYLAND_CLIENT_LIBRARIES} ${CAIRO_LIBRARIES} ${PANGO_LIBRARIES} sway_common) install( TARGETS swaybg From 8e8bdbcae21a0db730d48fc39aa780e37729412c Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 12 Nov 2015 21:45:32 -0500 Subject: [PATCH 9/9] cmake: run git in the source directory --- CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 00e8de6ed..f8dd9cb7a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,11 +15,13 @@ if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git") COMMAND git describe --always OUTPUT_VARIABLE GIT_COMMIT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" ) execute_process( COMMAND git rev-parse --abbrev-ref HEAD OUTPUT_VARIABLE GIT_BRANCH OUTPUT_STRIP_TRAILING_WHITESPACE + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" ) endif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.git")