Skip to content

Commit

Permalink
tweak zstd behavior in cmake and llvm config for better testing
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
ckissane authored and tru committed Oct 4, 2022
1 parent 67ac047 commit 55d4d86
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
2 changes: 2 additions & 0 deletions llvm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,8 @@ set(LLVM_ENABLE_ZLIB "ON" CACHE STRING "Use zlib for compression/decompression i

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

set(LLVM_PREFER_STATIC_ZSTD TRUE CACHE BOOL "Use static version of zstd if available. Can be TRUE, FALSE")

set(LLVM_ENABLE_CURL "OFF" CACHE STRING "Use libcurl for the HTTP client if available. Can be ON, OFF, or FORCE_ON")

set(LLVM_ENABLE_HTTPLIB "OFF" CACHE STRING "Use cpp-httplib HTTP server library if available. Can be ON, OFF, or FORCE_ON")
Expand Down
1 change: 0 additions & 1 deletion llvm/cmake/modules/LLVMConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ endif()

set(LLVM_ENABLE_ZSTD @LLVM_ENABLE_ZSTD@)
if(LLVM_ENABLE_ZSTD)
set(zstd_ROOT @zstd_ROOT@)
find_package(zstd)
endif()

Expand Down
27 changes: 23 additions & 4 deletions llvm/lib/Support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,29 @@ if (HAS_WERROR_GLOBAL_CTORS)
endif()

if(LLVM_ENABLE_ZLIB)
set(imported_libs ZLIB::ZLIB)
list(APPEND imported_libs ZLIB::ZLIB)
endif()

set(zstd_target none)

if(LLVM_ENABLE_ZSTD)
if(LLVM_PREFER_STATIC_ZSTD)
if(TARGET zstd::libzstd_static)
set(zstd_target zstd::libzstd_static)
else()
set(zstd_target zstd::libzstd_shared)
endif()
else()
if(TARGET zstd::libzstd_shared)
set(zstd_target zstd::libzstd_shared)
else()
set(zstd_target zstd::libzstd_static)
endif()
endif()
endif()

if(LLVM_ENABLE_ZSTD)
list(APPEND imported_libs zstd::libzstd_shared)
list(APPEND imported_libs ${zstd_target})
endif()

if( MSVC OR MINGW )
Expand Down Expand Up @@ -300,11 +318,12 @@ if(LLVM_ENABLE_ZSTD)
# CMAKE_BUILD_TYPE is only meaningful to single-configuration generators.
if(CMAKE_BUILD_TYPE)
string(TOUPPER ${CMAKE_BUILD_TYPE} build_type)
get_property(zstd_library TARGET zstd::libzstd_shared PROPERTY LOCATION_${build_type})
get_property(zstd_library TARGET ${zstd_target} PROPERTY LOCATION_${build_type})
endif()
if(NOT zstd_library)
get_property(zstd_library TARGET zstd::libzstd_shared PROPERTY LOCATION)
get_property(zstd_library TARGET ${zstd_target} PROPERTY LOCATION)
endif()
get_library_name(${zstd_library} zstd_library)
set(llvm_system_libs ${llvm_system_libs} "${zstd_library}")
endif()

Expand Down
8 changes: 7 additions & 1 deletion llvm/tools/llvm-config/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ add_llvm_tool(llvm-config
# Compute the substitution values for various items.
get_property(SUPPORT_SYSTEM_LIBS TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS)
get_property(WINDOWSMANIFEST_SYSTEM_LIBS TARGET LLVMWindowsManifest PROPERTY LLVM_SYSTEM_LIBS)

foreach(l ${SUPPORT_SYSTEM_LIBS} ${WINDOWSMANIFEST_SYSTEM_LIBS})
if(MSVC)
set(SYSTEM_LIBS ${SYSTEM_LIBS} "${l}.lib")
if(IS_ABSOLUTE ${l})
set(SYSTEM_LIBS ${SYSTEM_LIBS} "${l}")
else()
set(SYSTEM_LIBS ${SYSTEM_LIBS} "${l}.lib")
endif()
else()
if (l MATCHES "^-")
# If it's an option, pass it without changes.
Expand All @@ -34,6 +39,7 @@ foreach(l ${SUPPORT_SYSTEM_LIBS} ${WINDOWSMANIFEST_SYSTEM_LIBS})
endif()
endif()
endforeach()

string(REPLACE ";" " " SYSTEM_LIBS "${SYSTEM_LIBS}")

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

0 comments on commit 55d4d86

Please sign in to comment.