diff --git a/.github/workflows/push_pr_build_cmake.yml b/.github/workflows/push_pr_build_cmake.yml index f511286..a96750b 100644 --- a/.github/workflows/push_pr_build_cmake.yml +++ b/.github/workflows/push_pr_build_cmake.yml @@ -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 @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b7d610..3667da7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/Daemon/CMakeLists.txt b/Daemon/CMakeLists.txt index dfb2298..c548d0c 100644 --- a/Daemon/CMakeLists.txt +++ b/Daemon/CMakeLists.txt @@ -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() diff --git a/Daemon/openrc/CMakeLists.txt b/Daemon/openrc/CMakeLists.txt new file mode 100644 index 0000000..7064491 --- /dev/null +++ b/Daemon/openrc/CMakeLists.txt @@ -0,0 +1 @@ +# TBD diff --git a/Daemon/ydotoold.service-openrc.in b/Daemon/openrc/ydotoold.service-openrc.in old mode 100755 new mode 100644 similarity index 100% rename from Daemon/ydotoold.service-openrc.in rename to Daemon/openrc/ydotoold.service-openrc.in diff --git a/Daemon/systemd/CMakeLists.txt b/Daemon/systemd/CMakeLists.txt new file mode 100644 index 0000000..d25800b --- /dev/null +++ b/Daemon/systemd/CMakeLists.txt @@ -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}) diff --git a/Daemon/ydotoold.service.in b/Daemon/systemd/ydotoold.service.in similarity index 84% rename from Daemon/ydotoold.service.in rename to Daemon/systemd/ydotoold.service.in index 807cfd1..14957d4 100644 --- a/Daemon/ydotoold.service.in +++ b/Daemon/systemd/ydotoold.service.in @@ -1,5 +1,5 @@ [Unit] -Description=Starts ydotoold user service +Description=Starts ydotoold Daemon [Service] Type=simple @@ -13,4 +13,3 @@ TimeoutSec=180 [Install] WantedBy=basic.target -