mirror of
https://github.com/ziglang/zig.git
synced 2024-11-14 16:13:24 +00:00
Merge pull request #12136 from topolarity/llvm-config-rework
CMake: Improve usage of `llvm-config` (esp. for consistent static/shared linking)
This commit is contained in:
commit
7a09bce232
@ -66,9 +66,9 @@ endif()
|
||||
message(STATUS "Configuring zig version ${ZIG_VERSION}")
|
||||
|
||||
set(ZIG_STATIC off CACHE BOOL "Attempt to build a static zig executable (not compatible with glibc)")
|
||||
set(ZIG_SHARED_LLVM off CACHE BOOL "Prefer linking against shared LLVM libraries")
|
||||
set(ZIG_STATIC_LLVM off CACHE BOOL "Prefer linking against static LLVM libraries")
|
||||
set(ZIG_STATIC_ZLIB off CACHE BOOL "Prefer linking against static zlib")
|
||||
set(ZIG_PREFER_CLANG_CPP_DYLIB off CACHE BOOL "Try to link against -lclang-cpp")
|
||||
set(ZIG_USE_CCACHE off CACHE BOOL "Use ccache if available")
|
||||
|
||||
if(CCACHE_PROGRAM AND ZIG_USE_CCACHE)
|
||||
@ -80,6 +80,10 @@ if(ZIG_STATIC)
|
||||
set(ZIG_STATIC_ZLIB ON)
|
||||
endif()
|
||||
|
||||
if (ZIG_SHARED_LLVM AND ZIG_STATIC_LLVM)
|
||||
message(SEND_ERROR "-DZIG_SHARED_LLVM and -DZIG_STATIC_LLVM cannot both be enabled simultaneously")
|
||||
endif()
|
||||
|
||||
string(REGEX REPLACE "\\\\" "\\\\\\\\" ZIG_LIBC_LIB_DIR_ESCAPED "${ZIG_LIBC_LIB_DIR}")
|
||||
string(REGEX REPLACE "\\\\" "\\\\\\\\" ZIG_LIBC_STATIC_LIB_DIR_ESCAPED "${ZIG_LIBC_STATIC_LIB_DIR}")
|
||||
string(REGEX REPLACE "\\\\" "\\\\\\\\" ZIG_LIBC_INCLUDE_DIR_ESCAPED "${ZIG_LIBC_INCLUDE_DIR}")
|
||||
|
@ -676,6 +676,7 @@ fn addCMakeLibraryList(exe: *std.build.LibExeObjStep, list: []const u8) void {
|
||||
}
|
||||
|
||||
const CMakeConfig = struct {
|
||||
llvm_linkage: std.build.LibExeObjStep.Linkage,
|
||||
cmake_binary_dir: []const u8,
|
||||
cmake_prefix_path: []const u8,
|
||||
cxx_compiler: []const u8,
|
||||
@ -714,6 +715,7 @@ fn findAndParseConfigH(b: *Builder, config_h_path_option: ?[]const u8) ?CMakeCon
|
||||
};
|
||||
|
||||
var ctx: CMakeConfig = .{
|
||||
.llvm_linkage = undefined,
|
||||
.cmake_binary_dir = undefined,
|
||||
.cmake_prefix_path = undefined,
|
||||
.cxx_compiler = undefined,
|
||||
@ -757,6 +759,7 @@ fn findAndParseConfigH(b: *Builder, config_h_path_option: ?[]const u8) ?CMakeCon
|
||||
.prefix = "#define ZIG_DIA_GUIDS_LIB ",
|
||||
.field = "dia_guids_lib",
|
||||
},
|
||||
// .prefix = ZIG_LLVM_LINK_MODE parsed manually below
|
||||
};
|
||||
|
||||
var lines_it = mem.tokenize(u8, config_h_text, "\r\n");
|
||||
@ -769,6 +772,12 @@ fn findAndParseConfigH(b: *Builder, config_h_path_option: ?[]const u8) ?CMakeCon
|
||||
@field(ctx, mapping.field) = toNativePathSep(b, quoted);
|
||||
}
|
||||
}
|
||||
if (mem.startsWith(u8, line, "#define ZIG_LLVM_LINK_MODE ")) {
|
||||
var it = mem.split(u8, line, "\"");
|
||||
_ = it.next().?; // skip the stuff before the quote
|
||||
const quoted = it.next().?; // the stuff inside the quote
|
||||
ctx.llvm_linkage = if (mem.eql(u8, quoted, "shared")) .dynamic else .static;
|
||||
}
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
|
@ -8,52 +8,33 @@
|
||||
# CLANG_LIBDIRS
|
||||
|
||||
find_path(CLANG_INCLUDE_DIRS NAMES clang/Frontend/ASTUnit.h
|
||||
PATHS
|
||||
/usr/lib/llvm/14/include
|
||||
/usr/lib/llvm-14/include
|
||||
/usr/lib/llvm-14.0/include
|
||||
/usr/local/llvm140/include
|
||||
/usr/local/llvm14/include
|
||||
/usr/local/opt/llvm@14/include
|
||||
/opt/homebrew/opt/llvm@14/include
|
||||
/mingw64/include
|
||||
HINTS ${LLVM_INCLUDE_DIRS}
|
||||
# Only look for Clang next to LLVM or in { CMAKE_PREFIX_PATH, CMAKE_LIBRARY_PATH, CMAKE_FRAMEWORK_PATH }
|
||||
NO_SYSTEM_ENVIRONMENT_PATH
|
||||
NO_CMAKE_SYSTEM_PATH
|
||||
)
|
||||
|
||||
if(ZIG_PREFER_CLANG_CPP_DYLIB)
|
||||
if(${LLVM_LINK_MODE} STREQUAL "shared")
|
||||
find_library(CLANG_LIBRARIES
|
||||
NAMES
|
||||
libclang-cpp.so.14
|
||||
clang-cpp-14.0
|
||||
clang-cpp140
|
||||
clang-cpp
|
||||
NAMES_PER_DIR
|
||||
PATHS
|
||||
${CLANG_LIBDIRS}
|
||||
/usr/lib/llvm/14/lib
|
||||
/usr/lib/llvm/14/lib64
|
||||
/usr/lib/llvm-14/lib
|
||||
/usr/local/llvm140/lib
|
||||
/usr/local/llvm14/lib
|
||||
/usr/local/opt/llvm@14/lib
|
||||
/opt/homebrew/opt/llvm@14/lib
|
||||
HINTS "${LLVM_LIBDIRS}"
|
||||
# Only look for Clang next to LLVM or in { CMAKE_PREFIX_PATH, CMAKE_LIBRARY_PATH, CMAKE_FRAMEWORK_PATH }
|
||||
NO_SYSTEM_ENVIRONMENT_PATH
|
||||
NO_CMAKE_SYSTEM_PATH
|
||||
)
|
||||
endif()
|
||||
|
||||
if(NOT CLANG_LIBRARIES)
|
||||
else()
|
||||
macro(FIND_AND_ADD_CLANG_LIB _libname_)
|
||||
string(TOUPPER ${_libname_} _prettylibname_)
|
||||
find_library(CLANG_${_prettylibname_}_LIB NAMES ${_libname_} NAMES_PER_DIR
|
||||
PATHS
|
||||
${CLANG_LIBDIRS}
|
||||
/usr/lib/llvm/14/lib
|
||||
/usr/lib/llvm-14/lib
|
||||
/usr/lib/llvm-14.0/lib
|
||||
/usr/local/llvm140/lib
|
||||
/usr/local/llvm14/lib
|
||||
/usr/local/opt/llvm@14/lib
|
||||
/opt/homebrew/opt/llvm@14/lib
|
||||
/mingw64/lib
|
||||
/c/msys64/mingw64/lib
|
||||
c:\\msys64\\mingw64\\lib
|
||||
HINTS "${LLVM_LIBDIRS}"
|
||||
# Only look for Clang next to LLVM or in { CMAKE_PREFIX_PATH, CMAKE_LIBRARY_PATH, CMAKE_FRAMEWORK_PATH }
|
||||
NO_SYSTEM_ENVIRONMENT_PATH
|
||||
NO_CMAKE_SYSTEM_PATH
|
||||
)
|
||||
if(CLANG_${_prettylibname_}_LIB)
|
||||
set(CLANG_LIBRARIES ${CLANG_LIBRARIES} ${CLANG_${_prettylibname_}_LIB})
|
||||
|
@ -7,6 +7,7 @@
|
||||
# LLD_LIBRARIES
|
||||
|
||||
find_path(LLD_INCLUDE_DIRS NAMES lld/Common/Driver.h
|
||||
HINTS ${LLVM_INCLUDE_DIRS}
|
||||
PATHS
|
||||
/usr/lib/llvm-14/include
|
||||
/usr/local/llvm140/include
|
||||
@ -16,6 +17,7 @@ find_path(LLD_INCLUDE_DIRS NAMES lld/Common/Driver.h
|
||||
/mingw64/include)
|
||||
|
||||
find_library(LLD_LIBRARY NAMES lld-14.0 lld140 lld NAMES_PER_DIR
|
||||
HINTS ${LLVM_LIBDIRS}
|
||||
PATHS
|
||||
/usr/lib/llvm-14/lib
|
||||
/usr/local/llvm140/lib
|
||||
@ -29,6 +31,7 @@ else()
|
||||
macro(FIND_AND_ADD_LLD_LIB _libname_)
|
||||
string(TOUPPER ${_libname_} _prettylibname_)
|
||||
find_library(LLD_${_prettylibname_}_LIB NAMES ${_libname_} NAMES_PER_DIR
|
||||
HINTS ${LLVM_LIBDIRS}
|
||||
PATHS
|
||||
${LLD_LIBDIRS}
|
||||
/usr/lib/llvm-14/lib
|
||||
@ -39,8 +42,8 @@ else()
|
||||
/mingw64/lib
|
||||
/c/msys64/mingw64/lib
|
||||
c:/msys64/mingw64/lib)
|
||||
if(LLD_${_prettylibname_}_LIB)
|
||||
set(LLD_LIBRARIES ${LLD_LIBRARIES} ${LLD_${_prettylibname_}_LIB})
|
||||
if(LLD_${_prettylibname_}_LIB)
|
||||
set(LLD_LIBRARIES ${LLD_LIBRARIES} ${LLD_${_prettylibname_}_LIB})
|
||||
endif()
|
||||
endmacro(FIND_AND_ADD_LLD_LIB)
|
||||
|
||||
|
@ -6,158 +6,147 @@
|
||||
# LLVM_INCLUDE_DIRS
|
||||
# LLVM_LIBRARIES
|
||||
# LLVM_LIBDIRS
|
||||
# LLVM_LINK_MODE
|
||||
|
||||
find_path(LLVM_INCLUDE_DIRS NAMES llvm/IR/IRBuilder.h
|
||||
PATHS
|
||||
/usr/lib/llvm/14/include
|
||||
/usr/lib/llvm-14/include
|
||||
/usr/lib/llvm-14.0/include
|
||||
/usr/lib/llvm14/include
|
||||
/usr/local/llvm14/include
|
||||
/usr/local/llvm140/include
|
||||
/usr/local/opt/llvm@14/include
|
||||
/opt/homebrew/opt/llvm@14/include
|
||||
/mingw64/include
|
||||
)
|
||||
|
||||
if(ZIG_PREFER_CLANG_CPP_DYLIB)
|
||||
find_library(LLVM_LIBRARIES
|
||||
NAMES
|
||||
LLVM-14.0
|
||||
LLVM-14
|
||||
LLVM-140
|
||||
LLVM
|
||||
NAMES_PER_DIR
|
||||
PATHS
|
||||
${LLVM_LIBDIRS}
|
||||
/usr/lib/llvm/14/lib
|
||||
/usr/lib/llvm/14/lib64
|
||||
/usr/lib/llvm-14/lib
|
||||
/usr/lib/llvm14/lib
|
||||
/usr/local/llvm14/lib
|
||||
/usr/local/llvm140/lib
|
||||
/usr/local/opt/llvm@14/lib
|
||||
/opt/homebrew/opt/llvm@14/lib
|
||||
)
|
||||
if(ZIG_USE_LLVM_CONFIG)
|
||||
while(1)
|
||||
unset(LLVM_CONFIG_EXE CACHE)
|
||||
find_program(LLVM_CONFIG_EXE
|
||||
NAMES llvm-config-14 llvm-config-14.0 llvm-config140 llvm-config14 llvm-config NAMES_PER_DIR
|
||||
PATHS
|
||||
"/mingw64/bin"
|
||||
"/c/msys64/mingw64/bin"
|
||||
"c:/msys64/mingw64/bin"
|
||||
"C:/Libraries/llvm-14.0.0/bin")
|
||||
|
||||
find_program(LLVM_CONFIG_EXE
|
||||
NAMES llvm-config-14 llvm-config-14.0 llvm-config140 llvm-config14 llvm-config NAMES_PER_DIR
|
||||
PATHS
|
||||
"/mingw64/bin"
|
||||
"/c/msys64/mingw64/bin"
|
||||
"c:/msys64/mingw64/bin"
|
||||
"C:/Libraries/llvm-14.0.0/bin")
|
||||
if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
|
||||
if (DEFINED LLVM_CONFIG_ERROR_MESSAGE)
|
||||
message(FATAL_ERROR ${LLVM_CONFIG_ERROR_MESSAGE})
|
||||
else()
|
||||
message(FATAL_ERROR "unable to find llvm-config")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
|
||||
message(FATAL_ERROR "unable to find llvm-config")
|
||||
endif()
|
||||
# Check that this LLVM is the right version
|
||||
execute_process(
|
||||
COMMAND ${LLVM_CONFIG_EXE} --version
|
||||
OUTPUT_VARIABLE LLVM_CONFIG_VERSION
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
|
||||
message(FATAL_ERROR "unable to find llvm-config")
|
||||
endif()
|
||||
get_filename_component(LLVM_CONFIG_DIR "${LLVM_CONFIG_EXE}" DIRECTORY)
|
||||
if("${LLVM_CONFIG_VERSION}" VERSION_LESS 14 OR "${LLVM_CONFIG_VERSION}" VERSION_EQUAL 15 OR "${LLVM_CONFIG_VERSION}" VERSION_GREATER 15)
|
||||
# Save the error message, in case this is the last llvm-config we find
|
||||
set(LLVM_CONFIG_ERROR_MESSAGE "expected LLVM 14.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
|
||||
|
||||
execute_process(
|
||||
COMMAND ${LLVM_CONFIG_EXE} --version
|
||||
OUTPUT_VARIABLE LLVM_CONFIG_VERSION
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
# Ignore this directory and try the search again
|
||||
list(APPEND CMAKE_IGNORE_PATH "${LLVM_CONFIG_DIR}")
|
||||
continue()
|
||||
endif()
|
||||
|
||||
if("${LLVM_CONFIG_VERSION}" VERSION_LESS 14)
|
||||
message(FATAL_ERROR "expected LLVM 14.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
|
||||
endif()
|
||||
if("${LLVM_CONFIG_VERSION}" VERSION_EQUAL 15)
|
||||
message(FATAL_ERROR "expected LLVM 14.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
|
||||
endif()
|
||||
if("${LLVM_CONFIG_VERSION}" VERSION_GREATER 15)
|
||||
message(FATAL_ERROR "expected LLVM 14.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
|
||||
endif()
|
||||
elseif(ZIG_USE_LLVM_CONFIG)
|
||||
find_program(LLVM_CONFIG_EXE
|
||||
NAMES llvm-config-14 llvm-config-14.0 llvm-config140 llvm-config14 llvm-config NAMES_PER_DIR
|
||||
PATHS
|
||||
"/mingw64/bin"
|
||||
"/c/msys64/mingw64/bin"
|
||||
"c:/msys64/mingw64/bin"
|
||||
"C:/Libraries/llvm-14.0.0/bin")
|
||||
# Check that this LLVM supports linking as a shared/static library, if requested
|
||||
if (ZIG_SHARED_LLVM OR ZIG_STATIC_LLVM)
|
||||
if (ZIG_SHARED_LLVM)
|
||||
set(STATIC_OR_SHARED_LINK "--link-shared")
|
||||
elseif (ZIG_STATIC_LLVM)
|
||||
set(STATIC_OR_SHARED_LINK "--link-static")
|
||||
endif()
|
||||
|
||||
if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
|
||||
message(FATAL_ERROR "unable to find llvm-config")
|
||||
endif()
|
||||
execute_process(
|
||||
COMMAND ${LLVM_CONFIG_EXE} --libs ${STATIC_OR_SHARED_LINK}
|
||||
OUTPUT_QUIET
|
||||
ERROR_VARIABLE LLVM_CONFIG_ERROR
|
||||
ERROR_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
|
||||
message(FATAL_ERROR "unable to find llvm-config")
|
||||
endif()
|
||||
if (LLVM_CONFIG_ERROR)
|
||||
# Save the error message, in case this is the last llvm-config we find
|
||||
if (ZIG_SHARED_LLVM)
|
||||
set(LLVM_CONFIG_ERROR_MESSAGE "LLVM 14.x found at ${LLVM_CONFIG_EXE} does not support linking as a shared library")
|
||||
else()
|
||||
set(LLVM_CONFIG_ERROR_MESSAGE "LLVM 14.x found at ${LLVM_CONFIG_EXE} does not support linking as a static library")
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND ${LLVM_CONFIG_EXE} --version
|
||||
OUTPUT_VARIABLE LLVM_CONFIG_VERSION
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
# Ignore this directory and try the search again
|
||||
list(APPEND CMAKE_IGNORE_PATH "${LLVM_CONFIG_DIR}")
|
||||
continue()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
if("${LLVM_CONFIG_VERSION}" VERSION_LESS 14)
|
||||
message(FATAL_ERROR "expected LLVM 14.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
|
||||
endif()
|
||||
if("${LLVM_CONFIG_VERSION}" VERSION_EQUAL 15)
|
||||
message(FATAL_ERROR "expected LLVM 14.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
|
||||
endif()
|
||||
if("${LLVM_CONFIG_VERSION}" VERSION_GREATER 15)
|
||||
message(FATAL_ERROR "expected LLVM 14.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
|
||||
endif()
|
||||
|
||||
execute_process(
|
||||
COMMAND ${LLVM_CONFIG_EXE} --targets-built
|
||||
OUTPUT_VARIABLE LLVM_TARGETS_BUILT_SPACES
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
string(REPLACE " " ";" LLVM_TARGETS_BUILT "${LLVM_TARGETS_BUILT_SPACES}")
|
||||
function(NEED_TARGET TARGET_NAME)
|
||||
execute_process(
|
||||
COMMAND ${LLVM_CONFIG_EXE} --targets-built
|
||||
OUTPUT_VARIABLE LLVM_TARGETS_BUILT_SPACES
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
string(REPLACE " " ";" LLVM_TARGETS_BUILT "${LLVM_TARGETS_BUILT_SPACES}")
|
||||
function(NEED_TARGET TARGET_NAME)
|
||||
list (FIND LLVM_TARGETS_BUILT "${TARGET_NAME}" _index)
|
||||
if (${_index} EQUAL -1)
|
||||
message(FATAL_ERROR "LLVM (according to ${LLVM_CONFIG_EXE}) is missing target ${TARGET_NAME}. Zig requires LLVM to be built with all default targets enabled.")
|
||||
endif()
|
||||
endfunction(NEED_TARGET)
|
||||
NEED_TARGET("AArch64")
|
||||
NEED_TARGET("AMDGPU")
|
||||
NEED_TARGET("ARM")
|
||||
NEED_TARGET("AVR")
|
||||
NEED_TARGET("BPF")
|
||||
NEED_TARGET("Hexagon")
|
||||
NEED_TARGET("Lanai")
|
||||
NEED_TARGET("Mips")
|
||||
NEED_TARGET("MSP430")
|
||||
NEED_TARGET("NVPTX")
|
||||
NEED_TARGET("PowerPC")
|
||||
NEED_TARGET("RISCV")
|
||||
NEED_TARGET("Sparc")
|
||||
NEED_TARGET("SystemZ")
|
||||
NEED_TARGET("VE")
|
||||
NEED_TARGET("WebAssembly")
|
||||
NEED_TARGET("X86")
|
||||
NEED_TARGET("XCore")
|
||||
# Save the error message, in case this is the last llvm-config we find
|
||||
set(LLVM_CONFIG_ERROR_MESSAGE "LLVM (according to ${LLVM_CONFIG_EXE}) is missing target ${TARGET_NAME}. Zig requires LLVM to be built with all default targets enabled.")
|
||||
|
||||
if(ZIG_STATIC_LLVM)
|
||||
# Ignore this directory and try the search again
|
||||
list(APPEND CMAKE_IGNORE_PATH "${LLVM_CONFIG_DIR}")
|
||||
continue()
|
||||
endif()
|
||||
endfunction(NEED_TARGET)
|
||||
NEED_TARGET("AArch64")
|
||||
NEED_TARGET("AMDGPU")
|
||||
NEED_TARGET("ARM")
|
||||
NEED_TARGET("AVR")
|
||||
NEED_TARGET("BPF")
|
||||
NEED_TARGET("Hexagon")
|
||||
NEED_TARGET("Lanai")
|
||||
NEED_TARGET("Mips")
|
||||
NEED_TARGET("MSP430")
|
||||
NEED_TARGET("NVPTX")
|
||||
NEED_TARGET("PowerPC")
|
||||
NEED_TARGET("RISCV")
|
||||
NEED_TARGET("Sparc")
|
||||
NEED_TARGET("SystemZ")
|
||||
NEED_TARGET("VE")
|
||||
NEED_TARGET("WebAssembly")
|
||||
NEED_TARGET("X86")
|
||||
NEED_TARGET("XCore")
|
||||
|
||||
# Got it!
|
||||
break()
|
||||
endwhile()
|
||||
|
||||
if(ZIG_SHARED_LLVM OR ZIG_STATIC_LLVM)
|
||||
execute_process(
|
||||
COMMAND ${LLVM_CONFIG_EXE} --libfiles --link-static
|
||||
COMMAND ${LLVM_CONFIG_EXE} --libfiles ${STATIC_OR_SHARED_LINK}
|
||||
OUTPUT_VARIABLE LLVM_LIBRARIES_SPACES
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
string(REPLACE " " ";" LLVM_LIBRARIES "${LLVM_LIBRARIES_SPACES}")
|
||||
|
||||
execute_process(
|
||||
COMMAND ${LLVM_CONFIG_EXE} --system-libs --link-static
|
||||
COMMAND ${LLVM_CONFIG_EXE} --libdir ${STATIC_OR_SHARED_LINK}
|
||||
OUTPUT_VARIABLE LLVM_LIBDIRS_SPACES
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
string(REPLACE " " ";" LLVM_LIBDIRS "${LLVM_LIBDIRS_SPACES}")
|
||||
|
||||
execute_process(
|
||||
COMMAND ${LLVM_CONFIG_EXE} --system-libs ${STATIC_OR_SHARED_LINK}
|
||||
OUTPUT_VARIABLE LLVM_SYSTEM_LIBS_SPACES
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
string(REPLACE " " ";" LLVM_SYSTEM_LIBS "${LLVM_SYSTEM_LIBS_SPACES}")
|
||||
|
||||
execute_process(
|
||||
COMMAND ${LLVM_CONFIG_EXE} --libdir --link-static
|
||||
OUTPUT_VARIABLE LLVM_LIBDIRS_SPACES
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
string(REPLACE " " ";" LLVM_LIBDIRS "${LLVM_LIBDIRS_SPACES}")
|
||||
endif()
|
||||
if(NOT LLVM_LIBRARIES)
|
||||
COMMAND ${LLVM_CONFIG_EXE} --shared-mode ${STATIC_OR_SHARED_LINK}
|
||||
OUTPUT_VARIABLE LLVM_LINK_MODE
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
else()
|
||||
execute_process(
|
||||
COMMAND ${LLVM_CONFIG_EXE} --libs
|
||||
OUTPUT_VARIABLE LLVM_LIBRARIES_SPACES
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
string(REPLACE " " ";" LLVM_LIBRARIES "${LLVM_LIBRARIES_SPACES}")
|
||||
|
||||
execute_process(
|
||||
COMMAND ${LLVM_CONFIG_EXE} --libdir
|
||||
OUTPUT_VARIABLE LLVM_LIBDIRS_SPACES
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
string(REPLACE " " ";" LLVM_LIBDIRS "${LLVM_LIBDIRS_SPACES}")
|
||||
|
||||
execute_process(
|
||||
COMMAND ${LLVM_CONFIG_EXE} --system-libs
|
||||
OUTPUT_VARIABLE LLVM_SYSTEM_LIBS_SPACES
|
||||
@ -165,17 +154,32 @@ elseif(ZIG_USE_LLVM_CONFIG)
|
||||
string(REPLACE " " ";" LLVM_SYSTEM_LIBS "${LLVM_SYSTEM_LIBS_SPACES}")
|
||||
|
||||
execute_process(
|
||||
COMMAND ${LLVM_CONFIG_EXE} --libdir
|
||||
OUTPUT_VARIABLE LLVM_LIBDIRS_SPACES
|
||||
COMMAND ${LLVM_CONFIG_EXE} --shared-mode
|
||||
OUTPUT_VARIABLE LLVM_LINK_MODE
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
endif()
|
||||
|
||||
if (${LLVM_LINK_MODE} STREQUAL "shared")
|
||||
# We always ask for the system libs corresponding to static linking,
|
||||
# since on some distros LLD is only available as a static library
|
||||
# and we need these libraries to link it successfully
|
||||
execute_process(
|
||||
COMMAND ${LLVM_CONFIG_EXE} --system-libs --link-static
|
||||
OUTPUT_VARIABLE LLVM_STATIC_SYSTEM_LIBS_SPACES
|
||||
ERROR_QUIET # Some installations have no static libs, we just ignore the failure
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
string(REPLACE " " ";" LLVM_LIBDIRS "${LLVM_LIBDIRS_SPACES}")
|
||||
string(REPLACE " " ";" LLVM_STATIC_SYSTEM_LIBS "${LLVM_STATIC_SYSTEM_LIBS_SPACES}")
|
||||
|
||||
set(LLVM_LIBRARIES ${LLVM_LIBRARIES} ${LLVM_SYSTEM_LIBS} ${LLVM_STATIC_SYSTEM_LIBS})
|
||||
else()
|
||||
set(LLVM_LIBRARIES ${LLVM_LIBRARIES} ${LLVM_SYSTEM_LIBS})
|
||||
endif()
|
||||
|
||||
set(LLVM_LIBRARIES ${LLVM_LIBRARIES} ${LLVM_SYSTEM_LIBS})
|
||||
|
||||
if(NOT LLVM_LIBRARIES)
|
||||
find_library(LLVM_LIBRARIES NAMES LLVM LLVM-14 LLVM-14.0 NAMES_PER_DIR)
|
||||
endif()
|
||||
execute_process(
|
||||
COMMAND ${LLVM_CONFIG_EXE} --includedir
|
||||
OUTPUT_VARIABLE LLVM_INCLUDE_DIRS_SPACES
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
string(REPLACE " " ";" LLVM_INCLUDE_DIRS "${LLVM_INCLUDE_DIRS_SPACES}")
|
||||
|
||||
link_directories("${CMAKE_PREFIX_PATH}/lib")
|
||||
link_directories("${LLVM_LIBDIRS}")
|
||||
@ -185,10 +189,13 @@ else()
|
||||
|
||||
macro(FIND_AND_ADD_LLVM_LIB _libname_)
|
||||
string(TOUPPER ${_libname_} _prettylibname_)
|
||||
find_library(LLVM_${_prettylibname_}_LIB NAMES ${_libname_} NAMES_PER_DIR PATHS ${LLVM_LIBDIRS})
|
||||
find_library(LLVM_${_prettylibname_}_LIB
|
||||
NAMES ${_libname_} NAMES_PER_DIR)
|
||||
set(LLVM_LIBRARIES ${LLVM_LIBRARIES} ${LLVM_${_prettylibname_}_LIB})
|
||||
endmacro(FIND_AND_ADD_LLVM_LIB)
|
||||
|
||||
set(LLVM_LINK_MODE "static")
|
||||
|
||||
# This list can be re-generated with `llvm-config --libfiles` and then
|
||||
# reformatting using your favorite text editor. Note we do not execute
|
||||
# `llvm-config` here because we are cross compiling.
|
||||
@ -352,6 +359,9 @@ else()
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMBinaryFormat)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMSupport)
|
||||
FIND_AND_ADD_LLVM_LIB(LLVMDemangle)
|
||||
|
||||
get_filename_component(LLVM_LIBDIRS "${LLVM_LLVMCORE_LIB}" DIRECTORY)
|
||||
find_path(LLVM_INCLUDE_DIRS NAMES llvm/IR/IRBuilder.h)
|
||||
endif()
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
// Used by build.zig for communicating build information to self hosted build.
|
||||
#define ZIG_CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@"
|
||||
#define ZIG_LLVM_LINK_MODE "@LLVM_LINK_MODE@"
|
||||
#define ZIG_CMAKE_PREFIX_PATH "@CMAKE_PREFIX_PATH@"
|
||||
#define ZIG_CXX_COMPILER "@CMAKE_CXX_COMPILER@"
|
||||
#define ZIG_LLD_INCLUDE_PATH "@LLD_INCLUDE_DIRS@"
|
||||
|
Loading…
Reference in New Issue
Block a user