Skip to content

Commit

Permalink
Introduce HICTK_PREFER_STATIC_LINKING build knob
Browse files Browse the repository at this point in the history
  • Loading branch information
robomics committed Feb 11, 2024
1 parent 6e1a211 commit c011251
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 5 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ option(HICTK_BUILD_EXAMPLES "Build examples" OFF)
option(HICTK_BUILD_BENCHMARKS "Build benchmarks" OFF)
option(HICTK_WITH_EIGEN "Build with Eigen3 support" ON)
option(HICTK_BUILD_TOOLS "Build cli tools" ON)
option(HICTK_PREFER_STATIC_LINKING "Prefer linking to static libraries" OFF)

if(HICTK_WITH_EIGEN)
target_compile_definitions(hictk_project_options INTERFACE HICTK_WITH_EIGEN)
Expand Down
16 changes: 14 additions & 2 deletions src/libhictk/balancing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,19 @@ target_link_system_libraries(
INTERFACE
bshoshany-thread-pool::bshoshany-thread-pool
nonstd::span-lite
phmap
"zstd::libzstd_$<IF:$<BOOL:${BUILD_SHARED_LIBS}>,shared,static>")
phmap)

if(BUILD_SHARED_LIBS AND HICTK_PREFER_STATIC_LINKING)
if(TARGET zstd::libzstd_static)
target_link_system_libraries(balancing INTERFACE zstd::libzstd_static)
else()
target_link_system_libraries(balancing INTERFACE zstd::libzstd_shared)
endif()
else()
target_link_system_libraries(
balancing
INTERFACE
"zstd::libzstd_$<IF:$<BOOL:${BUILD_SHARED_LIBS}>,shared,static>")
endif()

target_compile_definitions(balancing INTERFACE span_FEATURE_MAKE_SPAN=1)
23 changes: 20 additions & 3 deletions src/libhictk/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ target_sources(
target_include_directories(common INTERFACE "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>"
"$<INSTALL_INTERFACE:include>")

target_link_libraries(
common INTERFACE fmt::fmt-header-only "libdeflate::libdeflate_$<IF:$<BOOL:${BUILD_SHARED_LIBS}>,shared,static>"
"zstd::libzstd_$<IF:$<BOOL:${BUILD_SHARED_LIBS}>,shared,static>")
target_link_system_libraries(common INTERFACE fmt::fmt-header-only)

if(BUILD_SHARED_LIBS AND HICTK_PREFER_STATIC_LINKING)
if(TARGET libdeflate::libdeflate_static)
target_link_system_libraries(common INTERFACE libdeflate::libdeflate_static)
else()
target_link_system_libraries(common INTERFACE libdeflate::libdeflate_shared)
endif()
if(TARGET zstd::libzstd_static)
target_link_system_libraries(common INTERFACE zstd::libzstd_static)
else()
target_link_system_libraries(common INTERFACE zstd::libzstd_shared)
endif()
else()
target_link_system_libraries(
common
INTERFACE
"libdeflate::libdeflate_$<IF:$<BOOL:${BUILD_SHARED_LIBS}>,shared,static>"
"zstd::libzstd_$<IF:$<BOOL:${BUILD_SHARED_LIBS}>,shared,static>")
endif()
19 changes: 19 additions & 0 deletions src/libhictk/hic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,22 @@ target_link_system_libraries(
phmap
readerwriterqueue::readerwriterqueue
"zstd::libzstd_$<IF:$<BOOL:${BUILD_SHARED_LIBS}>,shared,static>")

if(BUILD_SHARED_LIBS AND HICTK_PREFER_STATIC_LINKING)
if(TARGET libdeflate::libdeflate_static)
target_link_system_libraries(hic INTERFACE libdeflate::libdeflate_static)
else()
target_link_system_libraries(hic INTERFACE libdeflate::libdeflate_shared)
endif()
if(TARGET zstd::libzstd_static)
target_link_system_libraries(hic INTERFACE zstd::libzstd_static)
else()
target_link_system_libraries(hic INTERFACE zstd::libzstd_shared)
endif()
else()
target_link_system_libraries(
hic
INTERFACE
"libdeflate::libdeflate_$<IF:$<BOOL:${BUILD_SHARED_LIBS}>,shared,static>"
"zstd::libzstd_$<IF:$<BOOL:${BUILD_SHARED_LIBS}>,shared,static>")
endif()

0 comments on commit c011251

Please sign in to comment.