-
Notifications
You must be signed in to change notification settings - Fork 14
/
CMakeLists.txt
285 lines (227 loc) · 8.65 KB
/
CMakeLists.txt
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
#
# Off-the-Record Messaging (OTR) module for the irssi IRC client
# Copyright (C) 2008 Uli Meis <[email protected]>
#
# This program 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 2 of the License, or
# (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,USA
#
PROJECT(irssi-otr)
CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
IF(COMMAND cmake_policy)
cmake_policy(SET CMP0003 NEW)
ENDIF(COMMAND cmake_policy)
SET(CMAKE_MODULE_PATH
${PROJECT_SOURCE_DIR}/cmake-extensions/
${PROJECT_BINARY_DIR})
INCLUDE(cmake-extensions/cscope.cmake)
INCLUDE(cmake-extensions/Git.cmake)
INCLUDE(CheckFunctionExists)
INCLUDE(CheckIncludeFile)
INCLUDE(CheckIncludeFiles)
INCLUDE(tarballdefs.cmake OPTIONAL)
# get version from git
IF(NOT IRSSIOTR_VERSION)
IF(NOT EXISTS "${PROJECT_SOURCE_DIR}/.git")
MESSAGE(FATAL_ERROR "Cannot determine the irssi-otr version since this is "
"not a git checkout. Please set IRSSIOTR_VERSION, e.g.
cmake -DIRSSIOTR_VERSION=mydistro-0.1
or
cmake -DIRSSIOTR_VERSION=mydistro-git-<git-commit>")
ENDIF(NOT EXISTS "${PROJECT_SOURCE_DIR}/.git")
FIND_GIT_TAGORCOMMIT(${PROJECT_SOURCE_DIR} IRSSIOTR_VERSION)
IF(NOT IRSSIOTR_VERSION)
MESSAGE(FATAL_ERROR
"Couldn't determine version. Please run cmake -DIRSSIOTR_VERSION=...")
ENDIF(NOT IRSSIOTR_VERSION)
ENDIF(NOT IRSSIOTR_VERSION)
MESSAGE(STATUS "Building irssi-otr version ${IRSSIOTR_VERSION}")
# PkgConfig. Only available since 2.4.7, fetch if unavailable so people with
# older cmake can run this
FIND_PACKAGE(PkgConfig QUIET)
IF(NOT PKG_CONFIG_FOUND)
MESSAGE(STATUS "Couldn't find the pkg-config cmake module. Seems you're
running cmake < 2.4.7. Will try to fetch the module from 2.4.7...")
FIND_PACKAGE(Wget REQUIRED)
EXECUTE_PROCESS(COMMAND "bash" "-c"
"${WGET_EXECUTABLE} '-O' '-' \\
'http://www.cmake.org/files/v2.4/cmake-2.4.7.tar.gz' | \\
tar xz cmake-2.4.7/Modules/FindPkgConfig.cmake && \\
mv cmake-2.4.7/Modules/FindPkgConfig.cmake . && \\
rmdir -p cmake-2.4.7/Modules"
RESULT_VARIABLE PKGCONF_RET)
IF(NOT PKGCONF_RET EQUAL 0)
MESSAGE(FATAL_ERROR "Couldnt download cmake module for pkg-config")
ENDIF(NOT PKGCONF_RET EQUAL 0)
FIND_PACKAGE(PkgConfig REQUIRED)
ENDIF(NOT PKG_CONFIG_FOUND)
# GLIB
pkg_check_modules(GLIB REQUIRED glib-2.0)
# Python
FIND_PACKAGE(PythonInterp)
IF(NOT PYTHON_EXECUTABLE)
MESSAGE(FATAL_ERROR "Couldn't find a python interpreter")
ENDIF(NOT PYTHON_EXECUTABLE)
# LIBOTR
FIND_PACKAGE(LibOTR REQUIRED)
IF (LIBOTR_VERSION LESS "3.1.0")
MESSAGE(FATAL_ERROR "Need libotr version >= 3.1.0 (fragmentation)")
ENDIF (LIBOTR_VERSION LESS "3.1.0")
# LIBGCRYPT. A dependency of libotr and therefore one of ours.
FIND_PACKAGE(LibGcrypt REQUIRED)
# includes
SET(IRSSIOTR_INCLUDE_DIRS
${PROJECT_SOURCE_DIR}
${PROJECT_BINARY_DIR}
${GLIB_INCLUDE_DIRS}
${LIBOTR_INCLUDE_DIRS})
SET(CMAKE_REQUIRED_INCLUDES ${IRSSIOTR_INCLUDE_DIRS})
SET(CMAKE_REQUIRED_DEFINITIONS -DHAVE_CONFIG_H ${LIBGCRYPT_CFLAGS})
# irssi public headers
FIND_PATH(IRSSI_INCLUDE_DIR NAMES irssi/src/core/module.h)
MARK_AS_ADVANCED(IRSSI_INCLUDE_DIR)
IF(NOT IRSSI_INCLUDE_DIR)
MESSAGE(STATUS "*** no irssi found ***")
ELSEIF(BUILDFOR AND NOT BUILDFOR STREQUAL "irssi")
MESSAGE(STATUS "*** not building for irssi ***")
ELSE(NOT IRSSI_INCLUDE_DIR)
MESSAGE(STATUS "*** building for irssi ***")
SET(HAVE_IRSSI 1)
SET(IRSSIOTR_INCLUDE_DIRS
${IRSSIOTR_INCLUDE_DIRS}
${IRSSI_INCLUDE_DIR}/irssi
${IRSSI_INCLUDE_DIR}/irssi/src
${IRSSI_INCLUDE_DIR}/irssi/src/core
${PROJECT_BINARY_DIR}/irssi-headers
${PROJECT_SOURCE_DIR}/irssi-headers)
SET(CMAKE_REQUIRED_INCLUDES ${IRSSIOTR_INCLUDE_DIRS})
# irssi statusbar header
CHECK_INCLUDE_FILES("glib.h;common.h;fe-text/statusbar-item.h" HAVE_IRSSISBAR_H)
# Bad hack
IF (NOT HAVE_IRSSISBAR_H)
MESSAGE(STATUS "Need to fetch irssi header statusbar-item.h (you don't have it yet)")
IF (NOT WGET_EXECUTABLE)
FIND_PACKAGE(Wget REQUIRED)
ENDIF (NOT WGET_EXECUTABLE)
EXECUTE_PROCESS(COMMAND "mkdir" -p irssi-headers/fe-text)
EXECUTE_PROCESS(COMMAND "bash" "-c"
"${WGET_EXECUTABLE} '--post-data=revision=4936&root=irssi' \\
'http://svn.irssi.org/cgi-bin/viewvc.cgi/irssi/trunk/src/fe-text/statusbar-item.h' || exit 1"
${PROJECT_SOURCE_DIR} WORKING_DIRECTORY irssi-headers/fe-text
RESULT_VARIABLE IISBAR_RET)
IF(NOT IISBAR_RET EQUAL 0)
MESSAGE(FATAL_ERROR "Couldn't check out irssi headers from SVN")
ENDIF(NOT IISBAR_RET EQUAL 0)
SET(HAVE_IRSSISBAR_H 1 CACHE INTERNAL "Having irssi headers" FORCE)
ENDIF (NOT HAVE_IRSSISBAR_H)
ENDIF(NOT IRSSI_INCLUDE_DIR)
FIND_PATH(HEXCHAT_INCLUDE_DIR NAMES hexchat-plugin.h)
MARK_AS_ADVANCED(HEXCHAT_INCLUDE_DIR)
IF(NOT HEXCHAT_INCLUDE_DIR)
MESSAGE(STATUS "*** no hexchat found ***")
ELSEIF(BUILDFOR AND NOT BUILDFOR STREQUAL "xchat")
MESSAGE(STATUS "*** not building for hexchat ***")
ELSE(NOT HEXCHAT_INCLUDE_DIR)
MESSAGE(STATUS "*** building for hexchat ***")
SET(HAVE_HEXCHAT 1)
SET(IRSSIOTR_INCLUDE_DIRS
${IRSSIOTR_INCLUDE_DIRS}
${HEXCHAT_INCLUDE_DIR})
ENDIF(NOT HEXCHAT_INCLUDE_DIR)
include_directories(${IRSSIOTR_INCLUDE_DIRS})
# gregex.h
# available since 2.13 AFAIK
# optional for html stripping and nick ignoring
FIND_PATH(GREGEX_FILE "glib/gregex.h" ${GLIB_INCLUDE_DIRS} NO_DEFAULT_PATH)
IF(GREGEX_FILE)
CHECK_INCLUDE_FILE("glib.h" HAVE_GREGEX_H)
ELSE()
MESSAGE(FATAL_ERROR "gregex.h not found")
ENDIF()
# check for strsignal
CHECK_FUNCTION_EXISTS(strsignal HAVE_STRSIGNAL)
# generate io-config.h
CONFIGURE_FILE(io-config.h.in io-config.h)
# defs
IF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE debug)
ENDIF(NOT CMAKE_BUILD_TYPE)
SET(CMAKE_C_FLAGS_DEBUG -g)
MESSAGE(STATUS "This is a ${CMAKE_BUILD_TYPE} build")
ADD_DEFINITIONS(-DHAVE_CONFIG_H -Wall ${LIBGCRYPT_CFLAGS})
# docdir
IF(NOT DOCDIR)
SET(DOCDIR share/doc/${CMAKE_PROJECT_NAME})
ENDIF(NOT DOCDIR)
# generate otr-formats.{c,h}
ADD_CUSTOM_COMMAND(OUTPUT
${PROJECT_BINARY_DIR}/otr-formats.c
${PROJECT_BINARY_DIR}/xchat-formats.c
DEPENDS makeformats.py formats.txt README
COMMAND
${PYTHON_EXECUTABLE}
${PROJECT_SOURCE_DIR}/makeformats.py
${PROJECT_SOURCE_DIR}/formats.txt
${PROJECT_SOURCE_DIR}/README
)
# lib
# Now that took some time to figure out...
IF(APPLE)
SET(APPLE_LDFLAGS "-single_module -undefined dynamic_lookup")
ENDIF(APPLE)
FOREACH(X ${LIBGCRYPT_LDFLAGS} ${GLIB_LDFLAGS} ${APPLE_LDFLAGS})
SET(MAIN_LDFLAGS "${MAIN_LDFLAGS} ${X}")
ENDFOREACH(X ${LIBGCRYPT_LDFLAGS} ${GLIB_LDFLAGS} ${APPLE_LDFLAGS})
IF(HAVE_IRSSI)
ADD_LIBRARY(irssiotr SHARED irssi_otr.c otr_util.c otr_ops.c otr_key.c ${PROJECT_BINARY_DIR}/otr-formats.c)
TARGET_LINK_LIBRARIES(irssiotr ${GLIB_LIBRARIES} ${LIBOTR_LIBRARIES})
SET_TARGET_PROPERTIES(irssiotr PROPERTIES
COMPILE_FLAGS -DTARGET_IRSSI
OUTPUT_NAME "otr"
LINK_FLAGS "${MAIN_LDFLAGS}")
IF(APPLE)
SET_TARGET_PROPERTIES(irssiotr PROPERTIES SUFFIX ".so")
ENDIF(APPLE)
ENDIF(HAVE_IRSSI)
IF(HAVE_HEXCHAT)
ADD_LIBRARY(hexchatotr SHARED xchat_otr.c otr_util.c otr_ops.c otr_key.c ${PROJECT_BINARY_DIR}/xchat-formats.c)
TARGET_LINK_LIBRARIES(hexchatotr ${GLIB_LIBRARIES} ${LIBOTR_LIBRARIES})
SET_TARGET_PROPERTIES(hexchatotr PROPERTIES
COMPILE_FLAGS -DTARGET_XCHAT
OUTPUT_NAME "hexchatotr"
LINK_FLAGS "${MAIN_LDFLAGS}")
IF(APPLE)
SET_TARGET_PROPERTIES(hexchatotr PROPERTIES SUFFIX ".so")
ENDIF(APPLE)
ENDIF(HAVE_HEXCHAT)
# cscope
FILE(GLOB CSANDHS *.c *.h)
ADD_CSCOPE_TARGET("${CSANDHS}" "${IRSSIOTR_INCLUDE_DIRS}")
# Install / CPack
IF(CMAKE_INSTALL_TYPE MATCHES "package-.*")
INCLUDE(Packaging.cmake)
ELSEIF(CMAKE_INSTALL_TYPE MATCHES "home")
INSTALL(TARGETS irssiotr DESTINATION "$ENV{HOME}/.irssi/modules")
ELSE(CMAKE_INSTALL_TYPE MATCHES "package-.*")
IF(HAVE_IRSSI)
INSTALL(TARGETS irssiotr DESTINATION lib${LIB_SUFFIX}/irssi/modules)
ENDIF(HAVE_IRSSI)
IF(HAVE_HEXCHAT)
INSTALL(TARGETS hexchatotr DESTINATION lib${LIB_SUFFIX}/hexchat/plugins)
ENDIF(HAVE_HEXCHAT)
INSTALL(FILES README LICENSE DESTINATION ${DOCDIR})
ENDIF(CMAKE_INSTALL_TYPE MATCHES "package-.*")
# Source tarball
ADD_CUSTOM_TARGET(src-tarball
${PROJECT_SOURCE_DIR}/mksrcpackage.sh ${PROJECT_SOURCE_DIR}
${IRSSIOTR_VERSION})