]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
cmake,make-dist: build gperftools if WITH_STATIC_LIBSTDCXX
authorKefu Chai <kchai@redhat.com>
Wed, 25 Jul 2018 10:46:55 +0000 (18:46 +0800)
committerKefu Chai <kchai@redhat.com>
Sun, 29 Jul 2018 13:25:52 +0000 (21:25 +0800)
we could create a mini project to build a shared library, and use
try_compile() to test if the found gperftools is compiled with -fPIC.
but as we are targeting mostly xenial when enabling
WITH_STATIC_LIBSTDCXX, and google-perftools on xenial by default
is built without -fPIC. so let's keep it simple.

Signed-off-by: Kefu Chai <kchai@redhat.com>
CMakeLists.txt
cmake/modules/Buildgperftools.cmake [new file with mode: 0644]
make-dist
src/perfglue/CMakeLists.txt

index f073d8e3b84920f6ce6eba20f2f6b8d0296ac90f..99ea3bd5d8c767a0bfdfdd03051805fd915548a0 100644 (file)
@@ -316,7 +316,11 @@ endif(WITH_LZ4)
 #if allocator is set on command line make sure it matches below strings
 if(ALLOCATOR)
   if(${ALLOCATOR} MATCHES "tcmalloc(_minimal)?")
-    find_package(gperftools REQUIRED)
+    if(GPERFTOOLS_USE_STATIC_LIBS)
+      include(Buildgperftools)
+    else()
+      find_package(gperftools REQUIRED)
+    endif()
     set(HAVE_LIBTCMALLOC ON)
   elseif(${ALLOCATOR} STREQUAL "jemalloc")
     find_package(JeMalloc REQUIRED)
@@ -325,8 +329,10 @@ if(ALLOCATOR)
     message(FATAL_ERROR "Unsupported allocator selected: ${ALLOCATOR}")
   endif()
 else(ALLOCATOR)
-  find_package(gperftools)
-  set(HAVE_LIBTCMALLOC ${gperftools_FOUND})
+  if(NOT GPERFTOOLS_USE_STATIC_LIBS)
+    find_package(gperftools)
+    set(HAVE_LIBTCMALLOC ${gperftools_FOUND})
+  endif()
   if(NOT gperftools_FOUND)
     find_package(JeMalloc)
   endif()
diff --git a/cmake/modules/Buildgperftools.cmake b/cmake/modules/Buildgperftools.cmake
new file mode 100644 (file)
index 0000000..5242b4c
--- /dev/null
@@ -0,0 +1,42 @@
+if(EXISTS ${CMAKE_SOURCE_DIR}/src/gperftools/configure)
+  set(gperftools_SOURCE_DIR
+    SOURCE_DIR ${CMAKE_SOURCE_DIR}/src/gperftools)
+else()
+  set(gperftools_SOURCE_DIR
+    URL https://github.com/gperftools/gperftools/releases/download/gperftools-2.7/gperftools-2.7.tar.gz
+    URL_HASH SHA256=1ee8c8699a0eff6b6a203e59b43330536b22bbcbe6448f54c7091e5efb0763c9)
+endif()
+
+set(gperftools_ROOT_DIR ${CMAKE_CURRENT_BINARY_DIR}/gperftools)
+include(ExternalProject)
+# override the $DESTDIR specified by debian's dh-make, as it sets $DESTDIR
+# environment variable globally, which instructs GNU automake to install the
+# artifacts to the specified $DESTDIR instead of <INSTALL_DIR>, where the
+# headers and libraries are expected. if $DESTDIR is specified, the artifacts
+# will be installed into ${DESTDIR}/${prefix}. and the default ${prefix} is
+# /user/local, so pass an empty string to "configure"
+ExternalProject_Add(gperftools_ext
+  ${gperftools_SOURCE_DIR}
+  CONFIGURE_COMMAND <SOURCE_DIR>/configure --disable-libunwind --disable-stacktrace-via-backtrace --enable-frame-pointers --prefix= CXXFLAGS=-fPIC
+  BUILD_COMMAND $(MAKE)
+  INSTALL_DIR ${gperftools_ROOT_DIR}
+  INSTALL_COMMAND $(MAKE) install DESTDIR=<INSTALL_DIR>)
+
+# create the directory so cmake won't complain when looking at the imported
+# target
+file(MAKE_DIRECTORY ${gperftools_ROOT_DIR}/include)
+
+foreach(component tcmalloc tcmalloc_minimal profiler)
+  add_library(gperftools::${component} STATIC IMPORTED)
+  set_target_properties(gperftools::${component} PROPERTIES
+    INTERFACE_INCLUDE_DIRECTORIES ${gperftools_ROOT_DIR}/include
+    IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
+    IMPORTED_LOCATION ${gperftools_ROOT_DIR}/lib/${CMAKE_STATIC_LIBRARY_PREFIX}${component}${CMAKE_STATIC_LIBRARY_SUFFIX})
+  add_dependencies(gperftools::${component} gperftools_ext)
+endforeach()
+
+find_package(Threads)
+foreach(component tcmalloc profiler)
+  set_target_properties(gperftools::${component} PROPERTIES
+    INTERFACE_LINK_LIBRARIES "Threads::Threads")
+endforeach()
index eb9aa7b0f2bf36150c0a5a5d72f3c1881e5f73ec..e0aeadf11ab6b2fc5f1111fca42d0b8b582208d9 100755 (executable)
--- a/make-dist
+++ b/make-dist
@@ -61,6 +61,28 @@ download_boost() {
     rm -rf src/boost
 }
 
+download_gperftools() {
+    version=$1
+    shift
+    sha256=$1
+    shift
+    dname=gperftools-$version
+    fname=$dname.tar.gz
+    url=https://github.com/gperftools/gperftools/releases/download/$dname/$fname
+
+    if ! wget -c --no-verbose -O $fname $url; then
+        echo "Download of $url failed"
+        exit 1
+    elif [ $(sha256sum $fname | awk '{print $1}') != $sha256 ]; then
+        echo "Error: failed to download gperftools: SHA256 mismatch."
+        exit 1
+    fi
+    tar xzf $fname -C src
+    mv src/$dname src/gperftools
+    tar cf ${outfile}.gperftools.tar ${outfile}/src/gperftools
+    rm -rf src/gperftools
+}
+
 _python_autoselect() {
   python_command=
   for interpreter in python2.7 python3 ; do
@@ -135,9 +157,11 @@ download_boost $boost_version 2684c972994ee57fc5632e03bf044746f6eb45d4920c343937
                https://dl.bintray.com/boostorg/release/$boost_version/source \
                https://downloads.sourceforge.net/project/boost/boost/$boost_version \
                https://download.ceph.com/qa
+download_gperftools 2.7 1ee8c8699a0eff6b6a203e59b43330536b22bbcbe6448f54c7091e5efb0763c9
 build_dashboard_frontend
 tar --concatenate -f $outfile.all.tar $outfile.version.tar
 tar --concatenate -f $outfile.all.tar $outfile.boost.tar
+tar --concatenate -f $outfile.all.tar $outfile.gperftools.tar
 tar --concatenate -f $outfile.all.tar $outfile.tar
 tar --concatenate -f $outfile.all.tar dashboard_frontend.tar
 mv $outfile.all.tar $outfile.tar
index 11546e98e53731ed30efb126b1cab799774872c7..b1654c73c79eb344aba4c279ce59516073f66010 100644 (file)
@@ -11,7 +11,13 @@ endif()
 option(WITH_PROFILER "build extra profiler binaries" OFF)
 
 if(WITH_PROFILER)
-  find_package(gperftools REQUIRED profiler)
+  if(GPERFTOOLS_USE_STATIC_LIBS)
+    if(NOT TARGET gperftools::profiler)
+      include(Buildgperftools)
+    endif()
+  else()
+    find_package(gperftools REQUIRED profiler)
+  endif()
   add_library(cpu_profiler STATIC
     cpu_profiler.cc)
   target_link_libraries(cpu_profiler