source: trunk/CMakeLists.txt @ 14735

Last change on this file since 14735 was 14735, checked in by mikedld, 2 years ago

Bump minimum Qt version to 4.8

Earlier versions may continue to work, but we don't guarantee they will.

File size: 20.2 KB
Line 
1cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
2project(transmission)
3
4list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake)
5
6include(CheckIncludeFile)
7include(CheckIncludeFiles)
8include(CheckFunctionExists)
9include(CheckLibraryExists)
10include(ExternalProject)
11include(GNUInstallDirs)
12include(TrMacros)
13
14        option(ENABLE_DAEMON        "Build daemon" ON)
15tr_auto_option(ENABLE_GTK           "Build GTK+ client" AUTO)
16tr_auto_option(ENABLE_QT            "Build Qt client" AUTO)
17        option(ENABLE_UTILS         "Build utils (create, edit, show)" ON)
18        option(ENABLE_CLI           "Build command-line client" OFF)
19        option(ENABLE_TESTS         "Build unit tests" ON)
20        option(ENABLE_LIGHTWEIGHT   "Optimize libtransmission for low-resource systems: smaller cache size, prefer unencrypted peer connections, etc." OFF)
21        option(ENABLE_UTP           "Build µTP support" ON)
22        option(ENABLE_NLS           "Enable native language support" ON)
23        option(INSTALL_DOC          "Build/install documentation" ON)
24        option(INSTALL_LIB          "Install the library" OFF)
25        option(USE_QT5              "Use Qt 5 (instead of default Qt 4)" OFF)
26tr_auto_option(USE_SYSTEM_EVENT2    "Use system event2 library" AUTO)
27tr_auto_option(USE_SYSTEM_DHT       "Use system dht library" AUTO)
28tr_auto_option(USE_SYSTEM_MINIUPNPC "Use system miniupnpc library" AUTO)
29tr_auto_option(USE_SYSTEM_NATPMP    "Use system natpmp library" AUTO)
30tr_auto_option(USE_SYSTEM_UTP       "Use system utp library" AUTO)
31tr_auto_option(USE_SYSTEM_B64       "Use system b64 library" AUTO)
32tr_list_option(WITH_CRYPTO          "Use specified crypto library" AUTO openssl cyassl polarssl)
33tr_auto_option(WITH_INOTIFY         "Enable inotify support (on systems that support it)" AUTO)
34tr_auto_option(WITH_KQUEUE          "Enable kqueue support (on systems that support it)" AUTO)
35tr_auto_option(WITH_SYSTEMD         "Add support for systemd startup notification (on systems that support it)" AUTO)
36
37set(TR_NAME ${PROJECT_NAME})
38
39# convention: -TR MAJOR MINOR MAINT STATUS - (each a single char)
40# STATUS: "X" for prerelease beta builds,
41#         "Z" for unsupported trunk builds,
42#         "0" for stable, supported releases
43# these should be the only two lines you need to change
44set(TR_USER_AGENT_PREFIX "2.92+")
45set(TR_PEER_ID_PREFIX "-TR292Z-")
46
47string(REGEX MATCH "^([0-9]+)\\.([0-9]+).*" TR_VERSION "${TR_USER_AGENT_PREFIX}")
48set(TR_VERSION_MAJOR "${CMAKE_MATCH_1}")
49set(TR_VERSION_MINOR "${CMAKE_MATCH_2}")
50
51if(TR_PEER_ID_PREFIX MATCHES "X-$")
52    set(TR_BETA_RELEASE 1)
53elseif(TR_PEER_ID_PREFIX MATCHES "Z-$")
54    set(TR_NIGHTLY_RELEASE 1)
55else()
56    set(TR_STABLE_RELEASE 1)
57endif()
58
59set(TR_SCM_REVISION_FILE "${CMAKE_SOURCE_DIR}/REVISION")
60set(TR_SCM_REVISION_RELIABLE ON)
61
62if(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/.svn)
63    if(NOT "$ENV{JENKINS_URL}" STREQUAL "" AND NOT "$ENV{SVN_REVISION}" STREQUAL "")
64        # Jenkins automated build, use the set environment variables to avoid
65        # version mismatches between java's svn and command line's svn
66        set(TR_SCM_REVISION "$ENV{SVN_REVISION}")
67    else()
68        find_package(Subversion)
69        if(Subversion_FOUND)
70            Subversion_WC_INFO(${CMAKE_SOURCE_DIR} TR_SVN)
71            set(TR_SCM_REVISION "${TR_SVN_WC_REVISION}")
72        endif()
73    endif()
74elseif(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/.git)
75    find_package(Git)
76    if(GIT_FOUND)
77        execute_process(
78            COMMAND
79                ${GIT_EXECUTABLE} rev-list --max-count=1 --abbrev-commit HEAD
80            WORKING_DIRECTORY
81                ${CMAKE_SOURCE_DIR}
82            OUTPUT_VARIABLE
83                TR_SCM_REVISION
84            OUTPUT_STRIP_TRAILING_WHITESPACE
85        )
86    endif()
87endif()
88
89if("${TR_SCM_REVISION}" STREQUAL "" AND EXISTS "${TR_SCM_REVISION_FILE}")
90    file(READ "${TR_SCM_REVISION_FILE}" TR_SCM_REVISION)
91    string(STRIP "${TR_SCM_REVISION}" TR_SCM_REVISION)
92endif()
93
94if("${TR_SCM_REVISION}" STREQUAL "")
95    # Give up and check the source files
96    set(TR_SCM_REVISION 0)
97    set(TR_SCM_REVISION_RELIABLE OFF)
98    file(GLOB_RECURSE TR_ALL_SOURCES RELATIVE ${CMAKE_SOURCE_DIR} *.cc *.[chm] *.po)
99    foreach(F ${TR_ALL_SOURCES})
100        file(STRINGS ${F} F_ID REGEX "\\$Id:")
101        if(F_ID MATCHES "\\$Id: [^ ]+ ([0-9]+) " AND CMAKE_MATCH_1 GREATER TR_SCM_REVISION)
102            set(TR_SCM_REVISION ${CMAKE_MATCH_1})
103        endif()
104    endforeach()
105endif()
106
107if("${TR_SCM_REVISION}" STREQUAL "")
108    set(TR_SCM_REVISION 0)
109else()
110    if(TR_SCM_REVISION_RELIABLE)
111        file(WRITE "${TR_SCM_REVISION_FILE}" "${TR_SCM_REVISION}")
112    else()
113        file(REMOVE "${TR_SCM_REVISION_FILE}")
114    endif()
115endif()
116
117set_property(GLOBAL PROPERTY USE_FOLDERS ON)
118
119set(CURL_MINIMUM            7.15.4)
120set(EVENT2_MINIMUM          2.0.10)
121set(OPENSSL_MINIMUM         0.9.7)
122set(CYASSL_MINIMUM          3.0)
123set(POLARSSL_MINIMUM        1.2)
124set(ZLIB_MINIMUM            1.2.3)
125set(GTK_MINIMUM             3.4.0)
126set(GLIB_MINIMUM            2.32.0)
127set(GIO_MINIMUM             2.26.0)
128set(LIBAPPINDICATOR_MINIMUM 0.4.90)
129
130tr_github_upstream(EVENT2    transmission/libevent  c51b159cff 7be95856a39714dfd2218cb56415c990)
131tr_github_upstream(NATPMP    transmission/libnatpmp cf7f452d66 f1e7d5bf580972738d8ef21743d0adf7)
132tr_github_upstream(MINIUPNPC transmission/miniupnp  5de2bcb561 bdc5b64b9b8401d3524c50b9ec8173c1)
133tr_github_upstream(DHT       transmission/dht       cc379e406d 958253fafa01c59950d357c148aff090)
134tr_github_upstream(UTP       transmission/libutp    7c4f19abdf 8b92aa05abec5f6675cdde6477cd6f51)
135tr_github_upstream(B64       transmission/libb64    c1e3323498 10128cb30ad768d2c4caf627e0f69db3)
136
137if(WIN32)
138    foreach(L C CXX)
139        # Target version (Vista and up)
140        set(CMAKE_${L}_FLAGS "${CMAKE_${L}_FLAGS} -DWINVER=0x0600 -D_WIN32_WINNT=0x0600")
141        # Use Unicode API (although we always use W or A names explicitly)
142        set(CMAKE_${L}_FLAGS "${CMAKE_${L}_FLAGS} -DUNICODE -D_UNICODE")
143        # Ignore various deprecation and security warnings (at least for now)
144        set(CMAKE_${L}_FLAGS "${CMAKE_${L}_FLAGS} -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS")
145        # Increase maximum FD_SET size
146        set(CMAKE_${L}_FLAGS "${CMAKE_${L}_FLAGS} -DFD_SETSIZE=1024")
147        if(MSVC)
148            # Reduce noise (at least for now)
149            set(CMAKE_${L}_FLAGS "${CMAKE_${L}_FLAGS} /wd4244 /wd4267")
150        endif()
151
152        if(MINGW)
153            set(CMAKE_${L}_FLAGS "${CMAKE_${L}_FLAGS} -D__USE_MINGW_ANSI_STDIO=1")
154        endif()
155    endforeach()
156endif()
157
158find_package(Threads)
159find_package(PkgConfig QUIET)
160
161find_package(CURL ${CURL_MINIMUM} REQUIRED)
162
163find_package(ICONV)
164
165if(WITH_CRYPTO STREQUAL "AUTO" OR WITH_CRYPTO STREQUAL "openssl")
166    tr_get_required_flag(WITH_CRYPTO OPENSSL_IS_REQUIRED)
167    find_package(OpenSSL ${OPENSSL_MINIMUM} ${OPENSSL_IS_REQUIRED})
168    tr_fixup_list_option(WITH_CRYPTO "openssl" OPENSSL_FOUND "AUTO" OPENSSL_IS_REQUIRED)
169    if(WITH_CRYPTO STREQUAL "openssl")
170        set(CRYPTO_PKG "openssl")
171        set(CRYPTO_INCLUDE_DIRS ${OPENSSL_INCLUDE_DIR})
172        set(CRYPTO_LIBRARIES ${OPENSSL_LIBRARIES})
173    endif()
174endif()
175if(WITH_CRYPTO STREQUAL "AUTO" OR WITH_CRYPTO STREQUAL "cyassl")
176    tr_get_required_flag(WITH_CRYPTO CYASSL_IS_REQUIRED)
177    find_package(CyaSSL ${CYASSL_MINIMUM} ${CYASSL_IS_REQUIRED})
178    tr_fixup_list_option(WITH_CRYPTO "cyassl" CYASSL_FOUND "AUTO" CYASSL_IS_REQUIRED)
179    if(WITH_CRYPTO STREQUAL "cyassl")
180        set(CRYPTO_PKG "cyassl")
181        set(CRYPTO_INCLUDE_DIRS ${CYASSL_INCLUDE_DIRS})
182        set(CRYPTO_LIBRARIES ${CYASSL_LIBRARIES})
183    endif()
184endif()
185if(WITH_CRYPTO STREQUAL "AUTO" OR WITH_CRYPTO STREQUAL "polarssl")
186    tr_get_required_flag(WITH_CRYPTO POLARSSL_IS_REQUIRED)
187    find_package(PolarSSL ${POLARSSL_MINIMUM} ${POLARSSL_IS_REQUIRED})
188    tr_fixup_list_option(WITH_CRYPTO "polarssl" POLARSSL_FOUND "AUTO" POLARSSL_IS_REQUIRED)
189    if(WITH_CRYPTO STREQUAL "polarssl")
190        set(CRYPTO_PKG "polarssl")
191        set(CRYPTO_INCLUDE_DIRS ${POLARSSL_INCLUDE_DIRS})
192        set(CRYPTO_LIBRARIES ${POLARSSL_LIBRARIES})
193    endif()
194endif()
195# We should have found the library by now
196if(CRYPTO_PKG STREQUAL "")
197    if(WITH_CRYPTO STREQUAL "AUTO")
198        message(FATAL_ERROR "Unable to find any supported crypto library.")
199    else()
200        message(FATAL_ERROR "Requested crypto library '${WITH_CRYPTO}' is not supported.")
201    endif()
202endif()
203
204if(ENABLE_GTK)
205    tr_get_required_flag(ENABLE_GTK GTK_IS_REQUIRED)
206
207    pkg_check_modules(GTK ${GTK_IS_REQUIRED}
208        gtk+-3.0>=${GTK_MINIMUM}
209        glib-2.0>=${GLIB_MINIMUM}
210        gio-2.0>=${GIO_MINIMUM}
211        gmodule-2.0>=${GLIB_MINIMUM}
212        gthread-2.0>=${GLIB_MINIMUM})
213
214    tr_fixup_auto_option(ENABLE_GTK GTK_FOUND GTK_IS_REQUIRED)
215
216    set(WITH_LIBAPPINDICATOR OFF)
217    if(ENABLE_GTK)
218        pkg_check_modules(LIBAPPINDICATOR appindicator3-0.1>=${LIBAPPINDICATOR_MINIMUM})
219        if(LIBAPPINDICATOR_FOUND)
220            set(WITH_LIBAPPINDICATOR ON)
221        endif()
222    endif()
223endif()
224
225if(ENABLE_QT)
226    tr_get_required_flag(ENABLE_QT QT_IS_REQUIRED)
227
228    if(POLICY CMP0020)
229        cmake_policy(SET CMP0020 NEW)
230    endif()
231
232    set(QT_TARGETS)
233    set(ENABLE_QT_COM_INTEROP OFF)
234    set(ENABLE_QT_DBUS_INTEROP OFF)
235
236    if(USE_QT5)
237        set(QT5_REQUIRED_MODULES Core Gui Widgets Network LinguistTools)
238        set(QT5_OPTIONAL_MODULES DBus AxContainer AxServer)
239        foreach(M ${QT5_REQUIRED_MODULES})
240            find_package(Qt5${M} QUIET)
241            if(Qt5${M}_FOUND)
242                if(NOT M STREQUAL "LinguistTools")
243                    list(APPEND QT_TARGETS Qt5::${M})
244                endif()
245            else()
246                set(QT_TARGETS)
247                break()
248            endif()
249        endforeach()
250        if(QT_TARGETS)
251            foreach(M ${QT5_OPTIONAL_MODULES})
252                find_package(Qt5${M} QUIET)
253                if(Qt5${M}_FOUND)
254                    list(APPEND QT_TARGETS Qt5::${M})
255                endif()
256            endforeach()
257            if(Qt5AxContainer_FOUND AND Qt5AxServer_FOUND)
258                set(ENABLE_QT_COM_INTEROP ON)
259            endif()
260            if(Qt5DBus_FOUND)
261                set(ENABLE_QT_DBUS_INTEROP ON)
262            endif()
263        endif()
264    else()
265        set(QT4_REQUIRED_MODULES QtCore QtGui QtNetwork)
266        set(QT4_OPTIONAL_MODULES QtDBus QAxContainer QAxServer)
267        find_package(Qt4 4.8.0 QUIET COMPONENTS ${QT4_REQUIRED_MODULES} OPTIONAL_COMPONENTS ${QT4_OPTIONAL_MODULES})
268        foreach(M ${QT4_REQUIRED_MODULES})
269            string(TOUPPER "${M}" M_UPPER)
270            if(QT_${M_UPPER}_FOUND)
271                list(APPEND QT_TARGETS Qt4::${M})
272            else()
273                set(QT_TARGETS)
274                break()
275            endif()
276        endforeach()
277        if (QT_TARGETS)
278            foreach(M ${QT4_OPTIONAL_MODULES})
279                string(TOUPPER "${M}" M_UPPER)
280                if(QT_${M_UPPER}_FOUND)
281                    list(APPEND QT_TARGETS Qt4::${M})
282                endif()
283            endforeach()
284            if(QT_QAXCONTAINER_FOUND AND QT_QAXSERVER_FOUND)
285                set(ENABLE_QT_COM_INTEROP ON)
286            endif()
287            if(QT_QTDBUS_FOUND)
288                set(ENABLE_QT_DBUS_INTEROP ON)
289            endif()
290        endif()
291    endif()
292
293    if(ENABLE_QT_COM_INTEROP)
294        find_program(MIDL_EXECUTABLE midl)
295        if(NOT MIDL_EXECUTABLE)
296            set(ENABLE_QT_COM_INTEROP OFF)
297        endif()
298    endif()
299
300    set(QT_FOUND ON)
301    if(NOT QT_TARGETS OR NOT (ENABLE_QT_COM_INTEROP OR ENABLE_QT_DBUS_INTEROP))
302        if(QT_IS_REQUIRED)
303            message(FATAL_ERROR "Unable to find required Qt libraries.")
304        endif()
305        set(QT_FOUND OFF)
306    endif()
307
308    tr_fixup_auto_option(ENABLE_QT QT_FOUND QT_IS_REQUIRED)
309endif()
310
311find_package(ZLIB ${ZLIB_MINIMUM})
312if(ZLIB_FOUND)
313    add_definitions(-DHAVE_ZLIB)
314endif()
315
316set(THIRD_PARTY_DIR ${CMAKE_SOURCE_DIR}/third-party)
317
318if(WIN32)
319    tr_add_external_auto_library(EVENT2 event
320        PATCH_COMMAND "${CMAKE_COMMAND}" -E copy "${THIRD_PARTY_DIR}/event2.cmake" "<SOURCE_DIR>/CMakeLists.txt"
321              COMMAND "${CMAKE_COMMAND}" -E chdir "<SOURCE_DIR>" patch -p1 -i "${THIRD_PARTY_DIR}/event2-01-win32.patch"
322              COMMAND "${CMAKE_COMMAND}" -E chdir "<SOURCE_DIR>" patch -p1 -i "${THIRD_PARTY_DIR}/event2-02-win32.patch")
323else()
324    tr_add_external_auto_library(EVENT2 event
325        BUILD_IN_SOURCE 1
326        CONFIGURE_COMMAND "<SOURCE_DIR>/autogen.sh"
327                  COMMAND "<SOURCE_DIR>/configure" "--prefix=<INSTALL_DIR>" "--disable-shared")
328endif()
329
330tr_add_external_auto_library(NATPMP natpmp
331    PATCH_COMMAND "${CMAKE_COMMAND}" -E copy "${THIRD_PARTY_DIR}/natpmp.cmake" "<SOURCE_DIR>/CMakeLists.txt")
332if(NOT USE_SYSTEM_NATPMP)
333    set(NATPMP_DEFINITIONS -DNATPMP_STATICLIB)
334endif()
335
336tr_add_external_auto_library(MINIUPNPC miniupnpc
337    PATCH_COMMAND "${CMAKE_COMMAND}" -E remove_directory "<SOURCE_DIR>/minissdpd"
338          COMMAND "${CMAKE_COMMAND}" -E remove_directory "<SOURCE_DIR>/miniupnpc-async"
339          COMMAND "${CMAKE_COMMAND}" -E remove_directory "<SOURCE_DIR>/miniupnpc-libevent"
340          COMMAND "${CMAKE_COMMAND}" -E remove_directory "<SOURCE_DIR>/miniupnpd"
341          COMMAND "${CMAKE_COMMAND}" -E remove "<SOURCE_DIR>/README"
342          COMMAND "${CMAKE_COMMAND}" -E copy_directory "<SOURCE_DIR>/miniupnpc" "<SOURCE_DIR>"
343          COMMAND "${CMAKE_COMMAND}" -E remove_directory "<SOURCE_DIR>/miniupnpc"
344    CMAKE_ARGS
345        -DUPNPC_BUILD_STATIC=ON
346        -DUPNPC_BUILD_SHARED=OFF
347        -DUPNPC_BUILD_TESTS=OFF)
348set(MINIUPNPC_DEFINITIONS -DSYSTEM_MINIUPNP)
349if(NOT USE_SYSTEM_MINIUPNPC)
350    list(APPEND MINIUPNPC_DEFINITIONS -DMINIUPNP_STATICLIB)
351    set(MINIUPNPC_VERSION 1.9)
352    set(MINIUPNPC_API_VERSION 12)
353endif()
354
355tr_add_external_auto_library(DHT dht
356    PATCH_COMMAND "${CMAKE_COMMAND}" -E copy "${THIRD_PARTY_DIR}/dht.cmake" "<SOURCE_DIR>/CMakeLists.txt")
357
358if(ENABLE_UTP)
359    tr_add_external_auto_library(UTP utp
360        PATCH_COMMAND "${CMAKE_COMMAND}" -E copy "${THIRD_PARTY_DIR}/utp.cmake" "<SOURCE_DIR>/CMakeLists.txt"
361              COMMAND "${CMAKE_COMMAND}" -E copy "${THIRD_PARTY_DIR}/utp_config.h" "<SOURCE_DIR>/utp_config.h"
362              COMMAND "${CMAKE_COMMAND}" -E chdir "<SOURCE_DIR>" patch -p1 --binary -i "${THIRD_PARTY_DIR}/utp-01-ticket-5002.patch"
363              COMMAND "${CMAKE_COMMAND}" -E chdir "<SOURCE_DIR>" patch -p1 --binary -i "${THIRD_PARTY_DIR}/utp-02-win32.patch"
364              COMMAND "${CMAKE_COMMAND}" -E chdir "<SOURCE_DIR>" patch -p1 --binary -i "${THIRD_PARTY_DIR}/utp-03-msvc14.patch")
365endif()
366
367tr_add_external_auto_library(B64 b64
368    PATCH_COMMAND "${CMAKE_COMMAND}" -E copy "${THIRD_PARTY_DIR}/b64.cmake" "<SOURCE_DIR>/CMakeLists.txt"
369          COMMAND "${CMAKE_COMMAND}" -E chdir "<SOURCE_DIR>" patch -p1 -i "${THIRD_PARTY_DIR}/b64-01-newline.patch"
370          COMMAND "${CMAKE_COMMAND}" -E chdir "<SOURCE_DIR>" patch -p1 -i "${THIRD_PARTY_DIR}/b64-02-unsigned-char.patch")
371
372if(WITH_INOTIFY)
373    tr_get_required_flag(WITH_INOTIFY INOTIFY_IS_REQUIRED)
374
375    set(INOTIFY_FOUND OFF)
376    check_include_file(sys/inotify.h HAVE_SYS_INOTIFY_H)
377    check_function_exists(inotify_init HAVE_INOTIFY_INIT)
378    if(HAVE_SYS_INOTIFY_H AND HAVE_INOTIFY_INIT)
379        set(INOTIFY_FOUND ON)
380    endif()
381
382    tr_fixup_auto_option(WITH_INOTIFY INOTIFY_FOUND INOTIFY_IS_REQUIRED)
383endif()
384
385if(WITH_KQUEUE)
386    tr_get_required_flag(WITH_KQUEUE KQUEUE_IS_REQUIRED)
387
388    set(KQUEUE_FOUND OFF)
389    check_include_files("sys/types.h;sys/event.h" HAVE_SYS_EVENT_H)
390    check_function_exists(kqueue HAVE_KQUEUE)
391    if(HAVE_SYS_EVENT_H AND HAVE_KQUEUE)
392        set(KQUEUE_FOUND ON)
393    endif()
394
395    tr_fixup_auto_option(WITH_KQUEUE KQUEUE_FOUND KQUEUE_IS_REQUIRED)
396endif()
397
398if(WITH_SYSTEMD)
399    tr_get_required_flag(WITH_SYSTEMD SYSTEMD_IS_REQUIRED)
400
401    pkg_check_modules(SYSTEMD ${SYSTEMD_IS_REQUIRED} libsystemd)
402
403    tr_fixup_auto_option(WITH_SYSTEMD SYSTEMD_FOUND SYSTEMD_IS_REQUIRED)
404endif()
405
406include_directories(${CMAKE_BINARY_DIR})
407
408if(WIN32)
409    foreach(L C CXX)
410        # Filter out needless definitions
411        set(CMAKE_${L}_FLAGS "${CMAKE_${L}_FLAGS} -DWIN32_LEAN_AND_MEAN -DNOMINMAX")
412    endforeach()
413endif()
414
415if(CMAKE_VERSION VERSION_LESS "3.1")
416    if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
417        set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
418        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
419    endif()
420else()
421    set(CMAKE_C_STANDARD 99)
422    set(CMAKE_C_STANDARD_REQUIRED ON)
423    set(CMAKE_CXX_STANDARD 11)
424    set(CMAKE_CXX_STANDARD_REQUIRED ON)
425endif()
426
427if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
428    set(NEEDED_COMPILER_FLAGS
429        -Wall
430        -W
431        -Wcast-align
432        -Wfloat-equal
433        -Wmissing-format-attribute
434        -Wpointer-arith
435        -Wredundant-decls
436        -Wundef
437        -Wunused-parameter
438        -Wwrite-strings)
439
440    if(NOT CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_VERSION VERSION_GREATER "3.3")
441        list(APPEND NEEDED_COMPILER_FLAGS
442            -Wextra
443            -Winit-self)
444    endif()
445
446    if(MINGW)
447        # Disable excessive warnings since we're using __USE_MINGW_ANSI_STDIO
448        # Hopefully, any potential issues will be spotted on other platforms
449        list(APPEND NEEDED_COMPILER_FLAGS -Wno-format)
450    else()
451        list(APPEND NEEDED_COMPILER_FLAGS -Wformat-security)
452    endif()
453
454    set(NEEDED_C_COMPILER_FLAGS
455        ${NEEDED_COMPILER_FLAGS}
456        -Winline
457        -Wmissing-declarations
458        -Wnested-externs
459        -Wstrict-prototypes)
460    string(REPLACE ";" " " NEEDED_C_COMPILER_FLAGS_STRING "${NEEDED_C_COMPILER_FLAGS}")
461    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${NEEDED_C_COMPILER_FLAGS_STRING}")
462
463    set(NEEDED_CXX_COMPILER_FLAGS
464        ${NEEDED_COMPILER_FLAGS})
465    string(REPLACE ";" " " NEEDED_CXX_COMPILER_FLAGS_STRING "${NEEDED_CXX_COMPILER_FLAGS}")
466    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${NEEDED_CXX_COMPILER_FLAGS_STRING}")
467endif()
468
469include(LargeFileSupport)
470
471set(NEEDED_HEADERS
472    stdbool.h
473    sys/statvfs.h
474    xfs/xfs.h
475    xlocale.h)
476
477if(ENABLE_NLS)
478    list(APPEND NEEDED_HEADERS libintl.h)
479endif()
480
481foreach(H ${NEEDED_HEADERS})
482    tr_make_id("${H}" H_ID)
483    check_include_file(${H} HAVE_${H_ID})
484    if(HAVE_${H_ID})
485        add_definitions(-DHAVE_${H_ID})
486    endif()
487endforeach()
488
489set(NEEDED_FUNCTIONS
490    _configthreadlocale
491    canonicalize_file_name
492    daemon
493    fallocate64
494    getmntent
495    getpagesize
496    htonll
497    localtime_r
498    memmem
499    mkdtemp
500    ntohll
501    posix_fadvise
502    posix_fallocate
503    posix_memalign
504    pread
505    pwrite
506    statvfs
507    strlcpy
508    strsep
509    syslog
510    uselocale
511    valloc)
512
513foreach(F ${NEEDED_FUNCTIONS})
514    tr_make_id("${F}" F_ID)
515    check_function_exists(${F} HAVE_${F_ID})
516    if(HAVE_${F_ID})
517        add_definitions(-DHAVE_${F_ID})
518    endif()
519endforeach()
520
521if(ICONV_FOUND)
522    add_definitions(-DHAVE_ICONV)
523    if(ICONV_SECOND_ARGUMENT_IS_CONST)
524        add_definitions(-DICONV_SECOND_ARGUMENT_IS_CONST)
525    endif()
526endif()
527
528# if(MINGW)
529#     check_function_exists(__mingw_printf HAVE_MINGW_PRINTF)
530#     if(HAVE_MINGW_PRINTF)
531#         add_definitions(-D__USE_MINGW_ANSI_STDIO=1 -D__STDC_FORMAT_MACROS=1)
532#     endif()
533# endif()
534
535if(ENABLE_NLS)
536    check_library_exists(intl libintl_gettext "" HAVE_LIBINTL)
537    if(HAVE_LIBINTL)
538        set(LIBINTL_LIBRARY intl)
539    endif()
540endif()
541
542check_library_exists(m sqrt "" HAVE_LIBM)
543if(HAVE_LIBM)
544    set(LIBM_LIBRARY m)
545endif()
546
547if(ENABLE_TESTS)
548    enable_testing()
549    include(CTest)
550endif()
551
552add_subdirectory(libtransmission)
553
554foreach(P daemon cli utils gtk qt)
555    string(TOUPPER "${P}" P_ID)
556    if(ENABLE_${P_ID})
557        add_subdirectory(${P})
558    endif()
559endforeach()
560
561if(ENABLE_DAEMON OR ENABLE_GTK OR ENABLE_QT)
562    install(DIRECTORY web DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${TR_NAME}
563        PATTERN *.am EXCLUDE
564        PATTERN *.in EXCLUDE
565        PATTERN *.scss EXCLUDE)
566endif()
567
568if(ENABLE_GTK AND ENABLE_NLS)
569    find_package(Gettext REQUIRED)
570    add_subdirectory(po)
571endif()
572
573if(INSTALL_DOC)
574    install(FILES AUTHORS COPYING NEWS README extras/rpc-spec.txt extras/send-email-when-torrent-done.sh DESTINATION ${CMAKE_INSTALL_DOCDIR})
575endif()
576
577if(MSVC AND ENABLE_DAEMON AND ENABLE_QT AND ENABLE_UTILS AND USE_QT5 AND WITH_CRYPTO STREQUAL "openssl")
578    add_subdirectory(dist/msi)
579endif()
580
581set(CPACK_SOURCE_GENERATOR TBZ2)
582set(CPACK_SOURCE_PACKAGE_FILE_NAME "${TR_NAME}-${TR_USER_AGENT_PREFIX}")
583set(CPACK_SOURCE_IGNORE_FILES
584    \\\\.svn
585)
586
587include(CPack)
Note: See TracBrowser for help on using the repository browser.