Enable customizing the save statistics time interval
[qBittorrent.git] / cmake / Modules / CommonConfig.cmake
blobb57dc4bcf914cbda9f2d5f35c1cc5e600593891e
1 # Set platform variables and create some interface-only library targets
2 # that some or all other targets will link to, either directly or transitively,
3 # to consume common compile options/definitions
5 # treat value specified by the CXX_STANDARD target property as a requirement by default
6 set(CMAKE_CXX_STANDARD_REQUIRED ON)
7 set(CMAKE_CXX_EXTENSIONS OFF)
9 set(CMAKE_AUTOMOC ON)
10 set(CMAKE_AUTORCC ON)
11 set(CMAKE_AUTORCC_OPTIONS --compress-algo best --threshold 5)
13 add_library(qbt_common_cfg INTERFACE)
15 # C++ 20 support is required
16 # See also https://cmake.org/cmake/help/latest/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html
17 # for a breakdown of the features that CMake recognizes for each C++ standard
18 target_compile_features(qbt_common_cfg INTERFACE
19     cxx_std_20
22 target_compile_definitions(qbt_common_cfg INTERFACE
23     QT_DISABLE_DEPRECATED_UP_TO=0x060500
24     QT_NO_CAST_FROM_ASCII
25     QT_NO_CAST_TO_ASCII
26     QT_NO_CAST_FROM_BYTEARRAY
27     QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
28     QT_USE_QSTRINGBUILDER
29     QT_STRICT_ITERATORS
30     $<$<NOT:$<CONFIG:Debug>>:QT_NO_DEBUG_OUTPUT>
33 if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
34     target_compile_definitions(qbt_common_cfg INTERFACE
35         _DARWIN_FEATURE_64_BIT_INODE
36     )
37 endif()
39 if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
40     target_compile_definitions(qbt_common_cfg INTERFACE
41         NTDDI_VERSION=0x0A000006
42         _WIN32_WINNT=0x0A00
43         _WIN32_IE=0x0A00
44         WIN32_LEAN_AND_MEAN
45         NOMINMAX
46         UNICODE
47         _UNICODE
48     )
49 endif()
51 if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") OR (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang"))
52     target_compile_options(qbt_common_cfg INTERFACE
53         -Wall
54         -Wextra
55         -Wcast-qual
56         -Wcast-align
57         -Winvalid-pch
58         -Woverloaded-virtual
59         -Wold-style-cast
60         -Wnon-virtual-dtor
61         -pedantic
62         -pedantic-errors
63     )
65     # Clang 11 still doesn't support -Wstrict-null-sentinel
66     include(CheckCXXCompilerFlag)
67     check_cxx_compiler_flag(-Wstrict-null-sentinel SNS_SUPPORT)
68     if (SNS_SUPPORT)
69         target_compile_options(qbt_common_cfg INTERFACE -Wstrict-null-sentinel)
70     endif()
71 endif()
73 if ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") OR (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang"))
74     target_compile_options(qbt_common_cfg INTERFACE
75         -Wno-range-loop-analysis
76     )
77 endif()
79 if (MINGW)
80     target_link_options(qbt_common_cfg INTERFACE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:LINKER:--dynamicbase>)
81 endif()
83 if (MSVC)
84     target_compile_options(qbt_common_cfg INTERFACE
85         /guard:cf
86         /permissive-
87         /utf-8
88         # https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
89         /Zc:__cplusplus
90     )
91     target_link_options(qbt_common_cfg INTERFACE
92         /guard:cf
93         $<$<NOT:$<CONFIG:Debug>>:/OPT:REF /OPT:ICF>
94         # suppress linking warning due to /INCREMENTAL and /OPT:ICF being both ON
95         $<$<CONFIG:RelWithDebInfo>:/INCREMENTAL:NO>
96     )
98     if (MSVC_RUNTIME_DYNAMIC)
99         set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
100     else()
101         set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
102     endif()
103 endif()
105 if (DBUS)
106     target_compile_definitions(qbt_common_cfg INTERFACE QBT_USES_DBUS)
107 endif()
109 if (LibtorrentRasterbar_VERSION VERSION_GREATER_EQUAL ${minLibtorrentVersion})
110     target_compile_definitions(qbt_common_cfg INTERFACE QBT_USES_LIBTORRENT2)
111 endif()