source: trunk/CMakeLists.txt @ 14371

Last change on this file since 14371 was 14371, checked in by mikedld, 8 years ago

Fix utils test; move -Winline to C-only flags (it only harms C++)

File size: 13.0 KB
Line 
1cmake_minimum_required(VERSION 2.8.5 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(WITH_INOTIFY         "Enable inotify support (on systems that support it)" AUTO)
32tr_auto_option(WITH_KQUEUE          "Enable kqueue support (on systems that support it)" AUTO)
33tr_auto_option(WITH_SYSTEMD         "Add support for systemd startup notification (on systems that support it)" AUTO)
34
35set(TR_NAME ${PROJECT_NAME})
36
37# convention: -TR MAJOR MINOR MAINT STATUS - (each a single char)
38# STATUS: "X" for prerelease beta builds,
39#         "Z" for unsupported trunk builds,
40#         "0" for stable, supported releases
41# these should be the only two lines you need to change
42set(TR_USER_AGENT_PREFIX "2.84+")
43set(TR_PEER_ID_PREFIX "-TR284Z-")
44
45string(REGEX MATCH "^([0-9]+)\\.([0-9]+).*" TR_VERSION "${TR_USER_AGENT_PREFIX}")
46set(TR_VERSION_MAJOR "${CMAKE_MATCH_1}")
47set(TR_VERSION_MINOR "${CMAKE_MATCH_2}")
48
49if(TR_PEER_ID_PREFIX MATCHES "X-$")
50    set(TR_BETA_RELEASE 1)
51elseif(TR_PEER_ID_PREFIX MATCHES "Z-$")
52    set(TR_NIGHTLY_RELEASE 1)
53else()
54    set(TR_STABLE_RELEASE 1)
55endif()
56
57if(IS_DIRECTORY ${CMAKE_SOURCE_DIR}/.svn)
58    find_package(Subversion)
59    if(Subversion_FOUND)
60        Subversion_WC_INFO(${CMAKE_SOURCE_DIR} TR_SVN)
61        set(TR_SCM_REVISION "${TR_SVN_WC_REVISION}")
62    endif()
63
64    if("${TR_SCM_REVISION}" STREQUAL "")
65        file(GLOB_RECURSE TR_ALL_SOURCES RELATIVE ${CMAKE_SOURCE_DIR} *.cc *.[chm] *.po)
66        set(TR_SCM_REVISION 0)
67        foreach(F ${TR_ALL_SOURCES})
68            file(STRINGS ${F} F_ID REGEX "\\$Id:")
69            if(F_ID MATCHES "\\$Id: [^ ]+ ([0-9]+) " AND CMAKE_MATCH_1 GREATER TR_SCM_REVISION)
70                set(TR_SCM_REVISION ${CMAKE_MATCH_1})
71            endif()
72        endforeach()
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 "")
90    set(TR_SCM_REVISION 0)
91endif()
92
93set(CURL_MINIMUM            7.15.4)
94set(EVENT2_MINIMUM          2.0.10)
95set(OPENSSL_MINIMUM         0.9.4)
96set(ZLIB_MINIMUM            1.2.3)
97set(GTK_MINIMUM             3.4.0)
98set(GLIB_MINIMUM            2.32.0)
99set(GIO_MINIMUM             2.26.0)
100set(LIBAPPINDICATOR_MINIMUM 0.4.90)
101
102tr_github_upstream(EVENT2    libevent/libevent  be1aeff21a b9135e43c925b1f86ec43ea71a8c367a)
103tr_github_upstream(NATPMP    miniupnp/libnatpmp 31ebda6226 7e8deb00a98220622a6f2aeb98b8921b)
104tr_github_upstream(MINIUPNPC miniupnp/miniupnp  c490b42547 f9b7a4715bcd5034abae866e31102888)
105tr_github_upstream(DHT       jech/dht           bf62643a95 0a2a2abe447d8a73f0084c1bc837e566)
106tr_github_upstream(UTP       bittorrent/libutp  7c4f19abdf 8b92aa05abec5f6675cdde6477cd6f51)
107
108if(WIN32)
109    foreach(L C CXX)
110        # Target version (Vista and up)
111        set(CMAKE_${L}_FLAGS "${CMAKE_${L}_FLAGS} -DWINVER=0x0600 -D_WIN32_WINNT=0x0600")
112        # Use Unicode API (although we always use W or A names explicitly)
113        set(CMAKE_${L}_FLAGS "${CMAKE_${L}_FLAGS} -DUNICODE -D_UNICODE")
114        # Filter out needless definitions
115        set(CMAKE_${L}_FLAGS "${CMAKE_${L}_FLAGS} -DWIN32_LEAN_AND_MEAN -DNOMINMAX")
116        # Ignore various deprecation and security warnings (at least for now)
117        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")
118        # Increase maximum FD_SET size
119        set(CMAKE_${L}_FLAGS "${CMAKE_${L}_FLAGS} -DFD_SETSIZE=1024")
120        if(MSVC)
121            # Reduce noise (at least for now)
122            set(CMAKE_${L}_FLAGS "${CMAKE_${L}_FLAGS} /wd4244 /wd4267")
123        endif()
124    endforeach()
125endif()
126
127find_package(Threads)
128find_package(PkgConfig QUIET)
129
130find_package(OpenSSL ${OPENSSL_MINIMUM} REQUIRED)
131find_package(CURL ${CURL_MINIMUM} REQUIRED)
132
133if(UNIX)
134    find_package(ICONV REQUIRED)
135endif()
136
137if(ENABLE_GTK)
138    tr_get_required_flag(ENABLE_GTK GTK_IS_REQUIRED)
139
140    pkg_check_modules(GTK ${GTK_IS_REQUIRED}
141        gtk+-3.0>=${GTK_MINIMUM}
142        glib-2.0>=${GLIB_MINIMUM}
143        gio-2.0>=${GIO_MINIMUM}
144        gmodule-2.0>=${GLIB_MINIMUM}
145        gthread-2.0>=${GLIB_MINIMUM})
146
147    tr_fixup_auto_option(ENABLE_GTK GTK_FOUND GTK_IS_REQUIRED)
148
149    set(WITH_LIBAPPINDICATOR OFF)
150    if(ENABLE_GTK)
151        pkg_check_modules(LIBAPPINDICATOR appindicator3-0.1>=${LIBAPPINDICATOR_MINIMUM})
152        if(LIBAPPINDICATOR_FOUND)
153            set(WITH_LIBAPPINDICATOR ON)
154        endif()
155    endif()
156endif()
157
158if(ENABLE_QT)
159    tr_get_required_flag(ENABLE_QT QT_IS_REQUIRED)
160
161    if(POLICY CMP0020)
162        cmake_policy(SET CMP0020 NEW)
163    endif()
164
165    if(USE_QT5)
166        set(TR_QT5_MODULES Core Gui Widgets Network DBus LinguistTools)
167        set(QT_FOUND ON)
168        foreach(M ${TR_QT5_MODULES})
169            find_package(Qt5${M} ${QT_IS_REQUIRED})
170            if(NOT Qt5${M}_FOUND)
171                set(QT_FOUND OFF)
172                break()
173            endif()
174        endforeach()
175    else()
176        find_package(Qt4 4.6.2 ${QT_IS_REQUIRED} COMPONENTS QtCore QtGui QtNetwork QtDBus)
177    endif()
178
179    tr_fixup_auto_option(ENABLE_QT QT_FOUND QT_IS_REQUIRED)
180endif()
181
182find_package(ZLIB ${ZLIB_MINIMUM})
183if(ZLIB_FOUND)
184    add_definitions(-DHAVE_ZLIB)
185endif()
186
187set(THIRD_PARTY_DIR ${CMAKE_SOURCE_DIR}/third-party)
188
189if(WIN32)
190    tr_add_external_auto_library(EVENT2 event
191        PATCH_COMMAND "${CMAKE_COMMAND}" -E copy "${THIRD_PARTY_DIR}/event2.cmake" "<SOURCE_DIR>/CMakeLists.txt")
192else()
193    tr_add_external_auto_library(EVENT2 event
194        BUILD_IN_SOURCE 1
195        CONFIGURE_COMMAND "<SOURCE_DIR>/autogen.sh"
196                  COMMAND "<SOURCE_DIR>/configure" "--prefix=<INSTALL_DIR>" "--disable-shared")
197endif()
198
199tr_add_external_auto_library(NATPMP natpmp
200    PATCH_COMMAND "${CMAKE_COMMAND}" -E copy "${THIRD_PARTY_DIR}/natpmp.cmake" "<SOURCE_DIR>/CMakeLists.txt")
201if(NOT USE_SYSTEM_NATPMP)
202    set(NATPMP_DEFINITIONS -DNATPMP_STATICLIB)
203endif()
204
205tr_add_external_auto_library(MINIUPNPC miniupnpc
206    PATCH_COMMAND "${CMAKE_COMMAND}" -E remove_directory "<SOURCE_DIR>/minissdpd"
207          COMMAND "${CMAKE_COMMAND}" -E remove_directory "<SOURCE_DIR>/miniupnpc-async"
208          COMMAND "${CMAKE_COMMAND}" -E remove_directory "<SOURCE_DIR>/miniupnpc-libevent"
209          COMMAND "${CMAKE_COMMAND}" -E remove_directory "<SOURCE_DIR>/miniupnpd"
210          COMMAND "${CMAKE_COMMAND}" -E remove "<SOURCE_DIR>/README"
211          COMMAND "${CMAKE_COMMAND}" -E copy_directory "<SOURCE_DIR>/miniupnpc" "<SOURCE_DIR>"
212          COMMAND "${CMAKE_COMMAND}" -E remove_directory "<SOURCE_DIR>/miniupnpc"
213    CMAKE_ARGS
214        -DUPNPC_BUILD_STATIC=ON
215        -DUPNPC_BUILD_SHARED=OFF
216        -DUPNPC_BUILD_TESTS=OFF)
217set(MINIUPNPC_DEFINITIONS -DSYSTEM_MINIUPNP)
218if(NOT USE_SYSTEM_MINIUPNPC)
219    list(APPEND MINIUPNPC_DEFINITIONS -DMINIUPNP_STATICLIB)
220    set(MINIUPNPC_VERSION 1.9)
221    set(MINIUPNPC_API_VERSION 10)
222endif()
223
224tr_add_external_auto_library(DHT dht
225    PATCH_COMMAND "${CMAKE_COMMAND}" -E copy "${THIRD_PARTY_DIR}/dht.cmake" "<SOURCE_DIR>/CMakeLists.txt")
226
227if(ENABLE_UTP)
228    tr_add_external_auto_library(UTP utp
229        PATCH_COMMAND "${CMAKE_COMMAND}" -E copy "${THIRD_PARTY_DIR}/utp.cmake" "<SOURCE_DIR>/CMakeLists.txt"
230              COMMAND "${CMAKE_COMMAND}" -E copy "${THIRD_PARTY_DIR}/utp_config.h" "<SOURCE_DIR>/utp_config.h")
231endif()
232
233if(WITH_INOTIFY)
234    tr_get_required_flag(WITH_INOTIFY INOTIFY_IS_REQUIRED)
235
236    set(INOTIFY_FOUND OFF)
237    check_include_file(sys/inotify.h HAVE_SYS_INOTIFY_H)
238    check_function_exists(inotify_init HAVE_INOTIFY_INIT)
239    if(HAVE_SYS_INOTIFY_H AND HAVE_INOTIFY_INIT)
240        set(INOTIFY_FOUND ON)
241    endif()
242
243    tr_fixup_auto_option(WITH_INOTIFY INOTIFY_FOUND INOTIFY_IS_REQUIRED)
244endif()
245
246if(WITH_KQUEUE)
247    tr_get_required_flag(WITH_KQUEUE KQUEUE_IS_REQUIRED)
248
249    set(KQUEUE_FOUND OFF)
250    check_include_files("sys/types.h;sys/event.h" HAVE_SYS_EVENT_H)
251    check_function_exists(kqueue HAVE_KQUEUE)
252    if(HAVE_SYS_EVENT_H AND HAVE_KQUEUE)
253        set(KQUEUE_FOUND ON)
254    endif()
255
256    tr_fixup_auto_option(WITH_KQUEUE KQUEUE_FOUND KQUEUE_IS_REQUIRED)
257endif()
258
259if(WITH_SYSTEMD)
260    tr_get_required_flag(WITH_SYSTEMD SYSTEMD_IS_REQUIRED)
261
262    pkg_check_modules(SYSTEMD_DAEMON ${SYSTEMD_IS_REQUIRED} libsystemd-daemon)
263
264    tr_fixup_auto_option(WITH_SYSTEMD SYSTEMD_DAEMON_FOUND SYSTEMD_IS_REQUIRED)
265endif()
266
267include_directories(${CMAKE_BINARY_DIR})
268
269if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
270    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
271    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11")
272
273    set(NEEDED_COMPILER_FLAGS
274        -Wall
275        -W
276        -Wcast-align
277        -Wfloat-equal
278        -Wformat-security
279        -Wmissing-format-attribute
280        -Wpointer-arith
281        -Wredundant-decls
282        -Wundef
283        -Wunused-parameter
284        -Wwrite-strings)
285
286    if(NOT CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_VERSION VERSION_GREATER "3.3")
287        list(APPEND NEEDED_COMPILER_FLAGS
288            -Wextra
289            -Winit-self)
290    endif()
291
292    set(NEEDED_C_COMPILER_FLAGS
293        ${NEEDED_COMPILER_FLAGS}
294        -Winline
295        -Wmissing-declarations
296        -Wnested-externs
297        -Wstrict-prototypes)
298    string(REPLACE ";" " " NEEDED_C_COMPILER_FLAGS_STRING "${NEEDED_C_COMPILER_FLAGS}")
299    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${NEEDED_C_COMPILER_FLAGS_STRING}")
300
301    set(NEEDED_CXX_COMPILER_FLAGS
302        ${NEEDED_COMPILER_FLAGS})
303    string(REPLACE ";" " " NEEDED_CXX_COMPILER_FLAGS_STRING "${NEEDED_CXX_COMPILER_FLAGS}")
304    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${NEEDED_CXX_COMPILER_FLAGS_STRING}")
305endif()
306
307set(NEEDED_HEADERS
308    libintl.h
309    stdbool.h
310    sys/statvfs.h
311    xfs/xfs.h)
312
313foreach(H ${NEEDED_HEADERS})
314    tr_make_id("${H}" H_ID)
315    check_include_file(${H} HAVE_${H_ID})
316    if(HAVE_${H_ID})
317        add_definitions(-DHAVE_${H_ID})
318    endif()
319endforeach()
320
321set(NEEDED_FUNCTIONS
322    canonicalize_file_name
323    daemon
324    fallocate64
325    getmntent
326    getpagesize
327    htonll
328    iconv_open
329    localtime_r
330    memmem
331    mkdtemp
332    ntohll
333    posix_fadvise
334    posix_fallocate
335    posix_memalign
336    pread
337    pwrite
338    statvfs
339    strlcpy
340    strsep
341    syslog
342    valloc)
343
344foreach(F ${NEEDED_FUNCTIONS})
345    tr_make_id("${F}" F_ID)
346    check_function_exists(${F} HAVE_${F_ID})
347    if(HAVE_${F_ID})
348        add_definitions(-DHAVE_${F_ID})
349    endif()
350endforeach()
351
352if(MINGW)
353    check_function_exists(__mingw_printf HAVE_MINGW_PRINTF)
354    if(HAVE_MINGW_PRINTF)
355        add_definitions(-D__USE_MINGW_ANSI_STDIO=1 -D__STDC_FORMAT_MACROS=1)
356    endif()
357endif()
358
359check_library_exists(m sqrt "" HAVE_LIBM)
360if(HAVE_LIBM)
361    set(LIBM_LIBRARY m)
362endif()
363
364if(ENABLE_TESTS)
365    enable_testing()
366    include(CTest)
367endif()
368
369add_subdirectory(libtransmission)
370
371foreach(P daemon cli utils gtk qt)
372    string(TOUPPER "${P}" P_ID)
373    if(ENABLE_${P_ID})
374        add_subdirectory(${P})
375    endif()
376endforeach()
377
378if(ENABLE_DAEMON OR ENABLE_GTK OR ENABLE_QT)
379    install(DIRECTORY web DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${TR_NAME}
380        PATTERN *.am EXCLUDE
381        PATTERN *.scss EXCLUDE)
382endif()
383
384if(ENABLE_GTK AND ENABLE_NLS)
385    find_package(Gettext REQUIRED)
386    add_subdirectory(po)
387endif()
388
389if(INSTALL_DOC)
390    install(FILES AUTHORS COPYING NEWS README extras/rpc-spec.txt extras/send-email-when-torrent-done.sh DESTINATION ${CMAKE_INSTALL_DOCDIR})
391endif()
392
393set(CPACK_SOURCE_GENERATOR TBZ2)
394set(CPACK_SOURCE_PACKAGE_FILE_NAME "${TR_NAME}-${TR_USER_AGENT_PREFIX}")
395set(CPACK_SOURCE_IGNORE_FILES
396    \\\\.svn
397)
398
399include(CPack)
Note: See TracBrowser for help on using the repository browser.