Permalink
Browse files

cmake: turn libcommon into a shared library

prior to this change, libcommon is a convenient library which gets
linked into librados, librbd and libcephfs and all ceph executables.
this incurs some problems:
 - double dose of libcommon in memory space and HDD: waste of memory
   and disk space.
 - if an application links to two libraries including libcommon at the
   same time. take librados and libcephfs as an example, they could
   interfere with each other by changing the other guy's status.
after this change, libcommon is tuned into a shared library and
renamed to libceph-common. it will be installed into $prefix/lib/ceph,
and packaged in librados2.

ceph.spec.in,debian/librados2.install: package libceph-common in
  librados2.
CMakeLists.txt:
  - do not link against libboost-* if not necessary.
  - s/common/ceph-common/g
  - install libceph-common into $prefix/lib/ceph
  - set rpath to $prefix/lib/ceph
  - link against ceph-common if an executable needs access to non public
    symbols in ceph.

Signed-off-by: Kefu Chai <kchai@redhat.com>
  • Loading branch information...
1 parent 0bf9c62 commit 8f7643792c9e6a3d1ba4a06ca7d09b0de9af1443 @tchaikov tchaikov committed Jan 9, 2017
View
@@ -518,15 +518,6 @@ find_package(Boost 1.61 COMPONENTS ${BOOST_COMPONENTS} REQUIRED)
include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
include_directories(SYSTEM ${PROJECT_BINARY_DIR}/include)
-if (WITH_SYSTEM_BOOST)
- if(FREEBSD)
- # if boost_python is used then also link with libpython*
- LIST(APPEND Boost_LIBRARIES ${PYTHON_LIBRARIES})
- endif()
-else()
- LIST(APPEND Boost_LIBRARIES "-lz")
-endif()
-
CHECK_INCLUDE_FILE_CXX("boost/asio/coroutine.hpp" HAVE_BOOST_ASIO_COROUTINE)
find_package(Threads REQUIRED)
View
@@ -1353,6 +1353,8 @@ fi
%files -n librados2
%defattr(-,root,root,-)
%{_libdir}/librados.so.*
+%dir %{_libdir}/ceph
+%{_libdir}/ceph/libceph-common.so
%if %{with lttng}
%{_libdir}/librados_tp.so.*
%endif
@@ -1,2 +1,3 @@
usr/lib/librados.so.*
usr/lib/librados_tp.so.*
+usr/lib/ceph/libceph-common.so
View
@@ -5,6 +5,12 @@ include(GNUInstallDirs)
# for erasure and compressor plugins
set(CMAKE_INSTALL_PKGLIBDIR ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME})
set(CMAKE_INSTALL_FULL_PKGLIBDIR ${CMAKE_INSTALL_FULL_LIBDIR}/${PROJECT_NAME})
+# so libceph-common can be found
+set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
+if(NOT CMAKE_INSTALL_RPATH)
+ set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_FULL_PKGLIBDIR}")
+endif()
+
# to be compatible with configure_files shared with autoconfig
set(bindir ${CMAKE_INSTALL_FULL_BINDIR})
set(sbindir ${CMAKE_INSTALL_FULL_SBINDIR})
@@ -424,8 +430,6 @@ set(libcommon_files
common/TrackedOp.cc
common/SloppyCRCMap.cc
common/types.cc
- $<TARGET_OBJECTS:common_buffer_obj>
- $<TARGET_OBJECTS:common_texttable_obj>
log/Log.cc
log/SubsystemMap.cc
mon/MonCap.cc
@@ -503,7 +507,6 @@ set(libcommon_files
common/dns_resolve.cc
${arch_files}
${auth_files}
- $<TARGET_OBJECTS:compressor_objs>
${mds_files})
if(LINUX)
list(APPEND libcommon_files msg/async/EventEpoll.cc)
@@ -534,17 +537,36 @@ else()
perfglue/disabled_stubs.cc)
endif()
-if(ENABLE_SHARED)
- list(APPEND libcommon_files
- $<TARGET_OBJECTS:global_common_objs>)
-endif(ENABLE_SHARED)
-
-add_library(common STATIC ${libcommon_files}
- $<TARGET_OBJECTS:mon_common_objs>
- $<TARGET_OBJECTS:common_mountcephfs_objs>)
-target_link_libraries(common json_spirit erasure_code rt ${LIB_RESOLV}
- ${Boost_LIBRARIES} ${BLKID_LIBRARIES} ${Backtrace_LIBRARIES}
+add_library(common-objs OBJECT ${libcommon_files})
+add_library(ceph-common SHARED
+ $<TARGET_OBJECTS:common_buffer_obj>
+ $<TARGET_OBJECTS:common_texttable_obj>
+ $<TARGET_OBJECTS:compressor_objs>
+ $<TARGET_OBJECTS:common-objs>
+ $<TARGET_OBJECTS:common_mountcephfs_objs>
+ $<TARGET_OBJECTS:global_common_objs>)
+target_link_libraries(ceph-common json_spirit erasure_code rt ${LIB_RESOLV}
+ ${Boost_THREAD_LIBRARY}
+ ${Boost_SYSTEM_LIBRARY}
+ ${Boost_REGEX_LIBRARY}
+ ${Boost_RANDOM_LIBRARY}
+ ${Boost_PROGRAM_OPTIONS_LIBRARY}
+ ${Boost_DATE_TIME_LIBRARY}
+ ${Boost_IOSTREAMS_LIBRARY}
+ ${BLKID_LIBRARIES} ${Backtrace_LIBRARIES}
${CRYPTO_LIBS} ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS})
+if(NOT WITH_SYSTEM_BOOST)
+ target_link_libraries(ceph-common ${ZLIB_LIBRARIES})
+endif()
+install(TARGETS ceph-common DESTINATION ${CMAKE_INSTALL_PKGLIBDIR})
+if(WITH_EMBEDDED)
+ add_library(cephd_common STATIC
+ $<TARGET_OBJECTS:common_buffer_obj>
+ $<TARGET_OBJECTS:common_texttable_obj>
+ $<TARGET_OBJECTS:compressor_objs>
+ $<TARGET_OBJECTS:common-objs>
+ $<TARGET_OBJECTS:common_mountcephfs_objs>)
+endif()
set_source_files_properties(${CMAKE_SOURCE_DIR}/src/ceph_ver.c
${CMAKE_SOURCE_DIR}/src/common/version.cc
@@ -554,7 +576,7 @@ set_source_files_properties(${CMAKE_SOURCE_DIR}/src/ceph_ver.c
include(SIMDExt)
if(HAVE_ARMV8_CRC)
add_library(common_crc_aarch64 STATIC common/crc32c_aarch64.c)
- target_link_libraries(common common_crc_aarch64)
+ target_link_libraries(ceph-common common_crc_aarch64)
endif(HAVE_ARMV8_CRC)
add_library(common_utf8 STATIC common/utf8.c)
@@ -681,7 +703,7 @@ set(ceph_mon_srcs
add_executable(ceph-mon ${ceph_mon_srcs}
$<TARGET_OBJECTS:common_texttable_obj>)
add_dependencies(ceph-mon erasure_code_plugins)
- target_link_libraries(ceph-mon mon common os global ${EXTRALIBS}
+ target_link_libraries(ceph-mon mon ceph-common os global ${EXTRALIBS}
${CMAKE_DL_LIBS})
install(TARGETS ceph-mon DESTINATION bin)
@@ -841,7 +863,7 @@ if(WITH_LIBCEPHFS)
target_link_libraries(cephfs LINK_PRIVATE client
${CRYPTO_LIBS} ${EXTRALIBS})
if(ENABLE_SHARED)
- foreach(name common client osdc)
+ foreach(name ceph-common client osdc)
set(CEPHFS_LINK_FLAGS "${CEPHFS_LINK_FLAGS} -Wl,--exclude-libs,lib${name}.a")
endforeach()
set_target_properties(cephfs PROPERTIES
@@ -8,4 +8,4 @@ set(libclient_srcs
Trace.cc
posix_acl.cc)
add_library(client STATIC ${libclient_srcs})
-target_link_libraries(client common osdc)
+target_link_libraries(client ceph-common osdc)
@@ -6,7 +6,7 @@ set(snappy_sources
add_library(ceph_snappy SHARED ${snappy_sources})
add_dependencies(ceph_snappy ${CMAKE_SOURCE_DIR}/src/ceph_ver.h)
-target_link_libraries(ceph_snappy snappy common)
+target_link_libraries(ceph_snappy snappy)
set_target_properties(ceph_snappy PROPERTIES VERSION 2.0.0 SOVERSION 2)
install(TARGETS ceph_snappy DESTINATION ${compressor_plugin_dir})
@@ -29,7 +29,7 @@ endif(HAVE_INTEL_SSE4_1 AND HAVE_BETTER_YASM_ELF64)
add_library(ceph_zlib SHARED ${zlib_sources})
add_dependencies(ceph_zlib ${CMAKE_SOURCE_DIR}/src/ceph_ver.h)
-target_link_libraries(ceph_zlib z common)
+target_link_libraries(ceph_zlib z)
target_include_directories(ceph_zlib PRIVATE "${CMAKE_SOURCE_DIR}/src/isa-l/include")
set_target_properties(ceph_zlib PROPERTIES VERSION 2.0.0 SOVERSION 2)
install(TARGETS ceph_zlib DESTINATION ${compressor_plugin_dir})
@@ -7,4 +7,4 @@ set(global_common_files
add_library(global_common_objs OBJECT ${global_common_files})
add_library(global STATIC ${libglobal_srcs}
$<TARGET_OBJECTS:global_common_objs>)
-target_link_libraries(global common ${DPDK_LIBRARIES} ${EXTRALIBS})
+target_link_libraries(global ceph-common ${DPDK_LIBRARIES} ${EXTRALIBS})
@@ -8,6 +8,7 @@ set_target_properties(cephfs_jni PROPERTIES
SOVERSION 1)
add_dependencies(cephfs_jni jni-header)
include_directories(${JNI_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR})
-target_link_libraries(cephfs_jni LINK_PRIVATE cephfs common ${EXTRALIBS} ${JNI_LIBRARIES})
+target_link_libraries(cephfs_jni LINK_PRIVATE cephfs ceph-common
+ ${EXTRALIBS} ${JNI_LIBRARIES})
install(TARGETS cephfs_jni
DESTINATION ${CMAKE_INSTALL_LIBDIR})
@@ -1,4 +1,4 @@
add_library(json_spirit STATIC
json_spirit_reader.cpp
json_spirit_writer.cpp)
-target_link_libraries(json_spirit ${Boost_LIBRARIES} common_utf8)
+target_link_libraries(json_spirit common_utf8)
@@ -15,7 +15,7 @@ set(merge_libs
cephd_cls_kvs
cephd_rados
cephd_rbd
- common
+ cephd_common
common_utf8
erasure_code
global
@@ -8,7 +8,7 @@ add_library(rados_a STATIC
$<TARGET_OBJECTS:librados_api_obj>
$<TARGET_OBJECTS:librados_objs>
$<TARGET_OBJECTS:common_buffer_obj>)
-target_link_libraries(rados_a osdc common cls_lock_client
+target_link_libraries(rados_a osdc ceph-common cls_lock_client
${BLKID_LIBRARIES} ${CRYPTO_LIBS} ${EXTRALIBS})
if(WITH_LTTNG)
add_dependencies(librados_api_obj librados-tp)
@@ -19,7 +19,7 @@ if(ENABLE_SHARED)
$<TARGET_OBJECTS:librados_objs>
$<TARGET_OBJECTS:common_buffer_obj>)
# LINK_PRIVATE instead of PRIVATE is used to backward compatibility with cmake 2.8.11
- target_link_libraries(librados LINK_PRIVATE osdc common cls_lock_client
+ target_link_libraries(librados LINK_PRIVATE osdc ceph-common cls_lock_client
${BLKID_LIBRARIES} ${CRYPTO_LIBS} ${EXTRALIBS})
set_target_properties(librados PROPERTIES
OUTPUT_NAME rados
@@ -5,7 +5,7 @@ set(libradosstriper_srcs
add_library(radosstriper ${CEPH_SHARED}
${libradosstriper_srcs}
$<TARGET_OBJECTS:librados_objs>)
-target_link_libraries(radosstriper librados cls_lock_client osdc common pthread ${CRYPTO_LIBS} ${EXTRALIBS})
+target_link_libraries(radosstriper librados cls_lock_client osdc ceph-common pthread ${CRYPTO_LIBS} ${EXTRALIBS})
set_target_properties(radosstriper PROPERTIES
OUPUT_NAME radosstriper
VERSION 1.0.0
@@ -107,7 +107,7 @@ target_link_libraries(librbd LINK_PRIVATE
cls_rbd_client
cls_lock_client
cls_journal_client
- common
+ ceph-common
pthread
${CMAKE_DL_LIBS}
${EXTRALIBS})
@@ -40,4 +40,4 @@ set(mds_srcs
add_library(mds STATIC ${mds_srcs}
$<TARGET_OBJECTS:heap_profiler_objs>
$<TARGET_OBJECTS:common_util_obj>)
-target_link_libraries(mds ${ALLOC_LIBS} osdc common liblua)
+target_link_libraries(mds ${ALLOC_LIBS} osdc ceph-common liblua)
@@ -1,5 +1,5 @@
add_executable(rbd-fuse
rbd-fuse.cc)
target_link_libraries(rbd-fuse
- librbd librados common ${FUSE_LIBRARIES})
+ ceph-common librbd librados ${FUSE_LIBRARIES})
install(TARGETS rbd-fuse DESTINATION bin)
@@ -15,7 +15,7 @@ target_link_libraries(rbd_replay LINK_PRIVATE librbd librados global)
add_executable(rbd-replay
rbd-replay.cc)
target_link_libraries(rbd-replay
- librbd librados global rbd_replay rbd_replay_types common)
+ librbd librados global rbd_replay rbd_replay_types ceph-common)
install(TARGETS rbd-replay DESTINATION bin)
set(librbd_replay_ios_srcs
@@ -32,7 +32,7 @@ if(${WITH_BABELTRACE})
rbd_replay_types
librbd
librados
- common
+ ceph-common
global
babeltrace
babeltrace-ctf
@@ -111,7 +111,7 @@ target_include_directories(rgw_a PUBLIC
target_link_libraries(rgw_a librados cls_lock_client cls_rgw_client cls_refcount_client
cls_log_client cls_statelog_client cls_timeindex_client cls_version_client
- cls_replica_log_client cls_user_client common common_utf8 global
+ cls_replica_log_client cls_user_client ceph-common common_utf8 global
${CURL_LIBRARIES}
${EXPAT_LIBRARIES}
${OPENLDAP_LIBRARIES} ${CRYPTO_LIBS})
Oops, something went wrong.

0 comments on commit 8f76437

Please sign in to comment.