CMakeLists.txt 12.2 KB
Newer Older
1
cmake_minimum_required(VERSION 3.5)
2

Laurent Montel's avatar
Laurent Montel committed
3
set(PIM_VERSION "5.14.40")
4
project(Akonadi VERSION ${PIM_VERSION})
Will Stephenson's avatar
Will Stephenson committed
5

Daniel Vrátil's avatar
Daniel Vrátil committed
6
if (MSVC)
7
    # On Windows our target compiler is MSVC 14.14, which supports C++17, so
Daniel Vrátil's avatar
Daniel Vrátil committed
8
9
10
11
12
13
14
    # we can enable it. MSVC does not ship experimental/optional and similar
    # and disallows use of C++17 classes in C++14 mode.
    set(CMAKE_CXX_STANDARD 17)
else()
    # On Linux, MacOS and BSD we need to support older compilers that only
    # offer C++14.
    set(CMAKE_CXX_STANDARD 14)
15
    set(WITH_3RDPARTY_OPTIONAL TRUE)
Daniel Vrátil's avatar
Daniel Vrátil committed
16
endif()
17

18

19
# ECM setup
20
set(KF5_MIN_VERSION "5.68.0")
Laurent Montel's avatar
Laurent Montel committed
21

22
find_package(ECM ${KF5_MIN_VERSION} CONFIG REQUIRED)
Laurent Montel's avatar
Laurent Montel committed
23

24
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules)
Will Stephenson's avatar
Will Stephenson committed
25

26
27
28
29
include(KDEInstallDirs)
include(KDECMakeSettings)
include(KDEFrameworkCompilerSettings NO_POLICY_SCOPE)

30
include(GenerateExportHeader)
Daniel Vrátil's avatar
Daniel Vrátil committed
31
include(ECMGenerateHeaders)
32
include(ECMGeneratePriFile)
33

34
include(ECMSetupVersion)
35
include(FeatureSummary)
36
include(CheckIncludeFiles)
37
include(ECMQtDeclareLoggingCategory)
38
include(CheckSymbolExists)
39

40
include(KDEPackageAppTemplates)
Laurent Montel's avatar
Laurent Montel committed
41
include(ECMMarkNonGuiExecutable)
David Faure's avatar
David Faure committed
42
include(ECMAddTests)
43
44
45

include(AkonadiMacros)

46
set(QT_REQUIRED_VERSION "5.12.0")
47
set(RELEASE_SERVICE_VERSION "20.03.80")
48
set(AKONADI_FULL_VERSION "${PIM_VERSION} (${RELEASE_SERVICE_VERSION})")
49
50
51

configure_file(akonadifull-version.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/akonadifull-version.h @ONLY)

52

53
ecm_setup_version(PROJECT
54
55
    VARIABLE_PREFIX AKONADI
    VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/akonadi_version.h"
56
    PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KF5AkonadiConfigVersion.cmake"
57
58
59
    SOVERSION 5)

# Find packages
60
61
62
63
64
65
66
find_package(Qt5Core ${QT_REQUIRED_VERSION} REQUIRED COMPONENTS Private)
find_package(Qt5Sql ${QT_REQUIRED_VERSION} REQUIRED COMPONENTS Private)
find_package(Qt5DBus ${QT_REQUIRED_VERSION} REQUIRED)
find_package(Qt5Network ${QT_REQUIRED_VERSION} REQUIRED)
find_package(Qt5Test ${QT_REQUIRED_VERSION} REQUIRED)
find_package(Qt5Widgets ${QT_REQUIRED_VERSION} REQUIRED)
find_package(Qt5Xml ${QT_REQUIRED_VERSION} REQUIRED)
67

68
69
70
71
72
73
74
75
76
77
78
79
find_package(KF5Config ${KF5_MIN_VERSION} CONFIG REQUIRED)
find_package(KF5ConfigWidgets ${KF5_MIN_VERSION} CONFIG REQUIRED)
find_package(KF5CoreAddons ${KF5_MIN_VERSION} CONFIG REQUIRED)
find_package(KF5I18n ${KF5_MIN_VERSION} CONFIG REQUIRED)
find_package(KF5IconThemes ${KF5_MIN_VERSION} CONFIG REQUIRED)
find_package(KF5ItemModels ${KF5_MIN_VERSION} CONFIG REQUIRED)
find_package(KF5ItemViews ${KF5_MIN_VERSION} CONFIG REQUIRED)
find_package(KF5KIO ${KF5_MIN_VERSION} CONFIG REQUIRED)
find_package(KF5WidgetsAddons ${KF5_MIN_VERSION} CONFIG REQUIRED)
find_package(KF5WindowSystem ${KF5_MIN_VERSION} CONFIG REQUIRED)
find_package(KF5XmlGui ${KF5_MIN_VERSION} CONFIG REQUIRED)
find_package(KF5Crash ${KF5_MIN_VERSION} CONFIG REQUIRED)
80
81
82
83
84
85
find_package(Qt5Designer NO_MODULE)
set_package_properties(Qt5Designer PROPERTIES
   PURPOSE "Required to build the Qt Designer plugins"
   TYPE OPTIONAL
)

86
87
option(BUILD_DESIGNERPLUGIN "Build plugin for Qt Designer" ON)
add_feature_info(DESIGNERPLUGIN ${BUILD_DESIGNERPLUGIN} "Build plugin for Qt Designer")
88

Daniel Vrátil's avatar
Daniel Vrátil committed
89
set(Boost_MINIMUM_VERSION "1.34.0")
90
find_package(Boost ${Boost_MINIMUM_VERSION})
Daniel Vrátil's avatar
Daniel Vrátil committed
91
set_package_properties(Boost PROPERTIES
92
    DESCRIPTION "Boost C++ Libraries"
93
    URL "https://www.boost.org"
94
    TYPE REQUIRED
95
)
96

97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
set(AccountsQt5_MINIMUM_VERSION "1.15")
find_package(AccountsQt5 ${AccountsQt5_MINIMUM_VERSION})
set_package_properties(AccountsQt5 PROPERTIES
    DESCRIPTION "Qt bindings for the Accounts framework"
    URL "https://gitlab.com/accounts-sso/libaccounts-qt"
    TYPE OPTIONAL
)
set(KAccounts_MINIMUM_VERSION "19.08.0")
find_package(KAccounts ${KAccounts_MINIMUM_VERSION})
set_package_properties(KAccounts PROPERTIES
    DESCRIPTION "KDE library for Accounts framework integration"
    URL "https://cgit.kde.org/kaccounts-integration.git"
    TYPE OPTIONAL
)
if (${AccountsQt5_FOUND} AND ${KAccounts_FOUND})
    set(WITH_ACCOUNTS TRUE)
endif()

115

116
117
if(BUILD_TESTING)
    set(AKONADI_TESTS_EXPORT AKONADICORE_EXPORT)
Laurent Montel's avatar
Laurent Montel committed
118
    set(AKONADIWIDGET_TESTS_EXPORT AKONADIWIDGETS_EXPORT)
119
    add_definitions(-DBUILD_TESTING)
120
endif()
Daniel Vrátil's avatar
Daniel Vrátil committed
121
configure_file(akonaditests_export.h.in "${CMAKE_CURRENT_BINARY_DIR}/akonaditests_export.h")
Laurent Montel's avatar
Laurent Montel committed
122
configure_file(akonadiwidgetstests_export.h.in "${CMAKE_CURRENT_BINARY_DIR}/akonadiwidgetstests_export.h")
123
124
125
126
127
128
129
130
131

# Make sure the KF5Akonadi_DATA_DIR is absolute before passing it to KF5AkonadiConfig.cmake.in
# otherwise build fails either on OSX CI, or for normal users
if (IS_ABSOLUTE "${KDE_INSTALL_DATADIR_KF5}")
    set(KF5Akonadi_DATA_DIR "${KDE_INSTALL_DATADIR_KF5}/akonadi")
else()
    set(KF5Akonadi_DATA_DIR "${CMAKE_INSTALL_PREFIX}/${KDE_INSTALL_DATADIR_KF5}/akonadi")
endif()

132
133
check_symbol_exists(malloc_trim "malloc.h" HAVE_MALLOC_TRIM)

134
135
############### Build Options ###############
option(AKONADI_BUILD_QSQLITE "Build the Sqlite backend." TRUE)
136
option(BUILD_TOOLS "Build and install tools for development and testing purposes." TRUE)
137
option(NO_REGENERATE_MIME "Don't regenerate mime file (developer-only option)" FALSE )
138
option(INSTALL_APPARMOR "Install AppArmor profiles" TRUE)
139
140
141
142

if(BUILD_TESTING)
   set(BUILD_TOOLS TRUE)
endif()
143

Laurent Montel's avatar
Laurent Montel committed
144
set(SMI_MIN_VERSION "1.3")
145
find_package(SharedMimeInfo ${SMI_MIN_VERSION} REQUIRED)
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

find_program(XSLTPROC_EXECUTABLE xsltproc)
if(NOT XSLTPROC_EXECUTABLE)
    message(FATAL_ERROR "\nThe command line XSLT processor program 'xsltproc'  could not be found.\nPlease install xsltproc.\n")
endif()

find_program(MYSQLD_EXECUTABLE NAMES mysqld
    PATHS /usr/sbin /usr/local/sbin /usr/libexec /usr/local/libexec /opt/mysql/libexec /usr/mysql/bin /opt/mysql/sbin
    DOC "The mysqld executable path. ONLY needed at runtime"
)

if(MYSQLD_EXECUTABLE)
    message(STATUS "MySQL Server found: ${MYSQLD_EXECUTABLE}")
else()
    message(STATUS "MySQL Server wasn't found. it is required to use the MySQL backend.")
endif()

find_path(POSTGRES_PATH NAMES pg_ctl
    HINTS /usr/lib${LIB_SUFFIX}/postgresql/8.4/bin
          /usr/lib${LIB_SUFFIX}/postgresql/9.0/bin
          /usr/lib${LIB_SUFFIX}/postgresql/9.1/bin
          DOC "The pg_ctl executable path. ONLY needed at runtime by the PostgreSQL backend"
)

if(POSTGRES_PATH)
    message(STATUS "PostgreSQL Server found.")
else()
    message(STATUS "PostgreSQL wasn't found. it is required to use the Postgres backend.")
endif()


if("${DATABASE_BACKEND}" STREQUAL "SQLITE")
    set(SQLITE_TYPE "REQUIRED")
else()
    set(SQLITE_TYPE "OPTIONAL")
endif()

183
if(AKONADI_BUILD_QSQLITE)
184
185
186
    set(SQLITE_MIN_VERSION 3.6.23)
    find_package(Sqlite ${SQLITE_MIN_VERSION})
    set_package_properties(Sqlite PROPERTIES
187
        URL "https://www.sqlite.org"
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
        DESCRIPTION "The Sqlite database library"
        TYPE ${SQLITE_TYPE}
        PURPOSE "Required by the Sqlite backend"
    )
endif()

find_program(XMLLINT_EXECUTABLE xmllint)
if(NOT XMLLINT_EXECUTABLE)
    message(STATUS "xmllint not found, skipping akonadidb.xml schema validation")
endif()

check_include_files(unistd.h HAVE_UNISTD_H)
if(HAVE_UNISTD_H)
    add_definitions(-DHAVE_UNISTD_H)
endif()
203

204
205
206
207
208
209
if (IS_ABSOLUTE "${DBUS_INTERFACES_INSTALL_DIR}")
    set(AKONADI_DBUS_INTERFACES_INSTALL_DIR "${DBUS_INTERFACES_INSTALL_DIR}")
else()
    set(AKONADI_DBUS_INTERFACES_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${DBUS_INTERFACES_INSTALL_DIR}")
endif()

210
211
212
213
if (IS_ABSOLUTE "${KDE_INSTALL_INCLUDEDIR_KF5}")
    set(AKONADI_INCLUDE_DIR "${KDE_INSTALL_INCLUDEDIR_KF5}")
else()
    set(AKONADI_INCLUDE_DIR "${CMAKE_INSTALL_PREFIX}/${KDE_INSTALL_INCLUDEDIR_KF5}")
Raymond Wooninck's avatar
Raymond Wooninck committed
214
endif()
215

Christophe Giboudeaux's avatar
Christophe Giboudeaux committed
216
217
############### Build Options ###############

218
include(CTest)  # Calls enable_testing().
Bertjan Broeksema's avatar
Bertjan Broeksema committed
219
include(CTestConfig.cmake)
220

221
if(NOT DEFINED DATABASE_BACKEND)
222
    set(DATABASE_BACKEND "MYSQL" CACHE STRING "The default database backend to use for Akonadi. Can be either MYSQL, POSTGRES or SQLITE")
223
endif()
224

225
226
227
228
229
230
############### CTest options ###############
# Set a timeout value of 1 minute per test
set(DART_TESTING_TIMEOUT 60)

# CTestCustom.cmake has to be in the CTEST_BINARY_DIR.
# in the KDE build system, this is the same as CMAKE_BINARY_DIR.
Christophe Giboudeaux's avatar
Christophe Giboudeaux committed
231
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/CTestCustom.cmake ${CMAKE_CURRENT_BINARY_DIR}/CTestCustom.cmake COPYONLY)
232

233
234
235
############### Macros ###############

macro(SET_DEFAULT_DB_BACKEND)
236
237
    set(_backend ${ARGV0})
    if("${_backend}" STREQUAL "SQLITE")
238
        set(AKONADI_DATABASE_BACKEND QSQLITE3)
239
        set(AKONADI_BUILD_QSQLITE TRUE)
240
    else()
241
        if("${_backend}" STREQUAL "POSTGRES")
242
243
244
          set(AKONADI_DATABASE_BACKEND QPSQL)
        else()
          set(AKONADI_DATABASE_BACKEND QMYSQL)
245
        endif()
246
247
    endif()

248
    message(STATUS "Using default db backend ${AKONADI_DATABASE_BACKEND}")
249
    add_definitions(-DAKONADI_DATABASE_BACKEND="${AKONADI_DATABASE_BACKEND}")
250
endmacro()
251
252

#### DB BACKEND DEFAULT ####
253
set_default_db_backend(${DATABASE_BACKEND})
254

255
############### Compilers flags ###############
Christophe Giboudeaux's avatar
Christophe Giboudeaux committed
256

257
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_C_COMPILER MATCHES "icc" OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
258
    set(CMAKE_C_FLAGS   "${CMAKE_C_FLAGS} -Wno-long-long -std=iso9899:1990 -Wundef -Wcast-align -Werror-implicit-function-declaration -Wchar-subscripts -Wall -Wextra -Wpointer-arith -Wwrite-strings -Wformat-security -Wmissing-format-attribute -fno-common")
Daniel Vrátil's avatar
Daniel Vrátil committed
259
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wnon-virtual-dtor -Wundef -Wcast-align -Wchar-subscripts -Wall -Wextra -Wpointer-arith -Wformat-security -fno-common -pedantic")
Daniel Vrátil's avatar
Daniel Vrátil committed
260

261
262
263
    set(CMAKE_CXX_FLAGS_DEBUGFULL "-g3 -fno-inline" CACHE STRING "Flags used by the C++ compiler during debugfull builds." FORCE)
    set(CMAKE_C_FLAGS_DEBUGFULL   "-g3 -fno-inline" CACHE STRING "Flags used by the C compiler during debugfull builds." FORCE)
    mark_as_advanced(CMAKE_CXX_FLAGS_DEBUGFULL CMAKE_C_FLAGS_DEBUGFULL)
264
265
266
267
elseif (MSVC)
    # This sets the __cplusplus macro to a real value based on the version of C++ specified by
    # the /std switch. Without it MSVC keeps reporting C++98, so feature detection doesn't work.
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:__cplusplus")
268
endif()
Will Stephenson's avatar
Will Stephenson committed
269

270

Volker Krause's avatar
Volker Krause committed
271
if(MSVC)
272
    set(_ENABLE_EXCEPTIONS -EHsc)
273
274
else()
    set(_ENABLE_EXCEPTIONS -fexceptions)
Volker Krause's avatar
Volker Krause committed
275
276
endif()

277
278
279
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${_ENABLE_EXCEPTIONS}")

############### Configure files #############
280

281
configure_file(config-akonadi.h.cmake ${Akonadi_BINARY_DIR}/config-akonadi.h)
282

Christophe Giboudeaux's avatar
Christophe Giboudeaux committed
283
############### build targets ###############
284

285
add_definitions(-DTRANSLATION_DOMAIN=\"libakonadi5\")
286

287
288
289
290
291
include_directories(
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_CURRENT_BINARY_DIR}
    src
)
292

293
#add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0x050e00)
294

295
add_subdirectory(src)
296
add_subdirectory(icons)
297

298
299
add_subdirectory(templates)

300
301
302
303
304
305
306
307
if(BUILD_TOOLS)
    # add testrunner (application for managing a self-contained
    # test environment)
    add_subdirectory(autotests/libs/testrunner)
    add_subdirectory(autotests/libs/testresource)
    add_subdirectory(autotests/libs/testsearchplugin)
endif()

308
if(BUILD_TESTING)
309
310
    add_subdirectory(autotests)
    add_subdirectory(tests)
311
endif()
312

313
314
315
if(INSTALL_APPARMOR)
   add_subdirectory(apparmor)
endif()
Christophe Giboudeaux's avatar
Christophe Giboudeaux committed
316
317

############### install stuff ###############
318
319

install(FILES akonadi-mime.xml DESTINATION ${XDG_MIME_INSTALL_DIR})
320
321
322
if (NOT NO_REGENERATE_MIME)
   update_xdg_mimetypes(${XDG_MIME_INSTALL_DIR})
endif()   
323

324
############### CMake Config Files ###############
325

326
set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/KF5Akonadi")
327

328
configure_package_config_file(
329
330
    "${CMAKE_CURRENT_SOURCE_DIR}/KF5AkonadiConfig.cmake.in"
    "${CMAKE_CURRENT_BINARY_DIR}/KF5AkonadiConfig.cmake"
331
    INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR}
332
333
334
    PATH_VARS AKONADI_DBUS_INTERFACES_INSTALL_DIR
              AKONADI_INCLUDE_DIR
              KF5Akonadi_DATA_DIR
335
336
337
)

install(FILES
338
339
340
    "${CMAKE_CURRENT_BINARY_DIR}/KF5AkonadiConfig.cmake"
    "${CMAKE_CURRENT_BINARY_DIR}/KF5AkonadiConfigVersion.cmake"
    "${CMAKE_CURRENT_SOURCE_DIR}/KF5AkonadiMacros.cmake"
341
342
343
    DESTINATION "${CMAKECONFIG_INSTALL_DIR}"
    COMPONENT Devel
)
344

345
install(EXPORT
346
    KF5AkonadiTargets
347
    DESTINATION "${CMAKECONFIG_INSTALL_DIR}"
348
    FILE KF5AkonadiTargets.cmake
349
    NAMESPACE KF5::)
350

351
ecm_qt_install_logging_categories(
Laurent Montel's avatar
Laurent Montel committed
352
353
354
355
        EXPORT AKONADI
        FILE akonadi.categories
        DESTINATION ${KDE_INSTALL_LOGGINGCATEGORIESDIR}
        )
356

Daniel Vrátil's avatar
Daniel Vrátil committed
357
install(FILES
358
    ${CMAKE_CURRENT_BINARY_DIR}/akonadi_version.h
359
    DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5} COMPONENT Devel
360
)
361

362
feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)