]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: require 4.0.0 <= libfmt-dev < 5.0.0
authorKefu Chai <kchai@redhat.com>
Thu, 2 Aug 2018 11:04:30 +0000 (19:04 +0800)
committerKefu Chai <kchai@redhat.com>
Thu, 2 Aug 2018 14:14:03 +0000 (22:14 +0800)
FMT_VERSION is now living in fmt/core.h in libfmt >= 5.0, so we cannot
parse fmt/format.h for libfmt's version anymore. also we don't need
Findfmt.cmake now. because libfmt-dev 4.0 and up is required by seastar,
also it's libfmt-dev 3.x's cmake module which fails to offer fmt::fmt
target. in other words, it's safe to drop libfmt 3.x support. but 5.0.0
is not compatible with seastar, we will have failures like:

In file included from
/home/smithfarm/src/ceph/smithfarm/ceph/src/seastar/include/seastar/core/aligned_buffer.hh:25:0,
                 from
/home/smithfarm/src/ceph/smithfarm/ceph/src/seastar/include/seastar/core/reactor.hh:26,
                 from
/home/smithfarm/src/ceph/smithfarm/ceph/src/seastar/include/seastar/core/alien.hh:35,
                 from
/home/smithfarm/src/ceph/smithfarm/ceph/src/seastar/src/core/alien.cc:23:
/home/smithfarm/src/ceph/smithfarm/ceph/src/seastar/include/seastar/core/print.hh:
In function 'seastar::sstring seastar::format(const char*, A&& ...)':
/home/smithfarm/src/ceph/smithfarm/ceph/src/seastar/include/seastar/core/print.hh:135:10:
error: 'MemoryWriter' is not a member of 'fmt'
     fmt::MemoryWriter out;
          ^~~~~~~~~~~~
/home/smithfarm/src/ceph/smithfarm/ceph/src/seastar/include/seastar/core/print.hh:136:5:
error: 'out' was not declared in this scope
     out.write(fmt, std::forward<A>(a)...);
     ^~~

so, we should build libfmt even if we have libfmt-dev 5.x

Signed-off-by: Kefu Chai <kchai@redhat.com>
cmake/modules/Findc-ares.cmake
cmake/modules/Findfmt.cmake
src/CMakeLists.txt

index 766b6a3179e1d1a360c05ee6e19171ef1f565e12..6386f9acecb9788d6018661e33484ac1994c3f00 100644 (file)
@@ -1,4 +1,4 @@
-find_package(PkgConfig)
+find_package(PkgConfig QUIET)
 
 pkg_search_module(PC_cares
   libcares)
@@ -13,10 +13,9 @@ find_library(c-ares_LIBRARY
 
 set(c-ares_VERSION ${PC_cares_VERSION})
 
-include (FindPackageHandleStandardArgs)
+include(FindPackageHandleStandardArgs)
 
 find_package_handle_standard_args(c-ares
-  FOUND_VAR c-ares_FOUND
   REQUIRED_VARS
     c-ares_INCLUDE_DIR
     c-ares_LIBRARY
index 5573f0380f7eb09c73289e8091ac25b8ed8f0f66..244cfe0125f79593e6a59afad787270585c572dc 100644 (file)
@@ -1,26 +1,31 @@
 find_path(fmt_INCLUDE_DIR NAMES fmt/format.h)
 
-if(fmt_INCLUDE_DIR AND EXISTS "${fmt_INCLUDE_DIR}/fmt/format.h")
-  # parse "#define FMT_VERSION 40100" to 4.1.0
-  file(STRINGS "${fmt_INCLUDE_DIR}/fmt/format.h" fmt_VERSION_LINE
-    REGEX "^#define[ \t]+FMT_VERSION[ \t]+[0-9]+$")
-  string(REGEX REPLACE "^#define[ \t]+FMT_VERSION[ \t]+([0-9]+)$"
-    "\\1" fmt_VERSION "${fmt_VERSION_LINE}")
-  foreach(ver "fmt_VERSION_PATCH" "fmt_VERSION_MINOR" "fmt_VERSION_MAJOR")
-    math(EXPR ${ver} "${fmt_VERSION} % 100")
-    math(EXPR fmt_VERSION "(${fmt_VERSION} - ${${ver}}) / 100")
-  endforeach()
-  set(fmt_VERSION_STRING
+if(fmt_INCLUDE_DIR)
+  set(_fmt_version_file "${fmt_INCLUDE_DIR}/fmt/format.h")
+  if(NOT EXISTS "${_fmt_version_file}")
+    set(_fmt_version_file "${fmt_INCLUDE_DIR}/fmt/core.h")
+  endif()
+  if(EXISTS "${_fmt_version_file}")
+    # parse "#define FMT_VERSION 40100" to 4.1.0
+    file(STRINGS "${fmt_INCLUDE_DIR}/fmt/format.h" fmt_VERSION_LINE
+      REGEX "^#define[ \t]+FMT_VERSION[ \t]+[0-9]+$")
+    string(REGEX REPLACE "^#define[ \t]+FMT_VERSION[ \t]+([0-9]+)$"
+      "\\1" fmt_VERSION "${fmt_VERSION_LINE}")
+    foreach(ver "fmt_VERSION_PATCH" "fmt_VERSION_MINOR" "fmt_VERSION_MAJOR")
+      math(EXPR ${ver} "${fmt_VERSION} % 100")
+      math(EXPR fmt_VERSION "(${fmt_VERSION} - ${${ver}}) / 100")
+    endforeach()
+    set(fmt_VERSION
       "${fmt_VERSION_MAJOR}.${fmt_VERSION_MINOR}.${fmt_VERSION_PATCH}")
+  endif()
 endif()
 
 find_library(fmt_LIBRARY NAMES fmt)
 
 include(FindPackageHandleStandardArgs)
 find_package_handle_standard_args(fmt
-  FOUND_VAR fmt_FOUND
   REQUIRED_VARS fmt_INCLUDE_DIR fmt_LIBRARY
-  VERSION_VAR fmt_VERSION_STRING)
+  VERSION_VAR fmt_VERSION)
 mark_as_advanced(
   fmt_INCLUDE_DIR
   fmt_LIBRARY
index ec089119484115fc18847816f02163a20717de36..5d898f743ddf33426a54fa4e88c9cb8eb86ba675 100644 (file)
@@ -305,12 +305,20 @@ include_directories("${CMAKE_SOURCE_DIR}/src/dmclock/support/src")
 include_directories(SYSTEM "${CMAKE_SOURCE_DIR}/src/googletest/googletest/include")
 
 if(WITH_SEASTAR)
-  find_package(fmt 4.0.0)
+  find_package(fmt 4.0.0 QUIET)
   if(NOT fmt_FOUND)
+    message(STATUS "Could not find fmt, will build it")
+    add_subdirectory(fmt)
+  elseif(fmt_VERSION VERSION_GREATER_EQUAL 5.0.0)
+    message(WARNING "Could NOT find fmt: "
+      "Found unsuitable version \"${fmt_VERSION}\", "
+      "but required is at most \"5.0.0\" (found ${fmt_INCLUDE_DIR}). "
+      "Will build it")
     add_subdirectory(fmt)
   endif()
-  find_package(c-ares 1.13.0 QUIET MODULE)
+  find_package(c-ares 1.13.0 QUIET)
   if(NOT c-ares_FOUND)
+    message(STATUS "Could not find c-ares, will build it")
     include(Buildc-ares)
     build_c_ares()
   endif()