From: Kefu Chai Date: Tue, 10 Sep 2019 06:56:59 +0000 (+0800) Subject: cmake: enforce C++17 instead of relying on cmake-compile-features X-Git-Tag: v14.2.5~266^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e9bf7195309b77439fc81a35508d77b3652695bd;p=ceph.git cmake: enforce C++17 instead of relying on cmake-compile-features 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 ` 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 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. --- diff --git a/cmake/modules/FindBoost.cmake b/cmake/modules/FindBoost.cmake index dd08ba5e45c8..e2525b89345e 100644 --- a/cmake/modules/FindBoost.cmake +++ b/cmake/modules/FindBoost.cmake @@ -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()