Skip to content

Commit

Permalink
cmake: pass static linkflags to the linker who links libcommon
Browse files Browse the repository at this point in the history
Signed-off-by: Kefu Chai <kchai@redhat.com>
  • Loading branch information
tchaikov committed Jan 4, 2018
1 parent 24bc418 commit 75c5e5c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
21 changes: 16 additions & 5 deletions src/CMakeLists.txt
Expand Up @@ -682,7 +682,14 @@ if(WITH_DPDK)
endif(WITH_DPDK)

add_library(common STATIC ${ceph_common_objs})
target_link_libraries(common ${ceph_common_deps})
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()

add_library(ceph-common SHARED ${ceph_common_objs})
target_link_libraries(ceph-common ${ceph_common_deps})
Expand All @@ -691,10 +698,10 @@ 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")
set_target_properties(common PROPERTIES
LINK_FLAGS "-static-libstdc++ -static-libgcc")
endif()
install(TARGETS ceph-common DESTINATION ${CMAKE_INSTALL_PKGLIBDIR})

Expand Down Expand Up @@ -978,6 +985,10 @@ 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
Expand All @@ -998,7 +1009,7 @@ if(WITH_LIBCEPHFS)
ceph_syn.cc
client/SyntheticClient.cc)
add_executable(ceph-syn ${ceph_syn_srcs})
target_link_libraries(ceph-syn client global-static common)
target_link_libraries(ceph-syn client global-static ceph-common)

set(mount_ceph_srcs
mount/mount.ceph.c)
Expand All @@ -1019,7 +1030,7 @@ if(WITH_FUSE)
client/fuse_ll.cc)
add_executable(ceph-fuse ${ceph_fuse_srcs})
target_link_libraries(ceph-fuse ${ALLOC_LIBS} ${FUSE_LIBRARIES}
client common global-static)
client ceph-common global-static)
set_target_properties(ceph-fuse PROPERTIES COMPILE_FLAGS "-I${FUSE_INCLUDE_DIRS}")
install(TARGETS ceph-fuse DESTINATION bin)
install(PROGRAMS mount.fuse.ceph DESTINATION ${CMAKE_INSTALL_SBINDIR})
Expand Down
12 changes: 8 additions & 4 deletions src/librados/CMakeLists.txt
Expand Up @@ -12,8 +12,6 @@ if(ENABLE_SHARED)
$<TARGET_OBJECTS:librados_api_obj>
$<TARGET_OBJECTS:librados_objs>
$<TARGET_OBJECTS:common_buffer_obj>)
target_link_libraries(librados PRIVATE osdc ceph-common cls_lock_client
${BLKID_LIBRARIES} ${CRYPTO_LIBS} ${EXTRALIBS})
set_target_properties(librados PROPERTIES
OUTPUT_NAME rados
VERSION 2.0.0
Expand All @@ -28,9 +26,15 @@ else(ENABLE_SHARED)
add_library(librados STATIC
$<TARGET_OBJECTS:librados_api_obj>
$<TARGET_OBJECTS:librados_objs>)
target_link_libraries(librados osdc ceph-common cls_lock_client
${BLKID_LIBRARIES} ${CRYPTO_LIBS} ${EXTRALIBS})
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})

if(WITH_EMBEDDED)
Expand Down
7 changes: 6 additions & 1 deletion src/libradosstriper/CMakeLists.txt
Expand Up @@ -5,7 +5,12 @@ set(libradosstriper_srcs
add_library(radosstriper ${CEPH_SHARED}
${libradosstriper_srcs}
$<TARGET_OBJECTS:librados_objs>)
target_link_libraries(radosstriper librados cls_lock_client osdc ceph-common pthread ${CRYPTO_LIBS} ${EXTRALIBS})
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
Expand Down
4 changes: 4 additions & 0 deletions src/librbd/CMakeLists.txt
Expand Up @@ -147,6 +147,10 @@ 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
Expand Down

0 comments on commit 75c5e5c

Please sign in to comment.