Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CMake] Support LLVM-16 static linking #15164

Merged
merged 1 commit into from
Jul 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions cmake/utils/FindLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ macro(find_llvm use_llvm)
if(NOT "${__llvm_exit_code}" STREQUAL "0")
message(FATAL_ERROR "Fatal error executing: ${LLVM_CONFIG} --libdir")
endif()
message(STATUS "LLVM libdir: ${__llvm_libdir}")
# map prefix => $
# to handle the case when the prefix contains space.
string(REPLACE ${__llvm_prefix} "$" __llvm_cxxflags ${__llvm_cxxflags_space})
Expand Down Expand Up @@ -144,14 +145,33 @@ macro(find_llvm use_llvm)
endforeach()
separate_arguments(__llvm_system_libs)
foreach(__flag IN ITEMS ${__llvm_system_libs})
# If the library file ends in .lib try to
# also search the llvm_libdir
if(__flag MATCHES ".lib$")
if(EXISTS "${__llvm_libdir}/${__flag}")
set(__flag "${__llvm_libdir}/${__flag}")
if("${__flag}" STREQUAL "-lm")
message(STATUS "LLVM links against math")
list(APPEND LLVM_LIBS "m")
elseif(("${__flag}" STREQUAL "-lz") OR ("${__flag}" STREQUAL "z.lib"))
message(STATUS "LLVM links against zlib")
find_package(ZLIB REQUIRED)
list(APPEND LLVM_LIBS "ZLIB::ZLIB")
elseif("${__flag}" STREQUAL "-lzstd" OR ("${__flag}" STREQUAL "zstd.dll.lib"))
find_package(zstd REQUIRED)
if (TARGET "zstd::libzstd_static")
message(STATUS "LLVM links against static zstd")
list(APPEND LLVM_LIBS "zstd::libzstd_static")
else()
message(STATUS "LLVM links against shared zstd")
list(APPEND LLVM_LIBS "zstd::libzstd_shared")
endif()
elseif("${__flag}" STREQUAL "-lxml2")
message(STATUS "LLVM links against xml2")
list(APPEND LLVM_LIBS "-lxml2")
elseif((__flag MATCHES ".lib$") AND (EXISTS "${__llvm_libdir}/${__flag}"))
# If the library file ends in .lib try to also search the llvm_libdir
message(STATUS "LLVM linker flag under LLVM libdir: ${__llvm_libdir}/${__flag}")
list(APPEND LLVM_LIBS "${__llvm_libdir}/${__flag}")
else()
message(STATUS "LLVM linker flag: ${__flag}")
list(APPEND LLVM_LIBS "${__flag}")
endif()
list(APPEND LLVM_LIBS "${__flag}")
endforeach()
endif()
message(STATUS "Found LLVM_INCLUDE_DIRS=" "${LLVM_INCLUDE_DIRS}")
Expand Down
1 change: 1 addition & 0 deletions tests/scripts/task_config_build_minimal_cross_isa.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ if [ "$architecture_type" != "aarch64" ]; then
echo set\(CMAKE_FIND_ROOT_PATH /usr/aarch64-linux-gnu\) >> config.cmake
echo set\(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER\) >> config.cmake
echo set\(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY\) >> config.cmake
echo set\(ZLIB_LIBRARY /lib/aarch64-linux-gnu/libz.a\) >> config.cmake
else
# This usually runs in the ci_arm docker image.
echo -e 'find_program(LLVM_CONFIG "llvm-config")\nif (LLVM_CONFIG) \n\tset(USE_LLVM llvm-config) \nelse() \n\tset(USE_LLVM llvm-config-15)\nendif()' >> config.cmake
Expand Down
Loading