forked from d99kris/nmail
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
210 lines (186 loc) · 5.91 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
# Project
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
project(nmail LANGUAGES CXX C)
include(CheckIncludeFile)
set(CMAKE_CXX_STANDARD 14)
# Ccache
find_program(CCACHE_PROGRAM ccache)
if(CCACHE_PROGRAM)
message(STATUS "Found ccache")
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_PROGRAM}")
endif()
# Build type
set(DEFAULT_BUILD_TYPE "Release")
if((EXISTS "${CMAKE_SOURCE_DIR}/.svn") OR (EXISTS "${CMAKE_SOURCE_DIR}/.git"))
set(DEFAULT_BUILD_TYPE "RelWithDebInfo")
endif()
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
message(STATUS "Using build type '${DEFAULT_BUILD_TYPE}' (default).")
set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}")
else()
message(STATUS "Using build type '${CMAKE_BUILD_TYPE}'.")
endif()
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
# Application
add_executable(nmail
ext/apathy/path.hpp
ext/cxx-prettyprint/prettyprint.hpp
ext/cyrus-imap/lib/imapurl.c
ext/cyrus-imap/lib/imapurl.h
ext/sqlite_modern_cpp/hdr/sqlite_modern_cpp.h
src/addressbook.cpp
src/addressbook.h
src/auth.cpp
src/auth.h
src/body.cpp
src/body.h
src/cacheutil.cpp
src/cacheutil.h
src/config.cpp
src/config.h
src/contact.cpp
src/contact.h
src/crypto.cpp
src/crypto.h
src/encoding.cpp
src/encoding.h
src/flag.cpp
src/flag.h
src/header.cpp
src/header.h
src/imap.cpp
src/imap.h
src/imapcache.cpp
src/imapcache.h
src/imapindex.cpp
src/imapindex.h
src/imapmanager.cpp
src/imapmanager.h
src/lockfile.cpp
src/lockfile.h
src/log.cpp
src/log.h
src/loghelp.cpp
src/loghelp.h
src/main.cpp
src/offlinequeue.cpp
src/offlinequeue.h
src/sasl.cpp
src/sasl.h
src/searchengine.cpp
src/searchengine.h
src/serialization.h
src/sleepdetect.cpp
src/sleepdetect.h
src/smtp.cpp
src/smtp.h
src/smtpmanager.cpp
src/smtpmanager.h
src/sqlitehelp.cpp
src/sqlitehelp.h
src/status.cpp
src/status.h
src/ui.cpp
src/ui.h
src/util.cpp
src/util.h
src/version.cpp
src/version.h
)
install(TARGETS nmail DESTINATION bin)
# Platform specifics
if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
add_compile_definitions(_XOPEN_SOURCE_EXTENDED)
list(APPEND CMAKE_PREFIX_PATH /usr/local/opt/ncurses)
list(APPEND CMAKE_PREFIX_PATH /opt/homebrew/opt/ncurses)
list(APPEND OPENSSL_ROOT_DIR /usr/local/opt/openssl)
list(APPEND OPENSSL_ROOT_DIR /opt/homebrew/opt/openssl)
FIND_LIBRARY(CARBON_LIBRARY CoreFoundation)
FIND_LIBRARY(CARBON_LIBRARY CFNetwork)
FIND_LIBRARY(CARBON_LIBRARY Security)
target_link_libraries(nmail PUBLIC iconv z "-framework CoreFoundation" "-framework Security" "-framework CFNetwork")
endif()
# Headers
target_include_directories(nmail PRIVATE "ext")
# Compiler flags
set_target_properties(nmail PROPERTIES COMPILE_FLAGS
"-Wall -Wextra -Wpedantic -Wshadow -Wpointer-arith \
-Wcast-qual -Wno-missing-braces -Wswitch-default \
-Wunreachable-code -Wuninitialized -Wcast-align")
# todo: add -Wundef
# Dependency ncurses
set(CURSES_NEED_NCURSES TRUE)
set(CURSES_NEED_WIDE TRUE)
find_package(Curses REQUIRED)
include_directories(${CURSES_INCLUDE_DIR})
target_compile_options(nmail PUBLIC ${NCURSES_CFLAGS})
# Dependency openssl
find_package(OpenSSL REQUIRED)
include_directories(${OPENSSL_INCLUDE_DIR})
# Dependency xapian
find_package(Xapian REQUIRED)
# Dependency sqlite3
find_package(SQLite3 REQUIRED)
# Dependency libetpan
find_path(LIBETPAN_INCLUDE_DIR
NAMES libetpan/libetpan.h
PATHS ${additional_includes}
)
find_library(LIBETPAN_LIBRARY
NAMES etpan
PATHS ${additional_lib_searchpath}
)
if(NOT LIBETPAN_INCLUDE_DIR OR NOT LIBETPAN_LIBRARY)
message(FATAL_ERROR "ERROR: Could not find libetpan")
else()
message(STATUS "Found libetpan: ${LIBETPAN_LIBRARY}")
endif()
# Dependency sasl2
find_library(CYRUS_SASL_LIBRARY sasl2)
find_path(CYRUS_SASL_INCLUDE_DIR sasl/sasl.h PATH_SUFFIXES include)
find_package_handle_standard_args(sasl2 DEFAULT_MSG CYRUS_SASL_LIBRARY CYRUS_SASL_INCLUDE_DIR)
# Dependency execinfo / magic
CHECK_INCLUDE_FILE(execinfo.h FOUND_EXECINFO)
if(FOUND_EXECINFO)
target_compile_definitions(nmail PRIVATE HAVE_EXECINFO_H=1)
endif()
find_library(MAGIC_LIBRARY magic)
# Dependency libuuid
find_library(LIBUUID_LIBRARIES NAMES uuid)
find_path(LIBUUID_HEADERS uuid.h PATH_SUFFIXES uuid/)
if(NOT LIBUUID_LIBRARIES OR NOT LIBUUID_HEADERS)
message(FATAL_ERROR "ERROR: Could not find libuuid")
else()
message(STATUS "Found libuuid: ${LIBUUID_LIBRARIES} and ${LIBUUID_HEADERS}")
endif()
# Includes
include_directories(${LIBETPAN_INCLUDE_DIR} ${CYRUS_SASL_INCLUDE_DIR} "ext/sqlite_modern_cpp/hdr"
"ext/cereal/include" ${LIBUUID_HEADERS} "ext/cyrus-imap/lib")
# Linking
target_link_libraries(nmail PUBLIC
${CURSES_LIBRARIES} OpenSSL::SSL SQLite::SQLite3
${XAPIAN_LIBRARIES} ${LIBETPAN_LIBRARY} ${CYRUS_SASL_LIBRARY}
${MAGIC_LIBRARY} ${LIBUUID_LIBRARIES}
pthread ${CMAKE_DL_LIBS})
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
target_link_libraries(nmail PUBLIC -rdynamic)
endif()
# Manual
install(FILES src/nmail.1 DESTINATION share/man/man1)
# Utils
configure_file(src/oauth2nmail ${CMAKE_CURRENT_BINARY_DIR}/oauth2nmail COPYONLY)
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/oauth2nmail DESTINATION bin)
# Themes
macro(add_theme themename)
configure_file(themes/${themename} ${CMAKE_CURRENT_BINARY_DIR}/share/nmail/themes/${themename} COPYONLY)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/share/nmail/themes/${themename} DESTINATION share/nmail/themes)
endmacro()
add_theme("default.conf")
add_theme("htop-style.conf")
# Uninstall
add_custom_target(uninstall
COMMAND "${CMAKE_COMMAND}" -E remove "${CMAKE_INSTALL_PREFIX}/bin/nmail"
COMMAND "${CMAKE_COMMAND}" -E remove "${CMAKE_INSTALL_PREFIX}/share/man/man1/nmail.1"
COMMAND "${CMAKE_COMMAND}" -E remove "${CMAKE_INSTALL_PREFIX}/bin/oauth2nmail"
COMMAND "${CMAKE_COMMAND}" -E remove_directory "${CMAKE_INSTALL_PREFIX}/share/nmail"
)