2024-01-02 03:45:06 +01:00
|
|
|
#[[**************************************************************************
|
|
|
|
* dtranslatebot Discord Translate Bot
|
|
|
|
* Copyright (C) 2023-2024 Syping
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
* are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* This software is provided as-is, no warranties are given to you, we are not
|
|
|
|
* responsible for anything with use of the software, you are self responsible.
|
|
|
|
****************************************************************************]]
|
|
|
|
|
|
|
|
cmake_minimum_required(VERSION 3.16)
|
2024-03-03 15:17:03 +01:00
|
|
|
cmake_policy(VERSION 3.16...3.27)
|
2024-02-26 11:33:39 +01:00
|
|
|
project(dtranslatebot VERSION 0.2.0 LANGUAGES CXX)
|
2024-01-18 16:09:25 +01:00
|
|
|
include(GNUInstallDirs)
|
2024-01-02 03:45:06 +01:00
|
|
|
|
2024-01-18 16:09:25 +01:00
|
|
|
# dtranslatebot Source files
|
|
|
|
set(DTRANSLATEBOT_HEADERS
|
2024-02-26 11:33:39 +01:00
|
|
|
src/core/database.h
|
|
|
|
src/core/message_queue.h
|
|
|
|
src/core/regex.h
|
|
|
|
src/core/settings.h
|
|
|
|
src/core/settings_types.h
|
|
|
|
src/core/slashcommands.h
|
|
|
|
src/core/submit_queue.h
|
|
|
|
src/core/translator.h
|
|
|
|
src/core/webhook_push.h
|
|
|
|
src/database/file/file.h
|
2024-03-23 16:57:54 +01:00
|
|
|
src/translator/deepl/deepl.h
|
2024-02-26 11:33:39 +01:00
|
|
|
src/translator/libretranslate/libretranslate.h
|
2024-03-11 05:21:01 +01:00
|
|
|
src/translator/stub/stub.h
|
2024-01-18 16:09:25 +01:00
|
|
|
)
|
|
|
|
set(DTRANSLATEBOT_SOURCES
|
2024-02-26 11:33:39 +01:00
|
|
|
src/core/database.cpp
|
|
|
|
src/core/main.cpp
|
|
|
|
src/core/message_queue.cpp
|
|
|
|
src/core/settings.cpp
|
|
|
|
src/core/slashcommands.cpp
|
|
|
|
src/core/submit_queue.cpp
|
|
|
|
src/core/translator.cpp
|
|
|
|
src/core/webhook_push.cpp
|
|
|
|
src/database/file/file.cpp
|
2024-03-23 16:57:54 +01:00
|
|
|
src/translator/deepl/deepl.cpp
|
2024-02-26 11:33:39 +01:00
|
|
|
src/translator/libretranslate/libretranslate.cpp
|
2024-03-11 05:21:01 +01:00
|
|
|
src/translator/stub/stub.cpp
|
2024-01-02 03:45:06 +01:00
|
|
|
)
|
|
|
|
|
2024-01-18 16:09:25 +01:00
|
|
|
# dtranslatebot Module Path
|
|
|
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
|
2024-01-02 03:45:06 +01:00
|
|
|
|
2024-02-13 01:47:09 +01:00
|
|
|
# Boost C++ Libraries
|
|
|
|
option(WITH_BOOST "Build with Boost C++ Libraries" OFF)
|
|
|
|
if (WITH_BOOST)
|
|
|
|
find_package(Boost COMPONENTS regex)
|
|
|
|
if (Boost_regex_FOUND)
|
|
|
|
list(APPEND DTRANSLATEBOT_LIBRARIES
|
|
|
|
Boost::regex
|
|
|
|
)
|
|
|
|
set(DTRANSLATEBOT_USE_BOOST_REGEX TRUE)
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2024-01-18 16:09:25 +01:00
|
|
|
# D++ Discord API Library for Bots
|
2024-03-11 03:45:48 +01:00
|
|
|
option(WITH_DPP_STATIC_BUNDLE "Build with DPP Static Bundle" OFF)
|
|
|
|
if (WITH_DPP_STATIC_BUNDLE)
|
|
|
|
include(DPPStaticBundle)
|
2024-02-29 20:55:33 +01:00
|
|
|
else()
|
|
|
|
find_package(DPP REQUIRED)
|
|
|
|
endif()
|
2024-01-02 03:45:06 +01:00
|
|
|
|
2024-01-18 16:09:25 +01:00
|
|
|
# pthread Support
|
|
|
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
|
|
|
find_package(Threads REQUIRED)
|
2024-01-02 03:45:06 +01:00
|
|
|
|
2024-02-26 11:33:39 +01:00
|
|
|
# dtranslatebot Win32 Shared Resources
|
|
|
|
if (WIN32)
|
|
|
|
configure_file(src/resources/win32/dtranslatebot.rc.in "${dtranslatebot_BINARY_DIR}/resources/win32/dtranslatebot.rc" @ONLY)
|
|
|
|
list(APPEND DTRANSLATEBOT_RESOURCES
|
|
|
|
"${dtranslatebot_BINARY_DIR}/resources/win32/dtranslatebot.rc"
|
|
|
|
)
|
|
|
|
endif()
|
|
|
|
|
2024-02-26 12:01:23 +01:00
|
|
|
# dtranslatebot systemd Service
|
|
|
|
if (UNIX AND NOT APPLE)
|
|
|
|
option(WITH_SYSTEMD "Build with systemd Support" OFF)
|
|
|
|
if (WITH_SYSTEMD)
|
2024-03-17 05:21:33 +01:00
|
|
|
find_program(SYSTEMD_ESCAPE_EXECUTABLE NAMES systemd-escape)
|
|
|
|
if (DEFINED SYSTEMD_ESCAPE_EXECUTABLE)
|
|
|
|
execute_process(
|
|
|
|
COMMAND "${SYSTEMD_ESCAPE_EXECUTABLE}" "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/dtranslatebot"
|
|
|
|
OUTPUT_VARIABLE dtranslatebot_SERVICE_WORKDIR
|
|
|
|
)
|
|
|
|
string(STRIP "${dtranslatebot_SERVICE_WORKDIR}" dtranslatebot_SERVICE_WORKDIR)
|
|
|
|
else()
|
|
|
|
set(dtranslatebot_SERVICE_WORKDIR "${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/dtranslatebot")
|
|
|
|
endif()
|
2024-03-12 09:40:58 +01:00
|
|
|
configure_file(src/systemd/dtranslatebot.service.in "${dtranslatebot_BINARY_DIR}/systemd/service/dtranslatebot.service" @ONLY)
|
|
|
|
configure_file(src/systemd/dtranslatebot.sysusersd.in "${dtranslatebot_BINARY_DIR}/systemd/sysusers.d/dtranslatebot.conf" @ONLY)
|
|
|
|
install(FILES "${dtranslatebot_BINARY_DIR}/systemd/service/dtranslatebot.service" DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/systemd/system")
|
|
|
|
install(FILES "${dtranslatebot_BINARY_DIR}/systemd/sysusers.d/dtranslatebot.conf" DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/sysusers.d")
|
2024-02-26 12:01:23 +01:00
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2024-01-18 16:09:25 +01:00
|
|
|
# dtranslatebot Target + Installs
|
2024-02-26 11:33:39 +01:00
|
|
|
add_executable(dtranslatebot ${DTRANSLATEBOT_HEADERS} ${DTRANSLATEBOT_SOURCES} ${DTRANSLATEBOT_RESOURCES})
|
2024-03-12 06:36:24 +01:00
|
|
|
if (WITH_DPP_STATIC_BUNDLE)
|
2024-03-02 17:42:20 +01:00
|
|
|
add_dependencies(dtranslatebot DPP)
|
|
|
|
endif()
|
2024-02-13 01:47:09 +01:00
|
|
|
target_compile_definitions(dtranslatebot PRIVATE
|
2024-03-06 16:20:47 +01:00
|
|
|
${DPP_DEFINITIONS}
|
2024-02-13 01:47:09 +01:00
|
|
|
$<$<BOOL:${DTRANSLATEBOT_USE_BOOST_REGEX}>:DTRANSLATEBOT_USE_BOOST_REGEX>
|
|
|
|
)
|
2024-02-12 18:09:46 +01:00
|
|
|
if (MSVC AND MSVC_VERSION GREATER_EQUAL 1914)
|
|
|
|
target_compile_options(dtranslatebot PRIVATE $<$<COMPILE_LANGUAGE:CXX>:/Zc:__cplusplus>)
|
|
|
|
endif()
|
2024-03-06 16:20:47 +01:00
|
|
|
target_link_libraries(dtranslatebot PRIVATE ${DTRANSLATEBOT_LIBRARIES} ${DPP_LIBRARIES} Threads::Threads)
|
2024-01-18 16:09:25 +01:00
|
|
|
target_include_directories(dtranslatebot PRIVATE ${DPP_INCLUDE_DIR})
|
|
|
|
set_target_properties(dtranslatebot PROPERTIES
|
2024-01-02 03:45:06 +01:00
|
|
|
CXX_STANDARD 17
|
|
|
|
CXX_STANDARD_REQUIRED ON
|
|
|
|
)
|
2024-01-18 16:09:25 +01:00
|
|
|
install(TARGETS dtranslatebot DESTINATION "${CMAKE_INSTALL_BINDIR}")
|