Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create CMake option for systemd system/user service #237

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/push_pr_build_cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ jobs:
run: |
mv ${{github.workspace}}/build/ydotool ${{github.workspace}}/build/ydotool-${{matrix.os}}
mv ${{github.workspace}}/build/ydotoold ${{github.workspace}}/build/ydotoold-${{matrix.os}}
mv ${{github.workspace}}/build/ydotoold.service ${{github.workspace}}/build/ydotoold-${{matrix.os}}.service

- name: Archive production artifacts
uses: actions/upload-artifact@v4
Expand All @@ -56,4 +57,5 @@ jobs:
path: |
${{github.workspace}}/build/ydotool-${{matrix.os}}
${{github.workspace}}/build/ydotoold-${{matrix.os}}
${{github.workspace}}/build/ydotoold-${{matrix.os}}.service

10 changes: 0 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,6 @@ set(CMAKE_C_STANDARD 11)
# Include GNU install directory module to detect where to install
# files on Linux/Unix systems (e.g., lib vs lib64)
include(GNUInstallDirs)
find_package(PkgConfig)

# Try to get the systemd directory for user units from the package
# and fall back on upstream default without the '/usr' prefix
pkg_check_modules(SYSTEMD systemd)
if (SYSTEMD_FOUND)
pkg_get_variable(SD_UNITDIR systemd systemduserunitdir)
else()
set(SD_UNITDIR "lib/systemd/user")
endif()

execute_process(COMMAND git describe --tags --long --always RESULT_VARIABLE RC_GIT_VER OUTPUT_VARIABLE GIT_VERSION)

Expand Down
20 changes: 15 additions & 5 deletions Daemon/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/ydotoold.service.in"
"${PROJECT_BINARY_DIR}/ydotoold.service"
@ONLY)
install(FILES "${PROJECT_BINARY_DIR}/ydotoold.service" DESTINATION ${SD_UNITDIR})
option(SYSTEMD_USER_SERVICE "Install systemd user service file" ON)
option(SYSTEMD_SYSTEM_SERVICE "Install systemd system service file" OFF)
option(OPENRC "Install OpenRC service file" OFF) # To be implemented

if(SYSTEMD_USER_SERVICE AND SYSTEMD_SYSTEM_SERVICE)
message(FATAL_ERROR "Both system and user services are enabled. Choose one.")
endif()

if(SYSTEMD_USER_SERVICE OR SYSTEMD_SYSTEM_SERVICE)
add_subdirectory(systemd)
endif()

if(OPENRC)
add_subdirectory(openrc)
endif()
1 change: 1 addition & 0 deletions Daemon/openrc/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# TBD
File renamed without changes.
25 changes: 25 additions & 0 deletions Daemon/systemd/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
find_package(PkgConfig)

# Try to get the systemd directory for system/user units from the package
# and fall back on upstream default without the '/usr' prefix if not forced by
# command line.
pkg_check_modules(SYSTEMD systemd)
if (SYSTEMD_FOUND)
if(SYSTEMD_USER_SERVICE)
pkg_get_variable(SD_UNITDIR systemd systemduserunitdir)
elseif(SYSTEMD_SYSTEM_SERVICE)
pkg_get_variable(SD_UNITDIR systemd systemdsystemunitdir)
endif()
endif()

if(NOT DEFINED SD_UNITDIR)
set(SD_UNITDIR "lib/systemd/user")
endif()

message("Systemd service file is going to be installed at ${SD_UNITDIR}")

configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/ydotoold.service.in"
"${PROJECT_BINARY_DIR}/ydotoold.service"
@ONLY)
install(FILES "${PROJECT_BINARY_DIR}/ydotoold.service" DESTINATION ${SD_UNITDIR})
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Unit]
Description=Starts ydotoold user service
Description=Starts ydotoold Daemon

[Service]
Type=simple
Expand All @@ -13,4 +13,3 @@ TimeoutSec=180

[Install]
WantedBy=basic.target