-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
184 lines (173 loc) · 7.75 KB
/
CMakeLists.txt
File metadata and controls
184 lines (173 loc) · 7.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#[[**************************************************************************
* dtranslatebot Discord Translate Bot
* Copyright (C) 2023-2026 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)
cmake_policy(VERSION 3.16...4.3)
project(dtranslatebot VERSION 0.4.0 LANGUAGES CXX)
include(GNUInstallDirs)
# dtranslatebot Source files
set(DTRANSLATEBOT_HEADERS
src/core/curl_exception.h
src/core/database.h
src/core/discord_bot.h
src/core/http_headers.h
src/core/http_request.h
src/core/http_response.h
src/core/log.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
src/translator/deepl/deepl.h
src/translator/mozhi/mozhi.h
src/translator/libretranslate/libretranslate.h
src/translator/lingvatranslate/lingvatranslate.h
src/translator/stub/stub.h
)
set(DTRANSLATEBOT_SOURCES
src/core/curl_exception.cpp
src/core/database.cpp
src/core/discord_bot.cpp
src/core/http_headers.cpp
src/core/http_request.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
src/translator/deepl/deepl.cpp
src/translator/mozhi/mozhi.cpp
src/translator/libretranslate/libretranslate.cpp
src/translator/lingvatranslate/lingvatranslate.cpp
src/translator/stub/stub.cpp
)
# dtranslatebot Module Path
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# Boost C++ Libraries
option(WITH_BOOST "Build with Boost C++ Libraries" OFF)
if (WITH_BOOST)
find_package(Boost COMPONENTS regex REQUIRED)
list(APPEND DTRANSLATEBOT_LIBRARIES
Boost::regex
)
set(DTRANSLATEBOT_USE_BOOST_REGEX TRUE)
endif()
# curl Library
find_package(CURL REQUIRED)
# D++ Discord API Library for Bots
option(WITH_DPP_STATIC_BUNDLE "Build with DPP Static Bundle" OFF)
if (WITH_DPP_STATIC_BUNDLE)
include(DPPStaticBundle)
else()
find_package(DPP REQUIRED)
endif()
option(WITH_GUI "Build with dtranslatebot GUI" OFF)
if (WITH_GUI)
find_package(PkgConfig REQUIRED)
pkg_check_modules(gtkmm-4.0 REQUIRED IMPORTED_TARGET gtkmm-4.0)
list(APPEND DTRANSLATEBOT_HEADERS
src/gui/translator_dialog.h
src/gui/user_config.h
src/gui/user_interface.h
)
list(APPEND DTRANSLATEBOT_SOURCES
src/gui/main.cpp
src/gui/translator_dialog.cpp
src/gui/user_config.cpp
src/gui/user_interface.cpp
)
install(FILES src/resources/gui/de.syping.dtranslatebot.desktop DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/applications")
install(FILES src/resources/gui/dtranslatebot-16.png DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/16x16/apps" RENAME de.syping.dtranslatebot.png)
install(FILES src/resources/gui/dtranslatebot-20.png DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/20x20/apps" RENAME de.syping.dtranslatebot.png)
install(FILES src/resources/gui/dtranslatebot-24.png DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/24x24/apps" RENAME de.syping.dtranslatebot.png)
install(FILES src/resources/gui/dtranslatebot-32.png DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/32x32/apps" RENAME de.syping.dtranslatebot.png)
install(FILES src/resources/gui/dtranslatebot-48.png DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/48x48/apps" RENAME de.syping.dtranslatebot.png)
install(FILES src/resources/gui/dtranslatebot-64.png DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/64x64/apps" RENAME de.syping.dtranslatebot.png)
install(FILES src/resources/gui/dtranslatebot-96.png DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/96x96/apps" RENAME de.syping.dtranslatebot.png)
install(FILES src/resources/gui/dtranslatebot-128.png DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/128x128/apps" RENAME de.syping.dtranslatebot.png)
install(FILES src/resources/gui/dtranslatebot-256.png DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/256x256/apps" RENAME de.syping.dtranslatebot.png)
install(FILES src/resources/gui/dtranslatebot-512.png DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/icons/hicolor/512x512/apps" RENAME de.syping.dtranslatebot.png)
else()
list(APPEND DTRANSLATEBOT_SOURCES
src/cli/main.cpp
)
endif()
# pthread Support
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
# 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()
# dtranslatebot systemd Service
if (LINUX AND NOT WITH_GUI)
option(WITH_SYSTEMD "Build with systemd Support" OFF)
if (WITH_SYSTEMD)
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()
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")
endif()
endif()
# dtranslatebot Target + Installs
add_executable(dtranslatebot ${DTRANSLATEBOT_HEADERS} ${DTRANSLATEBOT_SOURCES} ${DTRANSLATEBOT_RESOURCES})
if (WITH_DPP_STATIC_BUNDLE)
add_dependencies(dtranslatebot DPP)
endif()
target_compile_definitions(dtranslatebot PRIVATE
${DPP_DEFINITIONS}
$<$<BOOL:${WITH_GUI}>:DTRANSLATEBOT_GUI>
$<$<BOOL:${DTRANSLATEBOT_USE_BOOST_REGEX}>:DTRANSLATEBOT_USE_BOOST_REGEX>
)
target_compile_options(dtranslatebot PRIVATE
$<$<AND:$<CXX_COMPILER_ID:MSVC>,$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,19.14>,$<COMPILE_LANGUAGE:CXX>>:/Zc:__cplusplus>
)
target_link_libraries(dtranslatebot PRIVATE
${DTRANSLATEBOT_LIBRARIES}
${DPP_LIBRARIES}
CURL::libcurl
Threads::Threads
$<$<BOOL:${WITH_GUI}>:PkgConfig::gtkmm-4.0>
)
target_include_directories(dtranslatebot PRIVATE
${DPP_INCLUDE_DIR}
)
set_target_properties(dtranslatebot PROPERTIES
CXX_STANDARD 17
CXX_STANDARD_REQUIRED ON
)
install(TARGETS dtranslatebot DESTINATION "${CMAKE_INSTALL_BINDIR}")