summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
blob: 7fb7d06204652dbf4d1dd99e6b375dfecdbd2160 (plain)
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
#
# Copyright (C) 2003-2017 Sébastien Helleu <flashcode@flashtux.org>
# Copyright (C) 2007-2008 Julien Louis <ptitlouis@sysif.net>
# Copyright (C) 2008-2009 Emmanuel Bouthenot <kolter@openics.org>
#
# This file is part of WeeChat, the extensible chat client.
#
# WeeChat is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# WeeChat is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with WeeChat.  If not, see <http://www.gnu.org/licenses/>.
#

cmake_minimum_required(VERSION 2.4)

project(weechat C)

# CMake options
set(CMAKE_VERBOSE_MAKEFILE OFF)
set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake ${CMAKE_MODULE_PATH})
set(CMAKE_SKIP_RPATH ON)
set(CMAKE_C_FLAGS   "${CMAKE_C_FLAGS} -Wall -Wextra -Werror-implicit-function-declaration")
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror-implicit-function-declaration")

# version
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/version.sh devel-major OUTPUT_VARIABLE VERSION_MAJOR)
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/version.sh devel-minor OUTPUT_VARIABLE VERSION_MINOR)
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/version.sh devel-patch OUTPUT_VARIABLE VERSION_PATCH)
string(REGEX REPLACE "\n" "" VERSION_MAJOR "${VERSION_MAJOR}")
string(REGEX REPLACE "\n" "" VERSION_MINOR "${VERSION_MINOR}")
string(REGEX REPLACE "\n" "" VERSION_PATCH "${VERSION_PATCH}")
if(VERSION_PATCH STREQUAL "")
  set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR})
else()
  set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
endif()

# license
set(LICENSE "GPL3")

# add definitions for version and license
if(COMMAND cmake_policy)
  cmake_policy(SET CMP0005 NEW)
  add_definitions(-DWEECHAT_VERSION="${VERSION}" -DWEECHAT_LICENSE="${LICENSE}")
else()
  add_definitions(-DWEECHAT_VERSION='"${VERSION}"' -DWEECHAT_LICENSE='"${LICENSE}"')
endif()

# package string
set(PKG_STRING "${PROJECT_NAME} ${VERSION}")
string(REPLACE "\";\"" "\ " PKG_STRING ${PKG_STRING})

if(DEFINED LIBDIR)
  set(LIBDIR ${LIBDIR}/${PROJECT_NAME})
else()
  set(LIBDIR ${CMAKE_INSTALL_PREFIX}/lib/${PROJECT_NAME})
endif()

if(NOT DEFINED SHAREDIR)
  set(SHAREDIR ${CMAKE_INSTALL_PREFIX}/share)
endif()

if(NOT DEFINED MANDIR)
  set(MANDIR ${SHAREDIR}/man)
endif()

if(NOT DEFINED LOCALEDIR)
  set(LOCALEDIR ${SHAREDIR}/locale)
endif()

if(DEFINED INCLUDEDIR)
  set(INCLUDEDIR ${INCLUDEDIR}/${PROJECT_NAME})
else()
  set(INCLUDEDIR ${CMAKE_INSTALL_PREFIX}/include/${PROJECT_NAME})
endif()

option(ENABLE_NCURSES    "Enable Ncurses interface"                  ON)
option(ENABLE_NLS        "Enable Native Language Support"            ON)
option(ENABLE_GNUTLS     "Enable SSLv3/TLS support"                  ON)
option(ENABLE_LARGEFILE  "Enable Large File Support"                 ON)
option(ENABLE_ALIAS      "Enable Alias plugin"                       ON)
option(ENABLE_ASPELL     "Enable Aspell plugin"                      ON)
option(ENABLE_ENCHANT    "Enable Enchant lib for Aspell plugin"      OFF)
option(ENABLE_BUFLIST    "Enable Buflist plugin"                     ON)
option(ENABLE_CHARSET    "Enable Charset plugin"                     ON)
option(ENABLE_EXEC       "Enable Exec plugin"                        ON)
option(ENABLE_FIFO       "Enable FIFO plugin"                        ON)
option(ENABLE_FSET       "Enable Fast Set plugin"                    ON)
option(ENABLE_IRC        "Enable IRC plugin"                         ON)
option(ENABLE_LOGGER     "Enable Logger plugin"                      ON)
option(ENABLE_RELAY      "Enable Relay plugin"                       ON)
option(ENABLE_SCRIPT     "Enable Script plugin (scripts manager)"    ON)
option(ENABLE_SCRIPTS    "Enable script plugins (perl, python, ...)" ON)
option(ENABLE_PERL       "Enable Perl scripting language"            ON)
option(ENABLE_PYTHON     "Enable Python scripting language"          ON)
option(ENABLE_PYTHON3    "Use Python 3.x if found (NOT recommended because many \"official\" scripts won't work)" OFF)
option(ENABLE_RUBY       "Enable Ruby scripting language"            ON)
option(ENABLE_LUA        "Enable Lua scripting language"             ON)
option(ENABLE_TCL        "Enable Tcl scripting language"             ON)
option(ENABLE_GUILE      "Enable Scheme (guile) scripting language"  ON)
option(ENABLE_JAVASCRIPT "Enable JavaScript scripting language"      ON)
option(ENABLE_PHP        "Enable PHP scripting language"             ON)
option(ENABLE_TRIGGER    "Enable Trigger plugin"                     ON)
option(ENABLE_XFER       "Enable Xfer plugin"                        ON)
option(ENABLE_MAN        "Enable build of man page"                  OFF)
option(ENABLE_DOC        "Enable build of documentation"             OFF)
option(ENABLE_TESTS      "Enable tests"                              OFF)

# option WEECHAT_HOME
if(NOT DEFINED WEECHAT_HOME OR "${WEECHAT_HOME}" STREQUAL "")
  set(WEECHAT_HOME "~/.weechat")
endif()
set(WEECHAT_HOME "${WEECHAT_HOME}" CACHE
  STRING "WeeChat home directory for config, logs, scripts.. (default is \"~/.weechat\")"
  FORCE)
mark_as_advanced(CLEAR WEECHAT_HOME)

# option CA_FILE
if(NOT DEFINED CA_FILE OR "${CA_FILE}" STREQUAL "")
  set(CA_FILE "/etc/ssl/certs/ca-certificates.crt")
endif()
set(CA_FILE "${CA_FILE}" CACHE
  STRING "File containing the certificate authorities (default is \"/etc/ssl/certs/ca-certificates.crt\"). This is the default value of option \"weechat.network.gnutls_ca_file\"."
  FORCE)
mark_as_advanced(CLEAR CA_FILE)

if(COMMAND cmake_policy)
  if(POLICY CMP0003)
    cmake_policy(SET CMP0003 NEW)
  endif()
  if(POLICY CMP0017)
    cmake_policy(SET CMP0017 NEW)
  endif()
endif()

add_definitions(-DHAVE_CONFIG_H)

include(CheckIncludeFiles)
include(CheckFunctionExists)
include(CheckSymbolExists)

check_include_files("langinfo.h" HAVE_LANGINFO_CODESET)
check_include_files("sys/resource.h" HAVE_SYS_RESOURCE_H)

check_function_exists(mallinfo HAVE_MALLINFO)

check_symbol_exists("eat_newline_glitch" "term.h" HAVE_EAT_NEWLINE_GLITCH)

# Check for Large File Support
if(ENABLE_LARGEFILE)
  add_definitions(-D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -D_LARGE_FILES)
endif()

# Check for Gettext
if(ENABLE_NLS)
  find_package(Gettext)
  if(GETTEXT_FOUND)
    add_definitions(-DENABLE_NLS)
  endif()
endif()

# Check for libgcrypt
find_package(GCRYPT REQUIRED)
add_definitions(-DHAVE_GCRYPT)
list(APPEND EXTRA_LIBS ${GCRYPT_LDFLAGS})

# Check for GnuTLS
if(ENABLE_GNUTLS)
  find_package(GnuTLS)
  if(GNUTLS_FOUND)
    string(REGEX REPLACE "/[^/]*$" "" GNUTLS_LIBRARY_PATH "${GNUTLS_LIBRARY}")
    add_definitions(-DHAVE_GNUTLS)
    include_directories(${GNUTLS_INCLUDE_PATH})
    set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -L${GNUTLS_LIBRARY_PATH}")
    list(APPEND EXTRA_LIBS gnutls)
  endif()
endif()

# Check for zlib
find_package(ZLIB REQUIRED)
add_definitions(-DHAVE_ZLIB)

# Check for iconv
find_package(Iconv)
if(ICONV_FOUND)
  add_definitions(-DHAVE_ICONV)
endif()

# Check for CURL
find_package(CURL REQUIRED)

# weechat_gui_common MUST be the first lib in the list
set(STATIC_LIBS weechat_gui_common)

find_library(DL_LIBRARY
  NAMES dl
  PATHS /lib /usr/lib /usr/libexec /usr/local/lib /usr/local/libexec
)
list(APPEND STATIC_LIBS weechat_plugins)
if(DL_LIBRARY)
  string(REGEX REPLACE "/[^/]*$" "" DL_LIBRARY_PATH "${DL_LIBRARY}")
  set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -L${DL_LIBRARY_PATH}")
  list(APPEND EXTRA_LIBS dl)
endif()

if(ENABLE_NLS)
  add_subdirectory(po)
endif()

add_subdirectory(src)
add_subdirectory(doc)

find_package(CppUTest)
if(ENABLE_TESTS AND CPPUTEST_FOUND)
  enable_testing()
  add_subdirectory(tests)
endif()

configure_file(config.h.cmake config.h @ONLY)

# set the git version in "config-git.h"
add_custom_target(version_git ALL
  COMMAND "${CMAKE_CURRENT_SOURCE_DIR}/tools/git-version.sh" "${CMAKE_CURRENT_SOURCE_DIR}" "${VERSION}" "config-git.h"
  WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")

configure_file(
  "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
  "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
  IMMEDIATE @ONLY)

add_custom_target(uninstall
  "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")

add_custom_target(dist
  "${CMAKE_CURRENT_SOURCE_DIR}/tools/makedist.sh" "${VERSION}" "HEAD" "${CMAKE_CURRENT_BINARY_DIR}"
  WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

# pkgconfig file
set(PACKAGE "${PROJECT_NAME}")
set(prefix "${CMAKE_INSTALL_PREFIX}")
set(exec_prefix "\${prefix}")
set(libdir "\${exec_prefix}/lib")
set(includedir "\${prefix}/include")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/weechat.pc.in ${CMAKE_CURRENT_BINARY_DIR}/weechat.pc @ONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/weechat.pc DESTINATION ${LIBDIR}/../pkgconfig)

# cygport file (used to build Cygwin packages)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/weechat.cygport.in ${CMAKE_CURRENT_BINARY_DIR}/weechat-${VERSION}-1.cygport @ONLY)

# install some files (only on Cygwin)
if(CYGWIN)
  install(FILES
    ${CMAKE_CURRENT_SOURCE_DIR}/AUTHORS.adoc
    ${CMAKE_CURRENT_SOURCE_DIR}/ChangeLog.adoc
    ${CMAKE_CURRENT_SOURCE_DIR}/Contributing.adoc
    ${CMAKE_CURRENT_SOURCE_DIR}/README.adoc
    ${CMAKE_CURRENT_SOURCE_DIR}/ReleaseNotes.adoc
    DESTINATION ${SHAREDIR}/doc/${PROJECT_NAME})
endif()

# icon
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/weechat.png DESTINATION ${SHAREDIR}/icons/hicolor/32x32/apps)

# packages
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Fast, light and extensible chat client")
set(CPACK_PACKAGE_VENDOR "Sébastien Helleu")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.adoc")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING")
set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})

# binary package
set(CPACK_GENERATOR "STGZ;TGZ;TBZ2")
set(CPACK_PACKAGE_FILE_NAME weechat-binary-${VERSION})

# source package
set(CPACK_SOURCE_GENERATOR "TGZ;TBZ2")
set(CPACK_SOURCE_PACKAGE_FILE_NAME weechat-${VERSION})
set(CPACK_SOURCE_IGNORE_FILES "/\\\\.git" "/build/" "/m4/"
  "/autom4te\\\\.cache/" "/ABOUT-NLS$" "/config\\\\.guess$" "/config\\\\.h$"
  "/config\\\\.h.in$" "/config\\\\.log$" "/config\\\\.rpath$"
  "/config\\\\.status$" "/config\\\\.sub$" "/configure$" "/depcomp$"
  "/install-sh$" "/missing$" "/intl/" "/libtool$" "/\\\\.libs/"
  "/ltmain\\\\.sh$" "/\\\\.deps/" "/html/" "/html1/" "/Makefile$"
  "/Makefile\\\\.in$" "stamp" "/po/.*\\\\.header$" "\\\\.gmo$" "~$" "\\\\.o$"
  "\\\\.lo$" "\\\\.a$" "\\\\.la$" "\\\\.lai$" "\\\\.Plo$" "/weechat$"
)

include(CPack)