]>
Commit | Line | Data |
---|---|---|
9f5d99f5 | 1 | # |
eecb2a99 | 2 | # Copyright (C) 2003-2024 Sébastien Helleu <flashcode@flashtux.org> |
6562d676 SH |
3 | # Copyright (C) 2007-2008 Julien Louis <ptitlouis@sysif.net> |
4 | # Copyright (C) 2008-2009 Emmanuel Bouthenot <kolter@openics.org> | |
5 | # | |
6 | # This file is part of WeeChat, the extensible chat client. | |
7 | # | |
8 | # WeeChat is free software; you can redistribute it and/or modify | |
9f5d99f5 | 9 | # it under the terms of the GNU General Public License as published by |
f1a39ce7 | 10 | # the Free Software Foundation; either version 3 of the License, or |
9f5d99f5 SH |
11 | # (at your option) any later version. |
12 | # | |
6562d676 | 13 | # WeeChat is distributed in the hope that it will be useful, |
9f5d99f5 SH |
14 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | # GNU General Public License for more details. | |
17 | # | |
18 | # You should have received a copy of the GNU General Public License | |
4712d0bb | 19 | # along with WeeChat. If not, see <https://www.gnu.org/licenses/>. |
9f5d99f5 SH |
20 | # |
21 | ||
41dbcb1a | 22 | cmake_minimum_required(VERSION 3.5) |
1f787ddc | 23 | |
7618fdd2 SH |
24 | project(weechat C) |
25 | ||
33450ddb | 26 | # CMake options |
7618fdd2 | 27 | set(CMAKE_VERBOSE_MAKEFILE OFF) |
6415c09a | 28 | set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake" "${CMAKE_MODULE_PATH}") |
7618fdd2 | 29 | set(CMAKE_SKIP_RPATH ON) |
7558fe7c SH |
30 | |
31 | # compiler options | |
3070c12f | 32 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsigned-char -fms-extensions -Wall -Wextra -Werror-implicit-function-declaration -Wformat -Werror=format-security") |
7558fe7c SH |
33 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsigned-char -fms-extensions -Wall -Wextra") |
34 | if (CMAKE_C_COMPILER_ID STREQUAL "GNU") | |
35 | # extra options specific to gcc/g++ | |
36 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat-overflow=2 -Wformat-truncation=2") | |
37 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat-overflow=2 -Wformat-truncation=2") | |
38 | endif() | |
7618fdd2 | 39 | |
33450ddb | 40 | # version |
6415c09a SH |
41 | execute_process(COMMAND "${CMAKE_SOURCE_DIR}/version.sh" devel-major OUTPUT_VARIABLE VERSION_MAJOR) |
42 | execute_process(COMMAND "${CMAKE_SOURCE_DIR}/version.sh" devel-minor OUTPUT_VARIABLE VERSION_MINOR) | |
43 | execute_process(COMMAND "${CMAKE_SOURCE_DIR}/version.sh" devel-patch OUTPUT_VARIABLE VERSION_PATCH) | |
cfc1f397 SH |
44 | string(REGEX REPLACE "\n" "" VERSION_MAJOR "${VERSION_MAJOR}") |
45 | string(REGEX REPLACE "\n" "" VERSION_MINOR "${VERSION_MINOR}") | |
46 | string(REGEX REPLACE "\n" "" VERSION_PATCH "${VERSION_PATCH}") | |
33450ddb | 47 | if(VERSION_PATCH STREQUAL "") |
6415c09a | 48 | set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}") |
33450ddb | 49 | else() |
6415c09a | 50 | set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") |
33450ddb SH |
51 | endif() |
52 | ||
53 | # license | |
7618fdd2 | 54 | set(LICENSE "GPL3") |
33450ddb | 55 | |
26f415f5 SH |
56 | # add definitions for version and license |
57 | if(COMMAND cmake_policy) | |
58 | cmake_policy(SET CMP0005 NEW) | |
59 | add_definitions(-DWEECHAT_VERSION="${VERSION}" -DWEECHAT_LICENSE="${LICENSE}") | |
60 | else() | |
61 | add_definitions(-DWEECHAT_VERSION='"${VERSION}"' -DWEECHAT_LICENSE='"${LICENSE}"') | |
62 | endif() | |
63 | ||
33450ddb | 64 | # package string |
7618fdd2 SH |
65 | set(PKG_STRING "${PROJECT_NAME} ${VERSION}") |
66 | string(REPLACE "\";\"" "\ " PKG_STRING ${PKG_STRING}) | |
67 | ||
8df3ad3d | 68 | if(NOT DEFINED LIBDIR) |
6415c09a | 69 | set(LIBDIR "${CMAKE_INSTALL_PREFIX}/lib") |
8df3ad3d RF |
70 | endif() |
71 | ||
72 | if(NOT DEFINED WEECHAT_LIBDIR) | |
6415c09a | 73 | set(WEECHAT_LIBDIR "${LIBDIR}/${PROJECT_NAME}") |
7618fdd2 SH |
74 | endif() |
75 | ||
68346462 | 76 | if(NOT DEFINED DATAROOTDIR) |
6415c09a | 77 | set(DATAROOTDIR "${CMAKE_INSTALL_PREFIX}/share") |
7618fdd2 SH |
78 | endif() |
79 | ||
973a4b2e | 80 | if(NOT DEFINED WEECHAT_SHAREDIR) |
6415c09a | 81 | set(WEECHAT_SHAREDIR "${DATAROOTDIR}/weechat") |
973a4b2e ES |
82 | endif() |
83 | ||
7618fdd2 | 84 | if(NOT DEFINED MANDIR) |
6415c09a | 85 | set(MANDIR "${DATAROOTDIR}/man") |
7618fdd2 SH |
86 | endif() |
87 | ||
88 | if(NOT DEFINED LOCALEDIR) | |
6415c09a | 89 | set(LOCALEDIR "${DATAROOTDIR}/locale") |
7618fdd2 SH |
90 | endif() |
91 | ||
92 | if(DEFINED INCLUDEDIR) | |
6415c09a | 93 | set(INCLUDEDIR "${INCLUDEDIR}/${PROJECT_NAME}") |
7618fdd2 | 94 | else() |
6415c09a | 95 | set(INCLUDEDIR "${CMAKE_INSTALL_PREFIX}/include/${PROJECT_NAME}") |
7618fdd2 SH |
96 | endif() |
97 | ||
c198e875 SH |
98 | option(ENABLE_NCURSES "Compile the Ncurses interface" ON) |
99 | option(ENABLE_HEADLESS "Compile the headless binary" ON) | |
100 | option(ENABLE_NLS "Enable Native Language Support" ON) | |
101 | option(ENABLE_LARGEFILE "Enable Large File Support" ON) | |
6bd0c631 | 102 | option(ENABLE_ZSTD "Enable Zstandard compression" ON) |
8971fc06 | 103 | option(ENABLE_CJSON "Enable cJSON support" ON) |
c198e875 SH |
104 | option(ENABLE_ALIAS "Enable Alias plugin" ON) |
105 | option(ENABLE_BUFLIST "Enable Buflist plugin" ON) | |
106 | option(ENABLE_CHARSET "Enable Charset plugin" ON) | |
107 | option(ENABLE_EXEC "Enable Exec plugin" ON) | |
108 | option(ENABLE_FIFO "Enable FIFO plugin" ON) | |
109 | option(ENABLE_FSET "Enable Fast Set plugin" ON) | |
110 | option(ENABLE_IRC "Enable IRC plugin" ON) | |
111 | option(ENABLE_LOGGER "Enable Logger plugin" ON) | |
112 | option(ENABLE_RELAY "Enable Relay plugin" ON) | |
113 | option(ENABLE_SCRIPT "Enable Script plugin (script manager)" ON) | |
114 | option(ENABLE_SCRIPTS "Enable script plugins (perl, python, …)" ON) | |
115 | option(ENABLE_PERL "Enable Perl scripting language" ON) | |
116 | option(ENABLE_PYTHON "Enable Python scripting language" ON) | |
117 | option(ENABLE_RUBY "Enable Ruby scripting language" ON) | |
118 | option(ENABLE_LUA "Enable Lua scripting language" ON) | |
119 | option(ENABLE_TCL "Enable Tcl scripting language" ON) | |
120 | option(ENABLE_GUILE "Enable Scheme (guile) scripting language" ON) | |
121 | option(ENABLE_JAVASCRIPT "Enable JavaScript scripting language" OFF) | |
122 | option(ENABLE_PHP "Enable PHP scripting language" ON) | |
123 | option(ENABLE_SPELL "Enable Spell checker plugin" ON) | |
124 | option(ENABLE_ENCHANT "Use Enchant lib in Spell checker plugin" OFF) | |
125 | option(ENABLE_TRIGGER "Enable Trigger plugin" ON) | |
126 | option(ENABLE_TYPING "Enable Typing plugin" ON) | |
127 | option(ENABLE_XFER "Enable Xfer plugin" ON) | |
128 | option(ENABLE_MAN "Enable build of man page" OFF) | |
129 | option(ENABLE_DOC "Enable build of documentation" OFF) | |
130 | option(ENABLE_DOC_INCOMPLETE "Enable incomplete doc" OFF) | |
131 | option(ENABLE_TESTS "Enable tests" OFF) | |
132 | option(ENABLE_CODE_COVERAGE "Enable code coverage" OFF) | |
2612adf8 SH |
133 | |
134 | # code coverage | |
135 | add_library(coverage_config INTERFACE) | |
136 | if(ENABLE_CODE_COVERAGE) | |
137 | target_compile_options(coverage_config INTERFACE -O0 -g --coverage) | |
138 | target_link_libraries(coverage_config INTERFACE --coverage) | |
139 | endif() | |
9f5d99f5 | 140 | |
6dbfb638 SH |
141 | # headless mode is required for documentation |
142 | if(ENABLE_DOC AND NOT ENABLE_HEADLESS) | |
143 | message(FATAL_ERROR "Headless mode is required to build documentation.") | |
144 | endif() | |
145 | ||
146 | # all plugins (except javascript) are required for documentation | |
6665cc86 SH |
147 | if(ENABLE_DOC AND NOT ENABLE_DOC_INCOMPLETE |
148 | AND (NOT ENABLE_NLS OR NOT ENABLE_ALIAS OR NOT ENABLE_BUFLIST | |
a62f2dac SH |
149 | OR NOT ENABLE_CHARSET OR NOT ENABLE_EXEC OR NOT ENABLE_FIFO |
150 | OR NOT ENABLE_FSET OR NOT ENABLE_IRC OR NOT ENABLE_LOGGER | |
151 | OR NOT ENABLE_RELAY OR NOT ENABLE_SCRIPT OR NOT ENABLE_SCRIPTS | |
152 | OR NOT ENABLE_PERL OR NOT ENABLE_PYTHON OR NOT ENABLE_RUBY | |
153 | OR NOT ENABLE_LUA OR NOT ENABLE_TCL OR NOT ENABLE_GUILE | |
6dbfb638 SH |
154 | OR NOT ENABLE_PHP OR NOT ENABLE_SPELL OR NOT ENABLE_TRIGGER |
155 | OR NOT ENABLE_TYPING OR NOT ENABLE_XFER)) | |
6665cc86 SH |
156 | message( |
157 | FATAL_ERROR | |
158 | " All plugins are required to build documentation.\n" | |
159 | " If you really want to build incomplete docs, enable this option:\n" | |
160 | " -DENABLE_DOC_INCOMPLETE=ON" | |
161 | ) | |
6dbfb638 SH |
162 | endif() |
163 | ||
805717e9 SH |
164 | # headless mode is required for tests |
165 | if(ENABLE_TESTS AND NOT ENABLE_HEADLESS) | |
166 | message(FATAL_ERROR "Headless mode is required for tests.") | |
167 | endif() | |
168 | ||
87e342dd | 169 | # option WEECHAT_HOME |
7618fdd2 | 170 | set(WEECHAT_HOME "${WEECHAT_HOME}" CACHE |
53617226 | 171 | STRING "Force a single WeeChat home directory for config, logs, scripts, etc." |
34e0226e | 172 | FORCE) |
7618fdd2 | 173 | mark_as_advanced(CLEAR WEECHAT_HOME) |
34e0226e | 174 | |
91ce4017 SH |
175 | if(COMMAND cmake_policy) |
176 | if(POLICY CMP0003) | |
177 | cmake_policy(SET CMP0003 NEW) | |
178 | endif() | |
179 | if(POLICY CMP0017) | |
180 | cmake_policy(SET CMP0017 NEW) | |
181 | endif() | |
182 | endif() | |
183 | ||
184 | add_definitions(-DHAVE_CONFIG_H) | |
185 | ||
57c0a825 SH |
186 | include(FindPkgConfig) |
187 | ||
91ce4017 SH |
188 | include(CheckIncludeFiles) |
189 | include(CheckFunctionExists) | |
190 | include(CheckSymbolExists) | |
191 | ||
192 | check_include_files("langinfo.h" HAVE_LANGINFO_CODESET) | |
193 | check_include_files("sys/resource.h" HAVE_SYS_RESOURCE_H) | |
194 | ||
cb6ecb68 | 195 | check_include_files("malloc.h" HAVE_MALLOC_H) |
68598de9 | 196 | check_symbol_exists("malloc_trim" "malloc.h" HAVE_MALLOC_TRIM) |
cb6ecb68 | 197 | |
91ce4017 | 198 | check_function_exists(mallinfo HAVE_MALLINFO) |
b222e750 | 199 | check_function_exists(mallinfo2 HAVE_MALLINFO2) |
91ce4017 SH |
200 | |
201 | check_symbol_exists("eat_newline_glitch" "term.h" HAVE_EAT_NEWLINE_GLITCH) | |
202 | ||
203 | # Check for Large File Support | |
204 | if(ENABLE_LARGEFILE) | |
205 | add_definitions(-D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -D_LARGE_FILES) | |
206 | endif() | |
207 | ||
91ce4017 | 208 | # Check for libgcrypt |
bf4e47b9 | 209 | pkg_check_modules(LIBGCRYPT REQUIRED libgcrypt) |
91ce4017 | 210 | add_definitions(-DHAVE_GCRYPT) |
bf4e47b9 SH |
211 | include_directories(${LIBGCRYPT_INCLUDE_DIRS}) |
212 | list(APPEND EXTRA_LIBS ${LIBGCRYPT_LDFLAGS}) | |
91ce4017 SH |
213 | |
214 | # Check for GnuTLS | |
e130ee73 SH |
215 | find_package(GnuTLS REQUIRED) |
216 | string(REGEX REPLACE "/[^/]*$" "" GNUTLS_LIBRARY_PATH "${GNUTLS_LIBRARY}") | |
217 | include_directories(${GNUTLS_INCLUDE_PATH}) | |
218 | set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -L${GNUTLS_LIBRARY_PATH}") | |
219 | list(APPEND EXTRA_LIBS gnutls) | |
91ce4017 SH |
220 | |
221 | # Check for zlib | |
222 | find_package(ZLIB REQUIRED) | |
498194f6 SH |
223 | |
224 | # Check for zstd | |
6bd0c631 SH |
225 | if(ENABLE_ZSTD) |
226 | pkg_check_modules(LIBZSTD REQUIRED libzstd) | |
227 | add_definitions(-DHAVE_ZSTD) | |
228 | endif() | |
91ce4017 | 229 | |
8971fc06 SH |
230 | # Check for cJSON |
231 | if(ENABLE_CJSON) | |
232 | pkg_check_modules(LIBCJSON REQUIRED libcjson) | |
233 | add_definitions(-DHAVE_CJSON) | |
234 | endif() | |
235 | ||
91ce4017 SH |
236 | # Check for iconv |
237 | find_package(Iconv) | |
238 | if(ICONV_FOUND) | |
d0b95b68 | 239 | add_definitions(-DHAVE_ICONV) |
91ce4017 SH |
240 | endif() |
241 | ||
242 | # Check for CURL | |
243 | find_package(CURL REQUIRED) | |
244 | ||
245 | # weechat_gui_common MUST be the first lib in the list | |
246 | set(STATIC_LIBS weechat_gui_common) | |
247 | ||
248 | find_library(DL_LIBRARY | |
249 | NAMES dl | |
250 | PATHS /lib /usr/lib /usr/libexec /usr/local/lib /usr/local/libexec | |
251 | ) | |
252 | list(APPEND STATIC_LIBS weechat_plugins) | |
253 | if(DL_LIBRARY) | |
254 | string(REGEX REPLACE "/[^/]*$" "" DL_LIBRARY_PATH "${DL_LIBRARY}") | |
255 | set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -L${DL_LIBRARY_PATH}") | |
256 | list(APPEND EXTRA_LIBS dl) | |
257 | endif() | |
258 | ||
7aa24ecd SH |
259 | add_subdirectory(icons) |
260 | ||
7618fdd2 | 261 | if(ENABLE_NLS) |
feb5ee88 SH |
262 | find_package(Gettext REQUIRED) |
263 | add_definitions(-DENABLE_NLS) | |
1d6e1fd7 SH |
264 | find_package(Intl REQUIRED) |
265 | list(APPEND EXTRA_LIBS "${Intl_LIBRARIES}") | |
d0b95b68 | 266 | add_subdirectory(po) |
feb5ee88 SH |
267 | else() |
268 | add_custom_target(translations COMMAND true) | |
7618fdd2 | 269 | endif() |
2487d8a5 | 270 | |
d0b95b68 SH |
271 | add_subdirectory(src) |
272 | add_subdirectory(doc) | |
9f5d99f5 | 273 | |
bff40e4c SH |
274 | if(ENABLE_TESTS) |
275 | find_package(CppUTest) | |
276 | if(CPPUTEST_FOUND) | |
277 | enable_testing() | |
278 | add_subdirectory(tests) | |
279 | else() | |
280 | message(SEND_ERROR "CppUTest not found") | |
281 | endif() | |
bff143dc SH |
282 | else() |
283 | enable_testing() | |
284 | add_test(NAME notests COMMAND true) | |
db9a8e7b SH |
285 | endif() |
286 | ||
7618fdd2 | 287 | configure_file(config.h.cmake config.h @ONLY) |
07d9deaf | 288 | |
2b78673a | 289 | # set the git version in "config-git.h" |
7618fdd2 | 290 | add_custom_target(version_git ALL |
30ad9ca6 | 291 | COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tools/set_git_version.sh" "${CMAKE_CURRENT_SOURCE_DIR}" "${VERSION}" "config-git.h" |
baf8f635 SH |
292 | WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}" |
293 | ) | |
2b78673a | 294 | |
7618fdd2 | 295 | configure_file( |
07d9deaf JL |
296 | "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in" |
297 | "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" | |
baf8f635 SH |
298 | IMMEDIATE @ONLY |
299 | ) | |
07d9deaf | 300 | |
7618fdd2 | 301 | add_custom_target(uninstall |
baf8f635 SH |
302 | "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" |
303 | ) | |
07d9deaf | 304 | |
7618fdd2 | 305 | add_custom_target(dist |
5cc40052 | 306 | "${CMAKE_CURRENT_SOURCE_DIR}/tools/makedist.sh" "${VERSION}" "HEAD" "${CMAKE_CURRENT_BINARY_DIR}" |
6415c09a | 307 | WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" |
baf8f635 | 308 | ) |
07d9deaf | 309 | |
55aa9dd0 | 310 | # pkgconfig file |
7618fdd2 SH |
311 | set(PACKAGE "${PROJECT_NAME}") |
312 | set(prefix "${CMAKE_INSTALL_PREFIX}") | |
313 | set(exec_prefix "\${prefix}") | |
2712f099 | 314 | string(REPLACE "${CMAKE_INSTALL_PREFIX}" "\${prefix}" libdir "${LIBDIR}") |
7618fdd2 | 315 | set(includedir "\${prefix}/include") |
6415c09a SH |
316 | configure_file("${CMAKE_CURRENT_SOURCE_DIR}/weechat.pc.in" "${CMAKE_CURRENT_BINARY_DIR}/weechat.pc" @ONLY) |
317 | install(FILES "${CMAKE_CURRENT_BINARY_DIR}/weechat.pc" DESTINATION "${LIBDIR}/pkgconfig") | |
55aa9dd0 | 318 | |
1466a565 | 319 | # cygport file (used to build Cygwin packages) |
6415c09a | 320 | configure_file("${CMAKE_CURRENT_SOURCE_DIR}/weechat.cygport.in" "${CMAKE_CURRENT_BINARY_DIR}/weechat-${VERSION}-1.cygport" @ONLY) |
1466a565 | 321 | |
8c3b85a0 SH |
322 | # install some files (only on Cygwin) |
323 | if(CYGWIN) | |
324 | install(FILES | |
a86c329b | 325 | "${CMAKE_CURRENT_SOURCE_DIR}/AUTHORS.md" |
82604217 | 326 | "${CMAKE_CURRENT_SOURCE_DIR}/CHANGELOG.md" |
5d0784bd | 327 | "${CMAKE_CURRENT_SOURCE_DIR}/CONTRIBUTING.md" |
d0d1d2e4 | 328 | "${CMAKE_CURRENT_SOURCE_DIR}/README.md" |
3653f4b7 | 329 | "${CMAKE_CURRENT_SOURCE_DIR}/UPGRADING.md" |
6415c09a | 330 | DESTINATION "${DATAROOTDIR}/doc/${PROJECT_NAME}" |
baf8f635 | 331 | ) |
8c3b85a0 SH |
332 | endif() |
333 | ||
8054cb0e | 334 | # desktop file |
6415c09a | 335 | install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/weechat.desktop" DESTINATION "${DATAROOTDIR}/applications") |