From 16e2da3352ffb05b03da122c9996efb74ded0801 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sun, 2 Sep 2018 14:42:54 +0800 Subject: [PATCH] cmake: link compressor plugins against lib the modern way * always link against the target library not library paths * import their include directories by linking against their target library, instead of doing so using target_include_directories() manually. Signed-off-by: Kefu Chai --- src/compressor/brotli/CMakeLists.txt | 9 +++++---- src/compressor/lz4/CMakeLists.txt | 2 +- src/compressor/snappy/CMakeLists.txt | 4 +--- src/compressor/zlib/CMakeLists.txt | 2 +- src/compressor/zstd/CMakeLists.txt | 7 +++---- 5 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/compressor/brotli/CMakeLists.txt b/src/compressor/brotli/CMakeLists.txt index bbf90b1603ea1..84648362d286f 100644 --- a/src/compressor/brotli/CMakeLists.txt +++ b/src/compressor/brotli/CMakeLists.txt @@ -26,12 +26,13 @@ set(bortli_libs enc dec common) foreach(lib ${bortli_libs}) add_library(brotli::${lib} STATIC IMPORTED) add_dependencies(brotli::${lib} brotli_ext) - set_property(TARGET brotli::${lib} PROPERTY IMPORTED_LOCATION "${CMAKE_BINARY_DIR}/src/brotli/libbrotli${lib}-static.a") + set_target_properties(brotli::${lib} PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_BINARY_DIR}/src/brotli/c/include" + IMPORTED_LOCATION "${CMAKE_BINARY_DIR}/src/brotli/libbrotli${lib}-static.a") list(APPEND BROTLI_LIBRARIES brotli::${lib}) endforeach() add_library(ceph_brotli SHARED ${brotli_sources}) -target_include_directories(ceph_brotli PRIVATE "${CMAKE_BINARY_DIR}/src/brotli/c/include") -List(REVERSE bortli_libs) -target_link_libraries(ceph_brotli ${BROTLI_LIBRARIES}) +list(REVERSE bortli_libs) +target_link_libraries(ceph_brotli PRIVATE ${BROTLI_LIBRARIES}) install(TARGETS ceph_brotli DESTINATION ${compressor_plugin_dir}) diff --git a/src/compressor/lz4/CMakeLists.txt b/src/compressor/lz4/CMakeLists.txt index 11d8576fac230..7a8a15d674fc9 100644 --- a/src/compressor/lz4/CMakeLists.txt +++ b/src/compressor/lz4/CMakeLists.txt @@ -5,7 +5,7 @@ set(lz4_sources ) add_library(ceph_lz4 SHARED ${lz4_sources}) -target_link_libraries(ceph_lz4 ${LZ4_LIBRARY}) +target_link_libraries(ceph_lz4 PRIVATE LZ4::LZ4) set_target_properties(ceph_lz4 PROPERTIES VERSION 2.0.0 SOVERSION 2 diff --git a/src/compressor/snappy/CMakeLists.txt b/src/compressor/snappy/CMakeLists.txt index 05df62024ca54..0bb233d4cde5b 100644 --- a/src/compressor/snappy/CMakeLists.txt +++ b/src/compressor/snappy/CMakeLists.txt @@ -5,9 +5,7 @@ set(snappy_sources ) add_library(ceph_snappy SHARED ${snappy_sources}) -target_include_directories(ceph_snappy SYSTEM PRIVATE - "${SNAPPY_INCLUDE_DIR}") -target_link_libraries(ceph_snappy snappy::snappy) +target_link_libraries(ceph_snappy PRIVATE snappy::snappy) set_target_properties(ceph_snappy PROPERTIES VERSION 2.0.0 SOVERSION 2 diff --git a/src/compressor/zlib/CMakeLists.txt b/src/compressor/zlib/CMakeLists.txt index 109fef521fc1e..51aba0834d356 100644 --- a/src/compressor/zlib/CMakeLists.txt +++ b/src/compressor/zlib/CMakeLists.txt @@ -38,7 +38,7 @@ else(HAVE_INTEL_SSE4_1 AND HAVE_BETTER_YASM_ELF64 AND (NOT APPLE)) endif(HAVE_INTEL_SSE4_1 AND HAVE_BETTER_YASM_ELF64 AND (NOT APPLE)) add_library(ceph_zlib SHARED ${zlib_sources}) -target_link_libraries(ceph_zlib ${ZLIB_LIBRARIES}) +target_link_libraries(ceph_zlib ZLIB::ZLIB) target_include_directories(ceph_zlib SYSTEM PRIVATE "${CMAKE_SOURCE_DIR}/src/isa-l/include") set_target_properties(ceph_zlib PROPERTIES VERSION 2.0.0 diff --git a/src/compressor/zstd/CMakeLists.txt b/src/compressor/zstd/CMakeLists.txt index e30cb895aee29..c730e48b16d6d 100644 --- a/src/compressor/zstd/CMakeLists.txt +++ b/src/compressor/zstd/CMakeLists.txt @@ -22,18 +22,17 @@ ExternalProject_Add_Step(zstd_ext forcebuild ALWAYS 1) add_library(zstd STATIC IMPORTED) -set_property(TARGET zstd PROPERTY +set_target_properties(zstd PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${CMAKE_SOURCE_DIR}/src/zstd/lib" IMPORTED_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/libzstd/lib/libzstd.a") add_dependencies(zstd zstd_ext) -set(ZSTD_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/src/zstd/lib) -# set(zstd_sources CompressionPluginZstd.cc ) add_library(ceph_zstd SHARED ${zstd_sources}) -target_link_libraries(ceph_zstd zstd) +target_link_libraries(ceph_zstd PRIVATE zstd) set_target_properties(ceph_zstd PROPERTIES VERSION 2.0.0 SOVERSION 2 -- 2.39.5