2024-07-14 23:08:29 +00:00
|
|
|
cmake_minimum_required(VERSION 3.20)
|
|
|
|
|
|
|
|
# Project name and version
|
|
|
|
project(gh-wh-handler VERSION 0.1.0)
|
|
|
|
|
2024-07-18 00:43:42 +00:00
|
|
|
# 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()
|
|
|
|
|
2024-07-14 23:08:29 +00:00
|
|
|
# Set the executable name
|
2024-07-18 00:43:42 +00:00
|
|
|
set(EXECUTABLE_NAME "gh-wh-handler.${ARCH}")
|
2024-07-14 23:08:29 +00:00
|
|
|
|
|
|
|
# Set the C++ standard
|
|
|
|
set(CMAKE_CXX_STANDARD 23)
|
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED True)
|
|
|
|
|
|
|
|
# Set the output directory
|
|
|
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin)
|
|
|
|
|
2024-07-15 21:07:12 +00:00
|
|
|
# Add include directories
|
|
|
|
set(INCLUDE_DIR "${CMAKE_SOURCE_DIR}/include")
|
|
|
|
include_directories(${INCLUDE_DIR})
|
|
|
|
|
2024-07-14 23:08:29 +00:00
|
|
|
# Add source files
|
|
|
|
file(GLOB_RECURSE SOURCES "src/*.cpp")
|
|
|
|
|
|
|
|
# Add the executable
|
|
|
|
add_executable(${EXECUTABLE_NAME} ${SOURCES})
|
2024-07-15 21:07:12 +00:00
|
|
|
target_include_directories(${EXECUTABLE_NAME} PUBLIC ${INCLUDE_DIR})
|
2024-07-14 23:08:29 +00:00
|
|
|
|
|
|
|
# Add compilation flags
|
|
|
|
target_compile_options(${EXECUTABLE_NAME} PRIVATE -Wall -Werror)
|
|
|
|
|
|
|
|
# Set linker flags for static linking
|
2024-07-18 00:43:42 +00:00
|
|
|
set_target_properties(${EXECUTABLE_NAME} PROPERTIES LINK_FLAGS
|
|
|
|
"-static -static-libgcc -static-libstdc++")
|
|
|
|
|
|
|
|
# Install the executable
|
|
|
|
set(SERVICE_EXECUTABLE "/services/gh-wh-handler/${EXECUTABLE_NAME}")
|
|
|
|
set(SERVICE_CONFIG "/services/gh-wh-handler/config.json")
|
2024-07-19 11:52:41 +00:00
|
|
|
set(SERVICE_LOGS "/services/gh-wh-handler/logs")
|
2024-07-18 00:43:42 +00:00
|
|
|
configure_file(
|
2024-07-18 18:13:15 +00:00
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/gh-wh-handler.service.in"
|
2024-07-19 14:27:39 +00:00
|
|
|
"${CMAKE_CURRENT_BINARY_DIR}/gh-wh-handler.service"
|
2024-07-18 00:43:42 +00:00
|
|
|
@ONLY)
|
|
|
|
install(CODE "file(MAKE_DIRECTORY /services/gh-wh-handler)")
|
2024-07-19 11:52:41 +00:00
|
|
|
install(CODE "file(MAKE_DIRECTORY /services/gh-wh-handler/logs)")
|
2024-07-18 00:43:42 +00:00
|
|
|
install(TARGETS ${EXECUTABLE_NAME} DESTINATION /services/gh-wh-handler)
|
2024-07-19 11:52:41 +00:00
|
|
|
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/config.json"
|
|
|
|
DESTINATION /services/gh-wh-handler)
|
2024-07-18 00:43:42 +00:00
|
|
|
install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink
|
|
|
|
/services/gh-wh-handler/${EXECUTABLE_NAME} /usr/bin/gh-wh-handler)")
|
2024-07-19 14:27:39 +00:00
|
|
|
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/gh-wh-handler.service"
|
2024-07-18 00:43:42 +00:00
|
|
|
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)")
|
|
|
|
|
2024-07-15 21:07:12 +00:00
|
|
|
|
2024-07-18 00:43:42 +00:00
|
|
|
if(NOT TARGET uninstall)
|
2024-07-19 14:27:39 +00:00
|
|
|
configure_file(
|
|
|
|
"${CMAKE_CURRENT_BINARY_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)
|
2024-07-18 00:43:42 +00:00
|
|
|
endif()
|