]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake: build c-ares if it's not found or not new enough
authorKefu Chai <kchai@redhat.com>
Thu, 19 Jul 2018 16:14:03 +0000 (00:14 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 25 Jul 2018 05:13:45 +0000 (13:13 +0800)
Signed-off-by: Kefu Chai <kchai@redhat.com>
cmake/modules/Buildc-ares.cmake [new file with mode: 0644]
cmake/modules/Findc-ares.cmake [new file with mode: 0644]
src/CMakeLists.txt

diff --git a/cmake/modules/Buildc-ares.cmake b/cmake/modules/Buildc-ares.cmake
new file mode 100644 (file)
index 0000000..83cac92
--- /dev/null
@@ -0,0 +1,22 @@
+function(build_c_ares)
+  include(ExternalProject)
+  set(C-ARES_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/c-ares")
+  set(C-ARES_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/c-ares")
+  ExternalProject_Add(c-ares_ext
+    SOURCE_DIR "${C-ARES_SOURCE_DIR}"
+    CMAKE_ARGS
+     -DCARES_STATIC=ON
+     -DCARES_SHARED=OFF
+     -DCARES_INSTALL=OFF
+    BINARY_DIR "${C-ARES_BINARY_DIR}"
+    BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR>
+    INSTALL_COMMAND "")
+  add_library(c-ares::c-ares STATIC IMPORTED)
+  add_dependencies(c-ares::c-ares c-ares_ext)
+  set_target_properties(c-ares::c-ares PROPERTIES
+    INTERFACE_INCLUDE_DIRECTORIES "${C-ARES_SOURCE_DIR}"
+    IMPORTED_LINK_INTERFACE_LANGUAGES "C"
+    IMPORTED_LOCATION "${C-ARES_BINARY_DIR}/lib/libcares.a")
+  # to appease find_package()
+  add_custom_target(c-ares DEPENDS c-ares::c-ares)
+endfunction()
diff --git a/cmake/modules/Findc-ares.cmake b/cmake/modules/Findc-ares.cmake
new file mode 100644 (file)
index 0000000..766b6a3
--- /dev/null
@@ -0,0 +1,31 @@
+find_package(PkgConfig)
+
+pkg_search_module(PC_cares
+  libcares)
+
+find_path(c-ares_INCLUDE_DIR
+  NAMES ares_dns.h
+  PATHS ${PC_cares_INCLUDE_DIRS})
+
+find_library(c-ares_LIBRARY
+  NAMES cares
+  PATHS ${PC_cares_LIBRARY_DIRS})
+
+set(c-ares_VERSION ${PC_cares_VERSION})
+
+include (FindPackageHandleStandardArgs)
+
+find_package_handle_standard_args(c-ares
+  FOUND_VAR c-ares_FOUND
+  REQUIRED_VARS
+    c-ares_INCLUDE_DIR
+    c-ares_LIBRARY
+  VERSION_VAR c-ares_VERSION)
+
+if(c-ares_FOUND AND NOT (TARGET c-ares::c-ares))
+  add_library(c-ares::c-ares UNKNOWN IMPORTED)
+  set_target_properties(c-ares::c-ares PROPERTIES
+    INTERFACE_INCLUDE_DIRECTORIES "${c-ares_INCLUDE_DIR}"
+    IMPORTED_LINK_INTERFACE_LANGUAGES "C"
+    IMPORTED_LOCATION "${c-ares_LIBRARY}")
+endif()
index b59f666a13d894cb70eff7a539ae1ce0a361ba48..c1f7f484c91bee79b7c4043d1985d2c537d8fcdf 100644 (file)
@@ -384,10 +384,15 @@ 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 CONFIG QUIET)
+  find_package(fmt QUIET CONFIG)
   if(NOT fmt_FOUND)
     add_subdirectory(fmt)
   endif()
+  find_package(c-ares 1.13.0 QUIET MODULE)
+  if(NOT c-ares_FOUND)
+    include(Buildc-ares)
+    build_c_ares()
+  endif()
   macro(find_package name)
     if(NOT TARGET ${name})
       _find_package(${ARGV})