Merge pull request #17125 from sledgehammer999/cmake_lupdate
[qBittorrent.git] / cmake / Modules / MacroQbtCommonConfig.cmake
blobe703437f46438febb31de1fa18880a373709b8f0
1 # Set common 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 macro(qbt_common_config)
6     # treat value specified by the CXX_STANDARD target property as a requirement by default
7     set(CMAKE_CXX_STANDARD_REQUIRED ON)
8     set(CMAKE_CXX_EXTENSIONS OFF)
10     add_library(qbt_common_cfg INTERFACE)
12     # Full C++ 17 support is required
13     # See also https://cmake.org/cmake/help/latest/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html
14     # for a breakdown of the features that CMake recognizes for each C++ standard
15     target_compile_features(qbt_common_cfg INTERFACE
16         cxx_std_17
17     )
19     target_compile_definitions(qbt_common_cfg INTERFACE
20         QT_DISABLE_DEPRECATED_BEFORE=0x050f02
21         QT_NO_CAST_FROM_ASCII
22         QT_NO_CAST_TO_ASCII
23         QT_NO_CAST_FROM_BYTEARRAY
24         QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
25         QT_USE_QSTRINGBUILDER
26         QT_STRICT_ITERATORS
27         $<$<NOT:$<CONFIG:Debug>>:QT_NO_DEBUG_OUTPUT>
28     )
30     if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
31         target_compile_definitions(qbt_common_cfg INTERFACE
32             _DARWIN_FEATURE_64_BIT_INODE
33         )
34     endif()
36     if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
37         target_compile_definitions(qbt_common_cfg INTERFACE
38             NTDDI_VERSION=0x06010000
39             _WIN32_WINNT=0x0601
40             _WIN32_IE=0x0601
41             WIN32_LEAN_AND_MEAN
42             NOMINMAX
43             UNICODE
44             _UNICODE
45         )
46     endif()
48     if ((CMAKE_CXX_COMPILER_ID STREQUAL "GNU") OR (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") OR (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang"))
49         target_compile_options(qbt_common_cfg INTERFACE
50             -Wall
51             -Wextra
52             -Wcast-qual
53             -Wcast-align
54             -Winvalid-pch
55             -Woverloaded-virtual
56             -Wold-style-cast
57             -Wnon-virtual-dtor
58             -pedantic
59             -pedantic-errors
60         )
62         # Clang 11 still doesn't support -Wstrict-null-sentinel
63         include(CheckCXXCompilerFlag)
64         check_cxx_compiler_flag(-Wstrict-null-sentinel SNS_SUPPORT)
65         if (SNS_SUPPORT)
66             target_compile_options(qbt_common_cfg INTERFACE -Wstrict-null-sentinel)
67         endif()
68     endif()
70     if ((CMAKE_CXX_COMPILER_ID STREQUAL "Clang") OR (CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang"))
71         target_compile_options(qbt_common_cfg INTERFACE
72             -Wno-range-loop-analysis
73         )
74     endif()
76     if (MINGW)
77         target_link_options(qbt_common_cfg INTERFACE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:LINKER:--dynamicbase>)
78     endif()
80     if (MSVC_RUNTIME_DYNAMIC)
81         set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
82     else()
83         set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
84     endif()
86     if (MSVC)
87         target_compile_options(qbt_common_cfg INTERFACE
88             /guard:cf
89             /utf-8
90             # https://devblogs.microsoft.com/cppblog/msvc-now-correctly-reports-__cplusplus/
91             /Zc:__cplusplus
92         )
93         target_link_options(qbt_common_cfg INTERFACE
94             /guard:cf
95             $<$<NOT:$<CONFIG:Debug>>:/OPT:REF /OPT:ICF>
96             # suppress linking warning due to /INCREMENTAL and /OPT:ICF being both ON
97             $<$<CONFIG:RelWithDebInfo>:/INCREMENTAL:NO>
98         )
99     endif()
101     if (LibtorrentRasterbar_VERSION VERSION_GREATER_EQUAL ${minLibtorrentVersion})
102         target_compile_definitions(qbt_common_cfg INTERFACE QBT_USES_LIBTORRENT2)
103     endif()
104 endmacro(qbt_common_config)