Install/uninstall cmake rules
Signed-off-by: Tiago Garcia <tiago.rgarcia@ua.pt>
This commit is contained in:
parent
5187a6771e
commit
11f0a82b23
|
@ -3,8 +3,22 @@ cmake_minimum_required(VERSION 3.20)
|
|||
# Project name and version
|
||||
project(gh-wh-handler VERSION 0.1.0)
|
||||
|
||||
# Detect architecture
|
||||
if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64")
|
||||
set(ARCH "x86_64")
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64")
|
||||
set(ARCH "aarch64")
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "armv7l")
|
||||
set(ARCH "armv7l")
|
||||
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "i686")
|
||||
set(ARCH "i686")
|
||||
# Add more architectures as needed
|
||||
else()
|
||||
set(ARCH "unknown")
|
||||
endif()
|
||||
|
||||
# Set the executable name
|
||||
set(EXECUTABLE_NAME "gh-wh-handler")
|
||||
set(EXECUTABLE_NAME "gh-wh-handler.${ARCH}")
|
||||
|
||||
# Set the C++ standard
|
||||
set(CMAKE_CXX_STANDARD 23)
|
||||
|
@ -28,20 +42,30 @@ target_include_directories(${EXECUTABLE_NAME} PUBLIC ${INCLUDE_DIR})
|
|||
target_compile_options(${EXECUTABLE_NAME} PRIVATE -Wall -Werror)
|
||||
|
||||
# Set linker flags for static linking
|
||||
set_target_properties(${EXECUTABLE_NAME} PROPERTIES
|
||||
LINK_FLAGS "-static -static-libgcc -static-libstdc++"
|
||||
)
|
||||
set_target_properties(${EXECUTABLE_NAME} PROPERTIES LINK_FLAGS
|
||||
"-static -static-libgcc -static-libstdc++")
|
||||
|
||||
# Install the service
|
||||
set(CMAKE_INSTALL_PREFIX "/usr/")
|
||||
install(TARGETS ${EXECUTABLE_NAME} DESTINATION bin)
|
||||
set(SERVICE_EXECUTABLE "/services/gh-wh-handler/gh-wh-handler.aarch64")
|
||||
set(SERVICE_CONFIG_FILE "/services/gh-wh-handler/config.json")
|
||||
configure_file(${CMAKE_SOURCE_DIR}/gh-wh-handler.service.in ${CMAKE_BINARY_DIR}/gh-wh-handler.service @ONLY)
|
||||
install(FILES ${CMAKE_BINARY_DIR}/gh-wh-handler.service DESTINATION /etc/systemd/system)
|
||||
install(CODE "
|
||||
execute_process(COMMAND systemctl daemon-reload)
|
||||
execute_process(COMMAND systemctl enable gh-wh-handler.service)
|
||||
execute_process(COMMAND systemctl start gh-wh-handler.service)
|
||||
")
|
||||
# Install the executable
|
||||
set(SERVICE_EXECUTABLE "/services/gh-wh-handler/${EXECUTABLE_NAME}")
|
||||
set(SERVICE_CONFIG "/services/gh-wh-handler/config.json")
|
||||
configure_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/gh-wh-handler.service.in"
|
||||
"${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/gh-wh-handler.service"
|
||||
@ONLY)
|
||||
install(CODE "file(MAKE_DIRECTORY /services/gh-wh-handler)")
|
||||
install(TARGETS ${EXECUTABLE_NAME} DESTINATION /services/gh-wh-handler)
|
||||
install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
|
||||
/services/gh-wh-handler/${EXECUTABLE_NAME} /usr/bin/gh-wh-handler)")
|
||||
install(FILES "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/gh-wh-handler.service"
|
||||
DESTINATION /etc/systemd/system)
|
||||
install(CODE "execute_process(COMMAND systemctl daemon-reload)")
|
||||
install(CODE "execute_process(COMMAND systemctl enable gh-wh-handler)")
|
||||
install(CODE "execute_process(COMMAND systemctl start gh-wh-handler)")
|
||||
|
||||
|
||||
if(NOT TARGET uninstall)
|
||||
configure_file(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/uninstall.cmake.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/uninstall.cmake" IMMEDIATE @ONLY)
|
||||
add_custom_target(uninstall COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/uninstall.cmake)
|
||||
endif()
|
||||
|
|
|
@ -3,7 +3,7 @@ Description=Runs github webhook handler
|
|||
After=network.target
|
||||
|
||||
[Service]
|
||||
ExecStart=@SERVICE_EXECUTABLE@ @SERVICE_CONFIG_FILE@
|
||||
ExecStart=@SERVICE_EXECUTABLE@ @SERVICE_CONFIG@
|
||||
Restart=always
|
||||
Type=simple
|
||||
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
message(STATUS "[0%] Stopping systemd service...")
|
||||
execute_process(COMMAND systemctl stop gh-wh-handler)
|
||||
|
||||
message(STATUS "[15%] Disabling systemd service...")
|
||||
execute_process(COMMAND systemctl disable gh-wh-handler)
|
||||
|
||||
message(STATUS "[30%] Removing service configuration file from systemd directory...")
|
||||
file(REMOVE /etc/systemd/system/gh-wh-handler.service)
|
||||
|
||||
message(STATUS "[45%] Reloading systemd daemon...")
|
||||
execute_process(COMMAND systemctl daemon-reload)
|
||||
|
||||
message(STATUS "[55%] Removing symlink to service executable...")
|
||||
execute_process(COMMAND rm /usr/bin/gh-wh-handler)
|
||||
|
||||
message(STATUS "[70%] Removing service executable from service directory...")
|
||||
file(REMOVE /services/gh-wh-handler/@EXECUTABLE_NAME@)
|
||||
|
||||
message(STATUS "[85%] Removing service directory...")
|
||||
file(REMOVE /services/gh-wh-handler)
|
||||
|
||||
message(STATUS "[100%] Uninstallation complete!")
|
Loading…
Reference in New Issue