Browse Source

Merge pull request #12480 from FranciscoPombal/cmake_force_cpp14

CMake: Enforce minimum C++ mode support
adaptive-webui-19844
Vladimir Golovnev 5 years ago committed by GitHub
parent
commit
5a78bcef99
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      .travis.yml
  2. 8
      CMakeLists.txt
  3. 24
      cmake/Modules/FunctionQbtCXXCompilerAndModeCheck.cmake
  4. 5
      cmake/Modules/MacroQbtCompilerSettings.cmake
  5. 11
      src/CMakeLists.txt

4
.travis.yml

@ -56,9 +56,11 @@ addons: @@ -56,9 +56,11 @@ addons:
sources:
# sources list: https://github.com/travis-ci/apt-source-safelist/blob/master/ubuntu.json
- sourceline: 'ppa:qbittorrent-team/qbt-libtorrent-travisci'
- sourceline: 'deb https://apt.kitware.com/ubuntu/ bionic main'
key_url: 'https://apt.kitware.com/keys/kitware-archive-latest.asc'
packages:
# packages list: https://github.com/travis-ci/apt-package-safelist/blob/master/ubuntu-trusty
- [autoconf, automake, colormake]
- [autoconf, automake, cmake, colormake]
- [libboost-dev, libboost-system-dev]
- libssl-dev
- [qtbase5-dev, libqt5svg5-dev, qttools5-dev]

8
CMakeLists.txt

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.9 FATAL_ERROR)
cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
message(AUTHOR_WARNING "If the build fails, please try the autotools/qmake method.")
@ -14,6 +14,12 @@ read_version("${CMAKE_CURRENT_SOURCE_DIR}/version.pri" VER_MAJOR VER_MINOR VER_B @@ -14,6 +14,12 @@ read_version("${CMAKE_CURRENT_SOURCE_DIR}/version.pri" VER_MAJOR VER_MINOR VER_B
project(qBittorrent VERSION ${VER_MAJOR}.${VER_MINOR}.${VER_BUGFIX}.${VER_BUILD})
# check for invalid compiler version/CXX standard as early as possible
include(FunctionQbtCXXCompilerAndModeCheck)
qbt_minimum_cxx_mode_check(14)
message(STATUS "Building in C++${CMAKE_CXX_STANDARD} mode.\n"
"Make sure libtorrent was built with the same C++ mode for ABI compatibility.")
set(PROJECT_VERSION "${VER_MAJOR}.${VER_MINOR}.${VER_BUGFIX}")
if (NOT VER_BUILD EQUAL 0)

24
cmake/Modules/FunctionQbtCXXCompilerAndModeCheck.cmake

@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
# Function for ensuring the build does not use a lower than the required minimum C++ mode, _min_std.
# It fails the build if:
# - the compiler does not fully support _min_std
# - the user specified a mode lower than _min_std via the CMAKE_CXX_STANDARD variable
# If both checks are successful, it sets the following variables at the PARENT_SCOPE:
# - CMAKE_CXX_STANDARD with the value _min_std, if it was not already set to a value >= _min_std
# - CMAKE_CXX_STANDARD_REQUIRED with the value ON
function(qbt_minimum_cxx_mode_check _min_std)
# ensure the compiler fully supports the minimum required C++ mode.
if(NOT CMAKE_CXX${_min_std}_STANDARD__HAS_FULL_SUPPORT)
message(FATAL_ERROR "${PROJECT_NAME} requires a compiler with full C++${_min_std} support")
endif()
# now we know that the compiler fully supports the minimum required C++ mode,
# but we must still prevent the user or compiler from forcing/defaulting to an insufficient C++ mode
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD ${_min_std} PARENT_SCOPE)
elseif((CMAKE_CXX_STANDARD VERSION_LESS ${_min_std}) OR (CMAKE_CXX_STANDARD VERSION_EQUAL 98))
message(FATAL_ERROR "${PROJECT_NAME} has to be built with at least C++${_min_std} mode.")
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON PARENT_SCOPE)
endfunction()

5
cmake/Modules/MacroQbtCompilerSettings.cmake

@ -24,11 +24,6 @@ macro(qbt_set_compiler_options) @@ -24,11 +24,6 @@ macro(qbt_set_compiler_options)
#"-Wno-error=sign-conversion -Wno-error=float-equal"
)
# GCC 4.8 has problems with std::array and its initialization
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9)
list(APPEND _GCC_COMMON_CXX_FLAGS "-Wno-error=missing-field-initializers")
endif()
include(CheckCXXCompilerFlag)
# check for -pedantic
check_cxx_compiler_flag(-pedantic _PEDANTIC_IS_SUPPORTED)

11
src/CMakeLists.txt

@ -1,14 +1,3 @@ @@ -1,14 +1,3 @@
set(CMAKE_CXX_STANDARD_REQUIRED True)
# If C++14 is available, use it as libtorent ABI depends on 11/14 version
if (cxx_std_14 IN_LIST CMAKE_CXX_COMPILE_FEATURES)
message(STATUS "Building in C++14 mode")
set(CMAKE_CXX_STANDARD "14")
else()
message(STATUS "Building in C++11 mode")
set(CMAKE_CXX_STANDARD "11")
endif()
include(MacroQbtCompilerSettings)
qbt_set_compiler_options()

Loading…
Cancel
Save