Skip to content

Commit 55d4d86

Browse files
ckissanetru
authored andcommitted
tweak zstd behavior in cmake and llvm config for better testing
add LLVM_PREFER_STATIC_ZSTD (default TRUE) cmake config flag (compression test seems to fail for shared zstd on windows, note that zstd multithread is by default disabled in the static build so it may be a hidden variable) propagate variable zstd_DIR in LLVMConfig.cmake.in fix llvm-config CMakeLists.txt behavior for absolute libs windows get zstd lib name Reviewed By: phosek Differential Revision: https://reviews.llvm.org/D132870 (cherry picked from commit c0b4f24)
1 parent 67ac047 commit 55d4d86

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

llvm/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,8 @@ set(LLVM_ENABLE_ZLIB "ON" CACHE STRING "Use zlib for compression/decompression i
446446

447447
set(LLVM_ENABLE_ZSTD "ON" CACHE STRING "Use zstd for compression/decompression if available. Can be ON, OFF, or FORCE_ON")
448448

449+
set(LLVM_PREFER_STATIC_ZSTD TRUE CACHE BOOL "Use static version of zstd if available. Can be TRUE, FALSE")
450+
449451
set(LLVM_ENABLE_CURL "OFF" CACHE STRING "Use libcurl for the HTTP client if available. Can be ON, OFF, or FORCE_ON")
450452

451453
set(LLVM_ENABLE_HTTPLIB "OFF" CACHE STRING "Use cpp-httplib HTTP server library if available. Can be ON, OFF, or FORCE_ON")

llvm/cmake/modules/LLVMConfig.cmake.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ endif()
7575

7676
set(LLVM_ENABLE_ZSTD @LLVM_ENABLE_ZSTD@)
7777
if(LLVM_ENABLE_ZSTD)
78-
set(zstd_ROOT @zstd_ROOT@)
7978
find_package(zstd)
8079
endif()
8180

llvm/lib/Support/CMakeLists.txt

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,29 @@ if (HAS_WERROR_GLOBAL_CTORS)
2222
endif()
2323

2424
if(LLVM_ENABLE_ZLIB)
25-
set(imported_libs ZLIB::ZLIB)
25+
list(APPEND imported_libs ZLIB::ZLIB)
26+
endif()
27+
28+
set(zstd_target none)
29+
30+
if(LLVM_ENABLE_ZSTD)
31+
if(LLVM_PREFER_STATIC_ZSTD)
32+
if(TARGET zstd::libzstd_static)
33+
set(zstd_target zstd::libzstd_static)
34+
else()
35+
set(zstd_target zstd::libzstd_shared)
36+
endif()
37+
else()
38+
if(TARGET zstd::libzstd_shared)
39+
set(zstd_target zstd::libzstd_shared)
40+
else()
41+
set(zstd_target zstd::libzstd_static)
42+
endif()
43+
endif()
2644
endif()
2745

2846
if(LLVM_ENABLE_ZSTD)
29-
list(APPEND imported_libs zstd::libzstd_shared)
47+
list(APPEND imported_libs ${zstd_target})
3048
endif()
3149

3250
if( MSVC OR MINGW )
@@ -300,11 +318,12 @@ if(LLVM_ENABLE_ZSTD)
300318
# CMAKE_BUILD_TYPE is only meaningful to single-configuration generators.
301319
if(CMAKE_BUILD_TYPE)
302320
string(TOUPPER ${CMAKE_BUILD_TYPE} build_type)
303-
get_property(zstd_library TARGET zstd::libzstd_shared PROPERTY LOCATION_${build_type})
321+
get_property(zstd_library TARGET ${zstd_target} PROPERTY LOCATION_${build_type})
304322
endif()
305323
if(NOT zstd_library)
306-
get_property(zstd_library TARGET zstd::libzstd_shared PROPERTY LOCATION)
324+
get_property(zstd_library TARGET ${zstd_target} PROPERTY LOCATION)
307325
endif()
326+
get_library_name(${zstd_library} zstd_library)
308327
set(llvm_system_libs ${llvm_system_libs} "${zstd_library}")
309328
endif()
310329

llvm/tools/llvm-config/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,14 @@ add_llvm_tool(llvm-config
1717
# Compute the substitution values for various items.
1818
get_property(SUPPORT_SYSTEM_LIBS TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS)
1919
get_property(WINDOWSMANIFEST_SYSTEM_LIBS TARGET LLVMWindowsManifest PROPERTY LLVM_SYSTEM_LIBS)
20+
2021
foreach(l ${SUPPORT_SYSTEM_LIBS} ${WINDOWSMANIFEST_SYSTEM_LIBS})
2122
if(MSVC)
22-
set(SYSTEM_LIBS ${SYSTEM_LIBS} "${l}.lib")
23+
if(IS_ABSOLUTE ${l})
24+
set(SYSTEM_LIBS ${SYSTEM_LIBS} "${l}")
25+
else()
26+
set(SYSTEM_LIBS ${SYSTEM_LIBS} "${l}.lib")
27+
endif()
2328
else()
2429
if (l MATCHES "^-")
2530
# If it's an option, pass it without changes.
@@ -34,6 +39,7 @@ foreach(l ${SUPPORT_SYSTEM_LIBS} ${WINDOWSMANIFEST_SYSTEM_LIBS})
3439
endif()
3540
endif()
3641
endforeach()
42+
3743
string(REPLACE ";" " " SYSTEM_LIBS "${SYSTEM_LIBS}")
3844

3945
# Fetch target specific compile options, e.g. RTTI option

0 commit comments

Comments
 (0)