mirror of
https://github.com/ceph/ceph
synced 2024-12-29 06:52:35 +00:00
Merge pull request #22990 from tchaikov/wip-cmake-link-static-libstdc++
cmake: fix "WITH_STATIC_LIBSTDCXX" Reviewed-by: Casey Bodley <cbodley@redhat.com>
This commit is contained in:
commit
1cbd929806
@ -167,7 +167,13 @@ set(CMAKE_POSITION_INDEPENDENT_CODE ${ENABLE_SHARED})
|
||||
|
||||
option(WITH_STATIC_LIBSTDCXX "Link against libstdc++ statically" OFF)
|
||||
if(WITH_STATIC_LIBSTDCXX)
|
||||
if(NOT CMAKE_COMPILER_IS_GNUCXX)
|
||||
if(CMAKE_COMPILER_IS_GNUCXX)
|
||||
set(static_linker_flags "-static-libstdc++ -static-libgcc")
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${static_linker_flags}")
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${static_linker_flags}")
|
||||
unset(static_linker_flags)
|
||||
set(GPERFTOOLS_USE_STATIC_LIBS TRUE)
|
||||
else()
|
||||
message(FATAL_ERROR "Please use GCC to enable WITH_STATIC_LIBSTDCXX")
|
||||
endif()
|
||||
endif()
|
||||
@ -310,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)
|
||||
@ -319,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()
|
||||
@ -337,6 +349,11 @@ else(ALLOCATOR)
|
||||
endif(gperftools_FOUND)
|
||||
endif(ALLOCATOR)
|
||||
|
||||
if(HAVE_LIBTCMALLOC AND WITH_STATIC_LIBSTDCXX)
|
||||
set(EXE_LINKER_USE_PIE FALSE)
|
||||
else()
|
||||
set(EXE_LINKER_USE_PIE ${ENABLE_SHARED})
|
||||
endif()
|
||||
|
||||
if(WITH_LIBCEPHFS OR WITH_KRBD)
|
||||
find_package(keyutils REQUIRED)
|
||||
|
@ -13,7 +13,12 @@ function(do_build_rocksdb)
|
||||
list(APPEND ROCKSDB_CMAKE_ARGS -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER})
|
||||
endif()
|
||||
|
||||
# libsnappy is a C++ library, we need to force rocksdb to link against
|
||||
# libsnappy statically.
|
||||
list(APPEND ROCKSDB_CMAKE_ARGS -DWITH_SNAPPY=${SNAPPY_FOUND})
|
||||
if(SNAPPY_FOUND AND WITH_STATIC_LIBSTDCXX)
|
||||
list(APPEND ROCKSDB_CMAKE_ARGS -DWITH_SNAPPY_STATIC_LIB=ON)
|
||||
endif()
|
||||
list(APPEND ROCKSDB_CMAKE_ARGS -DWITH_LZ4=${LZ4_FOUND})
|
||||
list(APPEND ROCKSDB_CMAKE_ARGS -DWITH_ZLIB=${ZLIB_FOUND})
|
||||
list(APPEND ROCKSDB_CMAKE_ARGS -DPORTABLE=ON)
|
||||
|
42
cmake/modules/Buildgperftools.cmake
Normal file
42
cmake/modules/Buildgperftools.cmake
Normal file
@ -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()
|
@ -5,13 +5,21 @@
|
||||
# SNAPPY_LIBRARIES - List of libraries when using snappy.
|
||||
# SNAPPY_FOUND - True if snappy found.
|
||||
|
||||
find_package(PkgConfig)
|
||||
pkg_search_module(PC_snappy
|
||||
QUIET snappy)
|
||||
|
||||
find_path(SNAPPY_INCLUDE_DIR
|
||||
NAMES snappy.h
|
||||
HINTS ${SNAPPY_ROOT_DIR}/include)
|
||||
HINTS
|
||||
${PC_snappy_INCLUDE_DIRS}
|
||||
${SNAPPY_ROOT_DIR}/include)
|
||||
|
||||
find_library(SNAPPY_LIBRARIES
|
||||
NAMES snappy
|
||||
HINTS ${SNAPPY_ROOT_DIR}/lib)
|
||||
HINTS
|
||||
${PC_snappy_LIBRARY_DIRS}
|
||||
${SNAPPY_ROOT_DIR}/lib)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(snappy DEFAULT_MSG SNAPPY_LIBRARIES SNAPPY_INCLUDE_DIR)
|
||||
|
24
make-dist
24
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
|
||||
|
@ -40,8 +40,12 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL GNU)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -rdynamic")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wstrict-null-sentinel -Woverloaded-virtual")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-new-ttp-matching")
|
||||
if(NOT WITH_OSD_INSTRUMENT_FUNCTIONS AND NOT HAVE_SEASTAR)
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie")
|
||||
# cmake does not add '-pie' for executables even if
|
||||
# CMAKE_POSITION_INDEPENDENT_CODE is TRUE.
|
||||
if(EXE_LINKER_USE_PIE)
|
||||
if (NOT WITH_OSD_INSTRUMENT_FUNCTIONS AND NOT HAVE_SEASTAR)
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie")
|
||||
endif()
|
||||
endif()
|
||||
elseif(CMAKE_CXX_COMPILER_ID STREQUAL Clang)
|
||||
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_EXPORTS_C_FLAG}")
|
||||
@ -444,14 +448,7 @@ if(WITH_DPDK)
|
||||
endif()
|
||||
|
||||
add_library(common STATIC ${ceph_common_objs})
|
||||
target_link_libraries(common
|
||||
PRIVATE ${ceph_common_deps})
|
||||
if(WITH_STATIC_LIBSTDCXX)
|
||||
# the apps linking against libcommon are daemons also written in C++, so we
|
||||
# need to link them against libstdc++.
|
||||
target_link_libraries(common
|
||||
INTERFACE "-static-libstdc++ -static-libgcc")
|
||||
endif()
|
||||
target_link_libraries(common ${ceph_common_deps})
|
||||
|
||||
add_library(ceph-common SHARED ${ceph_common_objs})
|
||||
target_link_libraries(ceph-common ${ceph_common_deps})
|
||||
@ -459,12 +456,6 @@ target_link_libraries(ceph-common ${ceph_common_deps})
|
||||
set_target_properties(ceph-common PROPERTIES
|
||||
SOVERSION 0
|
||||
INSTALL_RPATH "")
|
||||
if(WITH_STATIC_LIBSTDCXX)
|
||||
# link libstdc++ into ceph-common to avoid including libstdc++ in every apps,
|
||||
# to reduce the size of the app linking against ceph-common.
|
||||
set_target_properties(ceph-common PROPERTIES
|
||||
LINK_FLAGS "-static-libstdc++ -static-libgcc")
|
||||
endif()
|
||||
install(TARGETS ceph-common DESTINATION ${CMAKE_INSTALL_PKGLIBDIR})
|
||||
|
||||
if(${WITH_LTTNG})
|
||||
@ -554,6 +545,8 @@ target_link_libraries(ceph-osd osd os global-static common
|
||||
if(WITH_FUSE)
|
||||
target_link_libraries(ceph-osd ${FUSE_LIBRARIES})
|
||||
endif()
|
||||
set_target_properties(ceph-osd PROPERTIES
|
||||
POSITION_INDEPENDENT_CODE ${EXE_LINKER_USE_PIE})
|
||||
install(TARGETS ceph-osd DESTINATION bin)
|
||||
|
||||
add_subdirectory(mds)
|
||||
@ -649,10 +642,6 @@ if(WITH_LIBCEPHFS)
|
||||
add_library(cephfs ${CEPH_SHARED} ${libcephfs_srcs})
|
||||
target_link_libraries(cephfs PRIVATE client ceph-common
|
||||
${CRYPTO_LIBS} ${EXTRALIBS})
|
||||
if(WITH_STATIC_LIBSTDCXX)
|
||||
target_link_libraries(cephfs
|
||||
INTERFACE "-static-libstdc++ -static-libgcc")
|
||||
endif()
|
||||
if(ENABLE_SHARED)
|
||||
set_target_properties(cephfs PROPERTIES
|
||||
OUTPUT_NAME cephfs
|
||||
@ -693,9 +682,11 @@ if(WITH_FUSE)
|
||||
ceph_fuse.cc
|
||||
client/fuse_ll.cc)
|
||||
add_executable(ceph-fuse ${ceph_fuse_srcs})
|
||||
target_link_libraries(ceph-fuse ${ALLOC_LIBS} ${FUSE_LIBRARIES}
|
||||
target_link_libraries(ceph-fuse ${FUSE_LIBRARIES}
|
||||
client ceph-common global-static)
|
||||
set_target_properties(ceph-fuse PROPERTIES COMPILE_FLAGS "-I${FUSE_INCLUDE_DIRS}")
|
||||
set_target_properties(ceph-fuse PROPERTIES
|
||||
COMPILE_FLAGS "-I${FUSE_INCLUDE_DIRS}"
|
||||
POSITION_INDEPENDENT_CODE ${EXE_LINKER_USE_PIE})
|
||||
install(TARGETS ceph-fuse DESTINATION bin)
|
||||
install(PROGRAMS mount.fuse.ceph DESTINATION ${CMAKE_INSTALL_SBINDIR})
|
||||
endif(WITH_FUSE)
|
||||
|
@ -11,7 +11,7 @@ add_library(kv_objs OBJECT ${kv_srcs})
|
||||
add_library(kv STATIC $<TARGET_OBJECTS:kv_objs>)
|
||||
target_include_directories(kv_objs SYSTEM BEFORE PUBLIC ${ROCKSDB_INCLUDE_DIR})
|
||||
target_include_directories(kv SYSTEM BEFORE PUBLIC ${ROCKSDB_INCLUDE_DIR})
|
||||
target_link_libraries(kv ${LEVELDB_LIBRARIES} ${ROCKSDB_LIBRARIES} ${ALLOC_LIBS} ${SNAPPY_LIBRARIES} ${ZLIB_LIBRARIES})
|
||||
target_link_libraries(kv ${LEVELDB_LIBRARIES} ${ROCKSDB_LIBRARIES} ${SNAPPY_LIBRARIES} ${ZLIB_LIBRARIES})
|
||||
if(WITH_LZ4)
|
||||
target_link_libraries(kv ${LZ4_LIBRARY})
|
||||
endif()
|
||||
|
@ -30,10 +30,6 @@ endif(ENABLE_SHARED)
|
||||
target_link_libraries(librados PRIVATE
|
||||
osdc ceph-common cls_lock_client
|
||||
${BLKID_LIBRARIES} ${CRYPTO_LIBS} ${EXTRALIBS})
|
||||
if(WITH_STATIC_LIBSTDCXX)
|
||||
target_link_libraries(librados
|
||||
INTERFACE "-static-libstdc++ -static-libgcc")
|
||||
endif()
|
||||
target_link_libraries(librados ${rados_libs})
|
||||
install(TARGETS librados DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
|
||||
|
@ -7,10 +7,6 @@ add_library(radosstriper ${CEPH_SHARED}
|
||||
$<TARGET_OBJECTS:librados_objs>)
|
||||
target_link_libraries(radosstriper
|
||||
PRIVATE librados cls_lock_client osdc ceph-common pthread ${CRYPTO_LIBS} ${EXTRALIBS})
|
||||
if(WITH_STATIC_LIBSTDCXX)
|
||||
target_link_libraries(radosstriper
|
||||
INTERFACE "-static-libstdc++ -static-libgcc")
|
||||
endif()
|
||||
set_target_properties(radosstriper PROPERTIES
|
||||
OUPUT_NAME radosstriper
|
||||
VERSION 1.0.0
|
||||
|
@ -157,10 +157,6 @@ if(HAVE_UDEV)
|
||||
target_link_libraries(librbd PRIVATE
|
||||
udev)
|
||||
endif()
|
||||
if(WITH_STATIC_LIBSTDCXX)
|
||||
target_link_libraries(librbd INTERFACE
|
||||
"-static-libstdc++ -static-libgcc")
|
||||
endif()
|
||||
if(ENABLE_SHARED)
|
||||
set_target_properties(librbd PROPERTIES
|
||||
OUTPUT_NAME rbd
|
||||
|
@ -44,4 +44,4 @@ set(mds_srcs
|
||||
${CMAKE_SOURCE_DIR}/src/osdc/Journaler.cc)
|
||||
add_library(mds STATIC ${mds_srcs})
|
||||
target_link_libraries(mds PRIVATE
|
||||
heap_profiler cpu_profiler ${ALLOC_LIBS} osdc liblua)
|
||||
heap_profiler cpu_profiler osdc liblua)
|
||||
|
@ -24,5 +24,7 @@ target_include_directories(ceph-mgr SYSTEM PRIVATE "${PYTHON_INCLUDE_DIRS}")
|
||||
target_link_libraries(ceph-mgr
|
||||
osdc client heap_profiler
|
||||
global-static ceph-common
|
||||
Boost::python ${MGR_PYTHON_LIBRARIES} ${CMAKE_DL_LIBS} ${ALLOC_LIBS})
|
||||
Boost::python ${MGR_PYTHON_LIBRARIES} ${CMAKE_DL_LIBS})
|
||||
set_target_properties(ceph-mgr PROPERTIES
|
||||
POSITION_INDEPENDENT_CODE ${EXE_LINKER_USE_PIE})
|
||||
install(TARGETS ceph-mgr DESTINATION bin)
|
||||
|
@ -26,4 +26,4 @@ set(lib_mon_srcs
|
||||
add_library(mon STATIC
|
||||
${lib_mon_srcs}
|
||||
$<TARGET_OBJECTS:kv_objs>)
|
||||
target_link_libraries(mon heap_profiler ${ALLOC_LIBS})
|
||||
target_link_libraries(mon heap_profiler)
|
||||
|
@ -45,7 +45,7 @@ add_library(osd STATIC ${osd_srcs}
|
||||
$<TARGET_OBJECTS:global_common_objs>)
|
||||
target_link_libraries(osd PRIVATE
|
||||
${LEVELDB_LIBRARIES}
|
||||
dmclock heap_profiler cpu_profiler ${CMAKE_DL_LIBS} ${ALLOC_LIBS})
|
||||
dmclock heap_profiler cpu_profiler ${CMAKE_DL_LIBS})
|
||||
if(WITH_LTTNG)
|
||||
add_dependencies(osd osd-tp pg-tp)
|
||||
endif()
|
||||
|
@ -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
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 9090ae3ecfbf9b50a398a5d8b178f14b88dc047e
|
||||
Subproject commit 8e78d1040a6e2bae1577c484feefb2b92038ab9d
|
Loading…
Reference in New Issue
Block a user