catch gpgme errors, it's better.
[apps/madmutt.git] / CMakeLists.txt
1 SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake/Modules)
2
3 PROJECT(madmutt C D)
4 SET(PACKAGE madmutt)
5
6 # Using Phobos OR Tango (can be specified from cmake command line)
7 if (NOT CMAKE_D_USE_PHOBOS AND NOT CMAKE_D_USE_TANGO)
8     # default to phobos
9     message(STATUS "This application can be built with either Phobos or Tango!")
10     message(STATUS "You did not specify a standard library -- defaulting to Phobos.")
11     message(STATUS "If you wish to use Tango add -DCMAKE_D_USE_TANGO=True to cmake command line.")
12     set(CMAKE_D_USE_PHOBOS True)
13 endif (NOT CMAKE_D_USE_PHOBOS AND NOT CMAKE_D_USE_TANGO)
14
15 include(Cpkg2c)
16 include(XConfig)
17
18 ADD_DEFINITIONS(-DHAVE_CONFIG_H)
19 ADD_DEFINITIONS(-D_GNU_SOURCE)
20 INCLUDE_DIRECTORIES(${madmutt_BINARY_DIR} ${madmutt_SOURCE_DIR})
21
22 SET(BINDIR     "${CMAKE_INSTALL_PREFIX}/bin")
23 SET(DATADIR    "${CMAKE_INSTALL_PREFIX}/share")
24 SET(PKGDATADIR "${CMAKE_INSTALL_PREFIX}/share/madmutt")
25 SET(PKGDOCDIR  "${CMAKE_INSTALL_PREFIX}/share/doc/madmutt")
26 SET(SYSCONFDIR "${CMAKE_INSTALL_PREFIX}/etc")
27 SET(VERSION    "devel")
28 SET(MUTTLIBS   "")
29
30 ADD_DEFINITIONS("-DBINDIR=\\\"${BINDIR}\\\"")
31 ADD_DEFINITIONS("-DPKGDATADIR=\\\"${PKGDATADIR}\\\"")
32 ADD_DEFINITIONS("-DPKGDOCDIR=\\\"${PKGDOCDIR}\\\"")
33 ADD_DEFINITIONS("-DSYSCONFDIR=\\\"${SYSCONFDIR}\\\"")
34 ADD_DEFINITIONS("-DVERSION=\\\"${VERSION}\\\"")
35 ADD_DEFINITIONS("-DMUTTLOCALEDIR=\\\"${DATADIR}/locale\\\"")
36
37 SET(MAILPATH         CACHE STRING "Where new mail is spooled")
38 OPTION(WITH_GPGME    "Use GPGME [default: on]" ON)
39 OPTION(WITH_IDN      "Use GNU libidn for domain names [default: off]")
40
41 OPTION(USE_FLOCK     "Use flock to lock files [default: off]")
42 OPTION(USE_FCNTL     "Use fcntl to lock files [default: on]" ON)
43 OPTION(USE_HCACHE    "Enable headers caching  [default: off]")
44
45 FIND_FILE(SENDMAIL sendmail
46     PATHS /usr/sbin /sbin /usr/lib
47     DOC   "path to sendmail executable"
48 )
49
50 IF(NOT MAILPATH)
51     IF(EXISTS /var/mail)
52         SET(MAILPATH "/var/mail")
53     ELSEIF(EXISTS /var/spool/mail)
54         SET(MAILPATH "/var/spool/mail")
55     ELSEIF(EXISTS /usr/spool/mail)
56         SET(MAILPATH "/usr/spool/mail")
57     ELSEIF(EXISTS /usr/mail)
58         SET(MAILPATH "/usr/mail")
59     ELSE(EXISTS /var/mail)
60         MESSAGE(FATAL_ERROR "Unable to determine MAILPATH")
61     ENDIF(EXISTS /var/mail)
62 ENDIF(NOT MAILPATH)
63
64 # headers {{{
65 INCLUDE(CheckIncludeFile)
66
67 CHECK_INCLUDE_FILE(alloca.h               HAVE_ALLOCA_H)
68 CHECK_INCLUDE_FILE(argz.h                 HAVE_ARGZ_H)
69 CHECK_INCLUDE_FILE(getopt.h               HAVE_GETOPT_H)
70 CHECK_INCLUDE_FILE(iconv.h                HAVE_ICONV_H)
71 CHECK_INCLUDE_FILE(inttypes.h             HAVE_INTTYPES_H)
72 CHECK_INCLUDE_FILE(ioctl.h                HAVE_IOCTL_H)
73 CHECK_INCLUDE_FILE(langinfo.h             HAVE_LANGINFO_H)
74 CHECK_INCLUDE_FILE(limits.h               HAVE_LIMITS_H)
75 CHECK_INCLUDE_FILE(locale.h               HAVE_LOCALE_H)
76 CHECK_INCLUDE_FILE(memory.h               HAVE_MEMORY_H)
77 CHECK_INCLUDE_FILE(ncursesw/ncurses.h     HAVE_NCURSESW_NCURSES_H)
78 CHECK_INCLUDE_FILE(regex.h                HAVE_REGEX_H)
79 CHECK_INCLUDE_FILE(stdarg.h               HAVE_STDARG_H)
80 CHECK_INCLUDE_FILE(stddef.h               HAVE_STDDEF_H)
81 CHECK_INCLUDE_FILE(stdint.h               HAVE_STDINT_H)
82 CHECK_INCLUDE_FILE(stdlib.h               HAVE_STDLIB_H)
83 CHECK_INCLUDE_FILE(string.h               HAVE_STRING_H)
84 CHECK_INCLUDE_FILE(strings.h              HAVE_STRINGS_H)
85 CHECK_INCLUDE_FILE(sysexits.h             HAVE_SYSEXITS_H)
86 CHECK_INCLUDE_FILE(sys/ioctl.h            HAVE_SYS_IOCTL_H)
87 CHECK_INCLUDE_FILE(sys/param.h            HAVE_SYS_PARAM_H)
88 CHECK_INCLUDE_FILE(sys/resource.h         HAVE_SYS_RESOURCE_H)
89 CHECK_INCLUDE_FILE(sys/stat.h             HAVE_SYS_STAT_H)
90 CHECK_INCLUDE_FILE(sys/time.h             HAVE_SYS_TIME_H)
91 CHECK_INCLUDE_FILE(sys/types.h            HAVE_SYS_TYPES_H)
92 CHECK_INCLUDE_FILE(unistd.h               HAVE_UNISTD_H)
93 CHECK_INCLUDE_FILE(unix.h                 HAVE_UNIX_H)
94 CHECK_INCLUDE_FILE(wchar.h                HAVE_WCHAR_H)
95 CHECK_INCLUDE_FILE(wctype.h               HAVE_WCTYPE_H)
96
97 IF(NOT HAVE_ICONV_H)
98     MESSAGE(FATAL_ERROR "inconv.h not found")
99 ENDIF(NOT HAVE_ICONV_H)
100
101 # }}}
102 # types {{{
103
104 INCLUDE(CheckStructMember)
105
106 CHECK_STRUCT_MEMBER("struct dirent" "d_ino" "dirent.h" HAVE_DIRENT_D_INO)
107
108 # }}}
109 # functions {{{
110 INCLUDE (CheckFunctionExists)
111
112 CHECK_FUNCTION_EXISTS(strlimit    HAVE_SETRLIMIT)
113 CHECK_FUNCTION_EXISTS(getsid      HAVE_GETSID)
114 CHECK_FUNCTION_EXISTS(setegid     HAVE_SETEGID)
115 CHECK_FUNCTION_EXISTS(getopt      HAVE_GETOPT)
116 CHECK_FUNCTION_EXISTS(nl_langinfo HAVE_LANGINFO_CODESET)
117
118 # }}}
119 # libraries {{{
120 INCLUDE(CheckLibraryExists)
121 INCLUDE(FindPkgConfig)
122
123 FIND_LIBRARY(LIBUTIL NAMES util)
124 IF(NOT LIBUTIL)
125     MESSAGE(FATAL_ERROR "could not find libutil")
126 ENDIF(NOT LIBUTIL)
127 LIST(APPEND MUTTLIBS -lutil)
128
129 FIND_LIBRARY(NCURSESW NAMES ncursesw)
130 IF(NOT NCURSESW OR NOT HAVE_NCURSESW_NCURSES_H)
131     MESSAGE(FATAL_ERROR "could not libncursesw")
132 ENDIF(NOT NCURSESW OR NOT HAVE_NCURSESW_NCURSES_H)
133 SET(CMAKE_REQUIRED_INCLUDES "ncursesw/ncurses.h")
134 LIST(APPEND MUTTLIBS -lncursesw)
135
136 pkg_search_module(LUA REQUIRED lua5.1)
137 ADD_DEFINITIONS(${LUA_CFLAGS})
138 LIST(APPEND MUTTLIBS ${LUA_LDFLAGS})
139
140 IF(WITH_GPGME)
141     XCONFIG(gpgme-config gpgme_INCDIR gpgme_LINKDIR gpgme_LDFLAGS gpgme_CFLAGS)
142     INCLUDE_DIRECTORIES(${gpgme_INCDIR})
143     ADD_DEFINITIONS(${gpgme_CFLAGS})
144     LIST(APPEND MUTTLIBS ${gpgme_LDFLAGS})
145     SET(HAVE_GPGME 1)
146 ENDIF(WITH_GPGME)
147
148 XCONFIG(libgnutls-config gnutls_INCDIR gnutls_LINKDIR gnutls_LDFLAGS gnutls_CFLAGS)
149 INCLUDE_DIRECTORIES(${gnutls_INCDIR})
150 ADD_DEFINITIONS(${gnutls_CFLAGS})
151 CHECK_INCLUDE_FILE(gnutls/openssl.h  HAVE_GNUTLS_OPENSSL_H)
152 LIST(APPEND MUTTLIBS ${gnutls_LDFLAGS})
153
154 CHECK_LIBRARY_EXISTS(sasl2 sasl_client_init "" WITH_SASL)
155 IF(NOT WITH_SASL)
156     MESSAGE(FATAL_ERROR "sasl2 not found")
157 ENDIF(NOT WITH_SASL)
158 LIST(APPEND MUTTLIBS -lsasl2)
159
160 IF(WITH_IDN)
161     pkg_search_module(IDN REQUIRED libidn)
162     LIST(APPEND MUTTLIBS ${IDN_LDFLAGS})
163     SET(HAVE_LIBIDN 1)
164 ENDIF(WITH_IDN)
165
166 CHECK_LIBRARY_EXISTS(lockfile lockfile_create "" WITH_LOCKFILE)
167 IF(NOT WITH_LOCKFILE)
168     MESSAGE(FATAL_ERROR "lockfile not found")
169 ENDIF(NOT WITH_LOCKFILE)
170 LIST(APPEND MUTTLIBS -llockfile)
171
172 IF(USE_HCACHE)
173     OPTION(WITH_QDBM "Use qdbm for header caching [default: on]" ON)
174     OPTION(WITH_GDBM "Use gdbm for header caching [default: off]")
175     SET(USE_HCACHE)
176
177     IF(WITH_QDBM)
178         pkg_search_module(QDBM REQUIRED qdbm)
179         ADD_DEFINITIONS(${QDBM_CFLAGS})
180         SET(QDBM_LDFLAGS "${QDBM_LDFLAGS}")
181         # LIST(APPEND MUTTLIBS ${QDBM_LDFLAGS})
182         LIST(APPEND MUTTLIBS -lqdbm)
183         SET(USE_HCACHE 1)
184         SET(HAVE_QDBM 1)
185     ENDIF(WITH_QDBM)
186
187     IF(NOT USE_HCACHE AND WITH_GDBM)
188         CHECK_LIBRARY_EXISTS(gdbm gdbm_open "" GDBM)
189         IF(NOT GDBM)
190             MESSAGE(FATAL_ERROR "gdbm not found")
191         ENDIF(NOT GDBM)
192         LIST(APPEND MUTTLIBS -lgdbm)
193         SET(USE_HCACHE 1)
194         SET(HAVE_GDBM 1)
195     ENDIF(NOT USE_HCACHE AND WITH_GDBM)
196
197     IF(NOT USE_HCACHE)
198         MESSAGE(FATAL_ERROR "no backend for header caching selected")
199     ENDIF(NOT USE_HCACHE)
200 ENDIF(USE_HCACHE)
201
202 # }}}
203 # C flags {{{
204 # big debug flags
205 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99 -ggdb3")
206 # Use pipes and not temp files.
207 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -pipe")
208 # optimize even more
209 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2")
210 # let the type char be unsigned by default
211 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -funsigned-char")
212 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstrict-aliasing")
213 # turn on all common warnings
214 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall")
215 # turn on extra warnings
216 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W")
217 # treat warnings as errors
218 #SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Werror")
219 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wchar-subscripts")
220 # warn about undefined preprocessor identifiers
221 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wundef")
222 # warn about local variable shadowing another local variable
223 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow")
224 # warn about casting of pointers to increased alignment requirements
225 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wcast-align")
226 # make string constants const
227 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wwrite-strings")
228 # warn about comparisons between signed and unsigned values
229 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wsign-compare")
230 # warn about unused declared stuff
231 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wunused")
232 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-unused-parameter")
233 # warn about variable use before initialization
234 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wuninitialized")
235 # warn about variables which are initialized with themselves
236 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Winit-self")
237 # warn about pointer arithmetic on void* and function pointers
238 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wpointer-arith")
239 # warn about multiple declarations
240 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wredundant-decls")
241 # warn if the format string is not a string literal
242 #SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wformat-nonliteral")
243 # do not warn about zero-length formats.
244 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-format-zero-length")
245 # missing prototypes
246 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-prototypes")
247 # warn about functions without format attribute that should have one
248 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wmissing-format-attribute")
249 # }}}
250 # D flags {{{
251 # big debug flags
252 SET(CMAKE_D_FLAGS "${CMAKE_D_FLAGS} -ggdb3")
253 # Use pipes and not temp files.
254 SET(CMAKE_D_FLAGS "${CMAKE_D_FLAGS} -pipe")
255 # optimize even more
256 SET(CMAKE_D_FLAGS "${CMAKE_D_FLAGS} -O2")
257 # let the type char be unsigned by default
258 SET(CMAKE_D_FLAGS "${CMAKE_D_FLAGS} -funsigned-char")
259 SET(CMAKE_D_FLAGS "${CMAKE_D_FLAGS} -fstrict-aliasing")
260 # turn on all common warnings
261 SET(CMAKE_D_FLAGS "${CMAKE_D_FLAGS} -Wall")
262 # turn on extra warnings
263 SET(CMAKE_D_FLAGS "${CMAKE_D_FLAGS} -W")
264 # treat warnings as errors
265 #SET(CMAKE_D_FLAGS "${CMAKE_D_FLAGS} -Werror")
266 # warn about local variable shadowing another local variable
267 SET(CMAKE_D_FLAGS "${CMAKE_D_FLAGS} -Wshadow")
268 # warn about casting of pointers to increased alignment requirements
269 SET(CMAKE_D_FLAGS "${CMAKE_D_FLAGS} -Wcast-align")
270 # warn about comparisons between signed and unsigned values
271 SET(CMAKE_D_FLAGS "${CMAKE_D_FLAGS} -Wsign-compare")
272 # warn about unused declared stuff
273 SET(CMAKE_D_FLAGS "${CMAKE_D_FLAGS} -Wunused")
274 SET(CMAKE_D_FLAGS "${CMAKE_D_FLAGS} -Wno-unused-parameter")
275 # warn about variable use before initialization
276 SET(CMAKE_D_FLAGS "${CMAKE_D_FLAGS} -Wuninitialized")
277 # let's read GPGME's Reference Manual
278 SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FILE_OFFSET_BITS=64")
279 # }}}
280
281 CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h)
282
283 # we generate some includes
284 ADD_SUBDIRECTORY(lib-lib)
285 ADD_SUBDIRECTORY(lib-mime)
286 ADD_SUBDIRECTORY(lib-sys)
287 ADD_SUBDIRECTORY(lib-ui)
288 ADD_SUBDIRECTORY(imap)
289 ADD_SUBDIRECTORY(lib-mx)
290 ADD_SUBDIRECTORY(lib-lua)
291 ADD_SUBDIRECTORY(po)
292
293 MADMUTT_SOURCES(madmuttsrc madmuttgen
294     alias.cpkg
295     buffy.cpkg
296     charset.cpkg
297     crypt.cpkg
298     score.cpkg
299
300     account.c
301     attach.c
302     commands.c
303     compose.c
304     copy.c
305     editmsg.c
306     flags.c
307     handler.c
308     headers.c
309     help.c
310     hook.c
311     init.c
312     keymap.c
313     mutt_idna.c
314     muttlib.c
315     mutt_sasl.c
316     pager.c
317     pattern.c
318     pop.c
319     postpone.c
320     recvattach.c
321     recvcmd.c
322     send.c
323     sendlib.c
324     sort.c
325     state.c
326     thread.c
327
328     main.c
329 )
330
331 STRING(REGEX REPLACE ";" " " MUTTLIBS "${MUTTLIBS}")
332 ADD_EXECUTABLE(madmutt ${madmuttsrc})
333 TARGET_LINK_LIBRARIES(madmutt mime sys mx lua ui imap lib)
334 SET_TARGET_PROPERTIES(madmutt PROPERTIES
335     LINK_FLAGS "${MUTTLIBS}"
336     #    LINKER_LANGUAGE D
337 )
338
339 # generate_files hack {{{
340
341 ADD_CUSTOM_COMMAND(
342     OUTPUT  ${madmutt_SOURCE_DIR}/keymap_defs.h
343     DEPENDS ${madmutt_SOURCE_DIR}/OPS ${madmutt_SOURCE_DIR}/tools/gen_defs
344     COMMAND ${madmutt_SOURCE_DIR}/tools/gen_defs ${madmutt_SOURCE_DIR}/OPS > ${madmutt_SOURCE_DIR}/keymap_defs.h
345     COMMENT "Generating ${madmutt_SOURCE_DIR}/keymap_defs.h from ${madmutt_SOURCE_DIR}/OPS"
346 )
347 ADD_CUSTOM_COMMAND(
348     OUTPUT  ${madmutt_SOURCE_DIR}/charset.gperf
349     DEPENDS ${madmutt_SOURCE_DIR}/charset.def
350     COMMAND sh ${madmutt_SOURCE_DIR}/charset.def > ${madmutt_SOURCE_DIR}/charset.gperf
351     COMMENT "Generating ${madmutt_SOURCE_DIR}/charset.gperf from ${madmutt_SOURCE_DIR}/charset.def"
352 )
353 ADD_CUSTOM_TARGET(generate_file
354     DEPENDS ${madmuttgen}
355     ${madmutt_SOURCE_DIR}/keymap_defs.h
356     ${madmutt_SOURCE_DIR}/charset.gperf
357 )
358 ADD_DEPENDENCIES(generate_file generate_files)
359 ADD_DEPENDENCIES(madmutt generate_file)
360
361 # }}}