Skip to content

Commit

Permalink
[CMake] Use llvm-config to locate Findzstd.cmake (apache#16032)
Browse files Browse the repository at this point in the history
* [CMake] Fallback for finding static zstd library from the system

LLVM17 now depends on `-lzstd` when the `--link-static` option is used.
I.e:
```
$ llvm-config-16 --link-static --system-libs
-lrt -ldl -lm -lz -ltinfo -lxml2

$ llvm-config-17 --link-static --system-libs
-lrt -ldl -lm -lz -lzstd -ltinfo -lxml2
```

The current cmake rules try to find a "Findzstd.cmake" file located
within the project, although this doesn't seem to exist, resulting in a
compilation error. This commit adds a fallback to search the system for
libzstd.a incase a "Findzstd.cmake" is not found. The zstd library is
already installed as part of: https://github.com/apache/tvm/pull/15799/files#diff-c2c0605a8fdd4f5600690a8c7b1ec769882426af1b0ed01e8aaa0814e3a8f5dbR48

Change-Id: I19ab168f92d23e98809851f948e2122345ed01f1

* Use llvm-config to locate Findzstd.cmake

Use llvm-config to find the location of the "Find*.cmake" files
and add this location to the cmake `CMAKE_MODULE_PATH` variable.
This allows the build to discover "Findzstd.cmake".

Change-Id: I3d25074fad3b2b8fa4c3d47e0e4c0b27d8739c65
  • Loading branch information
lhutton1 authored and binarybana committed Nov 14, 2023
1 parent 8a3706b commit 2472fe3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmake/utils/FindLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ macro(find_llvm use_llvm)
message(FATAL_ERROR "Fatal error executing: ${LLVM_CONFIG} --libdir")
endif()
message(STATUS "LLVM libdir: ${__llvm_libdir}")
execute_process(COMMAND ${LLVM_CONFIG} --cmakedir
RESULT_VARIABLE __llvm_exit_code
OUTPUT_VARIABLE __llvm_cmakedir
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(NOT "${__llvm_exit_code}" STREQUAL "0")
message(FATAL_ERROR "Fatal error executing: ${LLVM_CONFIG} --cmakedir")
endif()
message(STATUS "LLVM cmakedir: ${__llvm_cmakedir}")
# map prefix => $
# to handle the case when the prefix contains space.
string(REPLACE ${__llvm_prefix} "$" __llvm_cxxflags ${__llvm_cxxflags_space})
Expand Down Expand Up @@ -165,6 +173,7 @@ macro(find_llvm use_llvm)
find_package(ZLIB REQUIRED)
list(APPEND LLVM_LIBS "ZLIB::ZLIB")
elseif("${__flag}" STREQUAL "-lzstd" OR ("${__flag}" STREQUAL "zstd.dll.lib"))
list(APPEND CMAKE_MODULE_PATH "${__llvm_cmakedir}")
find_package(zstd REQUIRED)
if (TARGET "zstd::libzstd_static")
message(STATUS "LLVM links against static zstd")
Expand Down

0 comments on commit 2472fe3

Please sign in to comment.