This is an automated email from the ASF dual-hosted git repository.
junrushao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/main by this push:
new 3b8d1a831d [CMake] Use llvm-config to locate Findzstd.cmake (#16032)
3b8d1a831d is described below
commit 3b8d1a831dca3c9165168365e7e77c4e7f6746c9
Author: Luke Hutton <[email protected]>
AuthorDate: Fri Nov 3 19:54:18 2023 +0000
[CMake] Use llvm-config to locate Findzstd.cmake (#16032)
* [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
---
cmake/utils/FindLLVM.cmake | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/cmake/utils/FindLLVM.cmake b/cmake/utils/FindLLVM.cmake
index f40d97d9ba..fe236e299c 100644
--- a/cmake/utils/FindLLVM.cmake
+++ b/cmake/utils/FindLLVM.cmake
@@ -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})
@@ -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")