]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: enforce C++17 instead of relying on cmake-compile-features 30283/head
authorKefu Chai <kchai@redhat.com>
Tue, 10 Sep 2019 06:56:59 +0000 (14:56 +0800)
committerKefu Chai <kchai@redhat.com>
Tue, 10 Sep 2019 10:40:37 +0000 (18:40 +0800)
this change is a follow-up of #30114

in FindBoost.cmake, we try to deduce the C++ flags by checking the C++
features offered by different C++ standard like C++98, C++11 and C++14
against the ones required by different boost component. then choose the
C++ dialect based on the `CXX_STANDARD` and `COMPILE_FEATURES`.

in the case of nautilus, since cmake 3.5.1 does not offer
CXX_STANDARD=17 support by then, we have to add `-std=c++17` to
`CMAKE_CXX_FLAGS` manually. but unfortunately, the
`cmake-compile-features` machinary does not check `CMAKE_CXX_FLAGS` for
the default C++ standard required by the project. so it falls back to
the minimal C++ standard required by the target.

since Boost::fiber and Boost::context share the same C++ feature set
dependencies which can be fulfilled by C++11, and by default,
`CXX_EXTENSIONS` is enabled, `--std=gnu++11` is used as we are using gcc
in our building hosts. so we have CXX_FLAGS like:

-std=c++17 ... -std=gnu++11

when compiling targets linked against Boost::context. and it seems the
last one takes effect. that's why some targets failed to compile if
the makefiles were generated with cmake 3.5.1.

in this change, `INTERFACE_COMPILE_FEATURES <features>` is replaced with
`CXX_STANDARD 17`. this renders this setting a no-op, as CMake 3.5.1
does not translate this setting to any CXX_FLAGS. but this does not
hurt, as we use C++17 project-wide, and C++17 is able to offer all
compile features required by Boost::context.

Signed-off-by: Kefu Chai <kchai@redhat.com>
Conflicts: this change is not cherry-picked from master, because in
  master, we use cmake 3.10 and up which offers the support of
  `CXX_STANDARD=17`, hence cmake is able to bump up the C++ standard
  to C++17 instead of falling back to C++11.

cmake/modules/FindBoost.cmake

index dd08ba5e45c85a9b1875cc9df7af1a0e80073a46..e2525b89345e3552bbefd0ad8ce6083ea6ba1bfa 100644 (file)
@@ -2134,7 +2134,7 @@ if(Boost_FOUND)
         endif()
         if(_Boost_${UPPERCOMPONENT}_COMPILER_FEATURES)
           set_target_properties(Boost::${COMPONENT} PROPERTIES
-            INTERFACE_COMPILE_FEATURES "${_Boost_${UPPERCOMPONENT}_COMPILER_FEATURES}")
+            CXX_STANDARD 17)
         endif()
       endif()
     endif()