mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-21 05:43:32 -07:00
CMake: overhaul and improve scripts
- Bump minimum required version and make use of more modern language features - Rely more on target_...() commands to establish dependency relationships between targets rather than directory property commands - Improve libtorrent package discovery - Enable and handle application features more explicitly - Improve user-facing output - Fix various compilation issues on Windows (MSVC and MinGW) and macOS - Improve handling of translations - Add explanatory comments where relevant - Make CMake scripts fully independent of qmake files/details - Remove old functions/macros
This commit is contained in:
parent
79bc4f40e8
commit
46123b9989
28 changed files with 474 additions and 1239 deletions
102
cmake/Modules/MacroQbtCommonConfig.cmake
Normal file
102
cmake/Modules/MacroQbtCommonConfig.cmake
Normal file
|
@ -0,0 +1,102 @@
|
|||
# Set common variables and create some interface-only library targets
|
||||
# that some or all other targets will link to, either directly or transitively,
|
||||
# to consume common compile options/definitions
|
||||
|
||||
macro(qbt_common_config)
|
||||
|
||||
# treat value specified by the CXX_STANDARD target property as a requirement by default
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
# these definitions are only needed for calls to
|
||||
# lt::generate_fingerprint and for the qbittorrent.rc file on Windows
|
||||
add_library(qbt_version_definitions INTERFACE)
|
||||
|
||||
target_compile_definitions(qbt_version_definitions INTERFACE
|
||||
QBT_VERSION_MAJOR=${qBittorrent_VERSION_MAJOR}
|
||||
QBT_VERSION_MINOR=${qBittorrent_VERSION_MINOR}
|
||||
QBT_VERSION_BUGFIX=${qBittorrent_VERSION_PATCH}
|
||||
QBT_VERSION_BUILD=${qBittorrent_VERSION_TWEAK}
|
||||
)
|
||||
|
||||
add_library(qbt_common_cfg INTERFACE)
|
||||
|
||||
# Full C++ 14 support is required
|
||||
# See also https://cmake.org/cmake/help/latest/prop_gbl/CMAKE_CXX_KNOWN_FEATURES.html
|
||||
# for a breakdown of the features that CMake recognizes for each C++ standard
|
||||
target_compile_features(qbt_common_cfg INTERFACE
|
||||
cxx_std_14
|
||||
cxx_aggregate_default_initializers
|
||||
cxx_attribute_deprecated
|
||||
cxx_binary_literals
|
||||
cxx_contextual_conversions
|
||||
cxx_decltype_auto
|
||||
cxx_digit_separators
|
||||
cxx_generic_lambdas
|
||||
cxx_lambda_init_captures
|
||||
cxx_relaxed_constexpr
|
||||
cxx_return_type_deduction
|
||||
cxx_variable_templates
|
||||
)
|
||||
|
||||
set(QBT_FULL_VERSION "${qBittorrent_VERSION}${QBT_VER_STATUS}")
|
||||
|
||||
target_compile_definitions(qbt_common_cfg INTERFACE
|
||||
QBT_VERSION="v${QBT_FULL_VERSION}"
|
||||
QBT_VERSION_2="${QBT_FULL_VERSION}"
|
||||
QT_DEPRECATED_WARNINGS
|
||||
QT_NO_CAST_TO_ASCII
|
||||
QT_NO_CAST_FROM_BYTEARRAY
|
||||
QT_USE_QSTRINGBUILDER
|
||||
QT_STRICT_ITERATORS
|
||||
$<$<NOT:$<CONFIG:Debug>>:QT_NO_DEBUG_OUTPUT>
|
||||
)
|
||||
|
||||
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
|
||||
target_compile_definitions(qbt_common_cfg INTERFACE
|
||||
NTDDI_VERSION=0x06010000
|
||||
_WIN32_WINNT=0x0601
|
||||
_WIN32_IE=0x0601
|
||||
WIN32_LEAN_AND_MEAN
|
||||
NOMINMAX
|
||||
UNICODE
|
||||
_UNICODE
|
||||
)
|
||||
endif()
|
||||
|
||||
if ((CXX_COMPILER_ID STREQUAL "GNU") OR (CXX_COMPILER_ID STREQUAL "Clang") OR (CXX_COMPILER_ID STREQUAL "AppleClang"))
|
||||
target_compile_options(qbt_common_cfg INTERFACE
|
||||
-Wall
|
||||
-Wextra
|
||||
-Wcast-qual
|
||||
-Wcast-align
|
||||
-Winvalid-pch
|
||||
-Woverloaded-virtual
|
||||
-Wold-style-cast
|
||||
-Wnon-virtual-dtor
|
||||
-pedantic
|
||||
-pedantic-errors
|
||||
)
|
||||
|
||||
# Clang 11 still doesn't support -Wstrict-null-sentinel
|
||||
include(CheckCXXCompilerFlag)
|
||||
check_cxx_compiler_flag(-Wstrict-null-sentinel SNS_SUPPORT)
|
||||
if (SNS_SUPPORT)
|
||||
target_compile_options(qbt_common_cfg INTERFACE -Wstrict-null-sentinel)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if (MINGW)
|
||||
target_link_options(qbt_common_cfg INTERFACE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:LINKER:--dynamicbase>)
|
||||
endif()
|
||||
|
||||
if (MSVC_RUNTIME_DYNAMIC)
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
|
||||
else()
|
||||
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
|
||||
endif()
|
||||
|
||||
if (CMAKE_GENERATOR MATCHES "Visual Studio")
|
||||
target_compile_options(qbt_common_cfg INTERFACE /MP)
|
||||
endif()
|
||||
|
||||
endmacro(qbt_common_config)
|
Loading…
Add table
Add a link
Reference in a new issue