Skip to content

Commit

Permalink
cmake: require CMake v3.10.2
Browse files Browse the repository at this point in the history
since we dropped the support of xenial, we now have the luxury of using
newer CMake! and by using CMake 3.10.2, we can prevent libfmt from
assuming that we are using C++11, and hence set `CMAKE_CXX_STANDARD` to
11, which will literally append `-std=gnu++11` to `CMAKE_CXX_FLAGS`.
the last `-std` option passed to `g++` takes precendence.
since we've switched over to C++17, and we are using C++17 features.
so, using cmake older than 3.8 breaks the build. because it is CMake 3.8
which stared support `CMAKE_CXX_STANDARD` 17.

- for bionic: https://packages.ubuntu.com/bionic/cmake : 3.10.2
- for CentOS7:
https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/c/ : 3.13.5

so in this change,

* bump up the required version to v3.10.2
* cleanups to wipe out the workaround for lower CMake versions
* use `PROJECT_VERSION` defined by `project()` command instead of
  `VERSION` explicitly defined.

Signed-off-by: Kefu Chai <kchai@redhat.com>
  • Loading branch information
tchaikov committed Aug 2, 2019
1 parent ddacfcc commit 92f027a
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 48 deletions.
10 changes: 7 additions & 3 deletions CMakeLists.txt
@@ -1,15 +1,19 @@
cmake_minimum_required(VERSION 3.5.1)
cmake_minimum_required(VERSION 3.10.2)
# remove cmake/modules/FindPython* once 3.12 is required

project(ceph CXX C ASM)
set(VERSION 15.0.0)
project(ceph
VERSION 15.0.0
LANGUAGES CXX C ASM)

if(POLICY CMP0028)
cmake_policy(SET CMP0028 NEW)
endif()
if(POLICY CMP0046)
cmake_policy(SET CMP0046 NEW)
endif()
if(POLICY CMP0048)
cmake_policy(SET CMP0048 NEW)
endif()
if(POLICY CMP0054)
cmake_policy(SET CMP0054 NEW)
endif()
Expand Down
2 changes: 1 addition & 1 deletion alpine/APKBUILD.in
@@ -1,7 +1,7 @@
# Contributor: John Coyle <dx9err@gmail.com>
# Maintainer: John Coyle <dx9err@gmail.com>
pkgname=ceph
pkgver=@VERSION@
pkgver=@PROJECT_VERSION@
pkgrel=@RPM_RELEASE@
pkgdesc="Ceph is a distributed object store and file system"
pkgusers="ceph"
Expand Down
2 changes: 1 addition & 1 deletion ceph.spec.in
Expand Up @@ -103,7 +103,7 @@
# main package definition
#################################################################################
Name: ceph
Version: @VERSION@
Version: @PROJECT_VERSION@
Release: @RPM_RELEASE@%{?dist}
%if 0%{?fedora} || 0%{?rhel}
Epoch: 2
Expand Down
12 changes: 2 additions & 10 deletions cmake/modules/FindStdFilesystem.cmake
Expand Up @@ -2,16 +2,8 @@ set(_std_filesystem_test_src
${CMAKE_CURRENT_LIST_DIR}/FindStdFilesystem_test.cc)

macro(try_std_filesystem_library _library _result)
if(CMAKE_VERSION VERSION_LESS "3.8")
# abuse the definition flags, because they are quite
# the same as CMAKE_C_FLAGS: they are passed to the
# compiler.
set(_std_filesystem_try_compile_arg
COMPILE_DEFINITIONS "-std=c++17")
else()
set(_std_filesystem_try_compile_arg
CXX_STANDARD 17)
endif()
set(_std_filesystem_try_compile_arg
CXX_STANDARD 17)
try_compile(_std_filesystem_compiles
${CMAKE_CURRENT_BINARY_DIR}
SOURCES ${_std_filesystem_test_src}
Expand Down
2 changes: 1 addition & 1 deletion make-dist
Expand Up @@ -116,7 +116,7 @@ echo "including src/.git_version, ceph.spec"

for spec in ceph.spec.in alpine/APKBUILD.in; do
cat $spec |
sed "s/@VERSION@/$rpm_version/g" |
sed "s/@PROJECT_VERSION@/$rpm_version/g" |
sed "s/@RPM_RELEASE@/$rpm_release/g" |
sed "s/@TARBALL_BASENAME@/ceph-$version/g" > `echo $spec | sed 's/.in$//'`
done
Expand Down
38 changes: 7 additions & 31 deletions src/CMakeLists.txt
Expand Up @@ -114,37 +114,13 @@ endif()


# require c++17
if(CMAKE_VERSION VERSION_LESS "3.8")
CHECK_CXX_COMPILER_FLAG("-std=c++17" COMPILER_SUPPORTS_CXX17)
if(NOT COMPILER_SUPPORTS_CXX17)
message(FATAL_ERROR
"The compiler ${CMAKE_CXX_COMPILER} has no C++17 support.")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17")

# for compiletest_cxx11_client
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
if(NOT COMPILER_SUPPORTS_CXX11)
message(FATAL_ERROR
"The compiler ${CMAKE_CXX_COMPILER} has no C++11 support.")
endif()

include(CheckCCompilerFlag)
CHECK_C_COMPILER_FLAG("-std=gnu99" COMPILER_SUPPORTS_GNU99)
if(NOT COMPILER_SUPPORTS_GNU99)
message(FATAL_ERROR
"The compiler ${CMAKE_C_COMPILER} has no GNU C99 support.")
endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
else()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD 99)
# we use `asm()` to inline assembly, so enable the GNU extension
set(CMAKE_C_EXTENSIONS ON)
set(C_STANDARD_REQUIRED ON)
endif()
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_C_STANDARD 99)
# we use `asm()` to inline assembly, so enable the GNU extension
set(CMAKE_C_EXTENSIONS ON)
set(C_STANDARD_REQUIRED ON)

include(CheckCXXSourceCompiles)
CHECK_CXX_SOURCE_COMPILES("
Expand Down
2 changes: 1 addition & 1 deletion src/include/config-h.in.cmake
Expand Up @@ -290,7 +290,7 @@
#cmakedefine HAVE_STATIC_CAST

/* Version number of package */
#cmakedefine VERSION "@VERSION@"
#cmakedefine VERSION "@PROJECT_VERSION@"

/* Defined if pthread_setname_np() is available */
#cmakedefine HAVE_PTHREAD_SETNAME_NP 1
Expand Down

0 comments on commit 92f027a

Please sign in to comment.