build: simplify llvm-config provided system library parsing

- Revert the addition of CLANG_SYSTEM_LIBARIES and LLVM_SYSTEM_LIBRARIES
- Change addCMakeLibraryList to parse non-absolute path .lib dependencies as system libraries
This commit is contained in:
kcbanner 2023-01-04 02:18:51 -05:00
parent f5135f8e3b
commit 3cacbea95b
5 changed files with 11 additions and 49 deletions

View File

@ -133,9 +133,9 @@ find_package(lld 15)
if(ZIG_STATIC_ZLIB)
if (MSVC)
list(REMOVE_ITEM LLVM_SYSTEM_LIBRARIES "z.lib")
list(REMOVE_ITEM LLVM_LIBRARIES "z.lib")
else()
list(REMOVE_ITEM LLVM_SYSTEM_LIBRARIES "-lz")
list(REMOVE_ITEM LLVM_LIBRARIES "-lz")
endif()
find_library(ZLIB NAMES libz.a libzlibstatic.a z zlib libz NAMES_PER_DIR)
@ -144,9 +144,9 @@ endif()
if(ZIG_STATIC_ZSTD)
if (MSVC)
list(REMOVE_ITEM LLVM_SYSTEM_LIBRARIES "zstd.lib")
list(REMOVE_ITEM LLVM_LIBRARIES "zstd.lib")
else()
list(REMOVE_ITEM LLVM_SYSTEM_LIBRARIES "-lzstd")
list(REMOVE_ITEM LLVM_LIBRARIES "-lzstd")
endif()
find_library(ZSTD NAMES libzstd.a libzstdstatic.a zstd NAMES_PER_DIR)
@ -154,7 +154,7 @@ if(ZIG_STATIC_ZSTD)
endif()
if(APPLE AND ZIG_STATIC)
list(REMOVE_ITEM LLVM_SYSTEM_LIBRARIES "-lcurses")
list(REMOVE_ITEM LLVM_LIBRARIES "-lcurses")
find_library(CURSES NAMES libcurses.a libncurses.a NAMES_PER_DIR
PATHS
/usr/local/opt/ncurses/lib
@ -710,7 +710,6 @@ target_link_libraries(zigcpp LINK_PUBLIC
${CLANG_LIBRARIES}
${LLD_LIBRARIES}
${LLVM_LIBRARIES}
${LLVM_SYSTEM_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)

View File

@ -552,8 +552,6 @@ fn addCmakeCfgOptionsToExe(
addCMakeLibraryList(exe, cfg.clang_libraries);
addCMakeLibraryList(exe, cfg.lld_libraries);
addCMakeLibraryList(exe, cfg.llvm_libraries);
addCMakeSystemLibraryList(exe, cfg.clang_system_libraries);
addCMakeSystemLibraryList(exe, cfg.llvm_system_libraries);
if (use_zig_libcxx) {
exe.linkLibCpp();
@ -683,29 +681,14 @@ fn addCMakeLibraryList(exe: *std.build.LibExeObjStep, list: []const u8) void {
while (it.next()) |lib| {
if (mem.startsWith(u8, lib, "-l")) {
exe.linkSystemLibrary(lib["-l".len..]);
} else if (exe.target.isWindows() and mem.endsWith(u8, lib, ".lib") and !fs.path.isAbsolute(lib)) {
exe.linkSystemLibrary(lib[0 .. lib.len - ".lib".len]);
} else {
exe.addObjectFile(lib);
}
}
}
fn addCMakeSystemLibraryList(exe: *std.build.LibExeObjStep, list: []const u8) void {
var it = mem.tokenize(u8, list, ";");
while (it.next()) |lib| {
var start_offset: usize = 0;
var end_offset: usize = 0;
if (mem.startsWith(u8, lib, "-l")) {
start_offset = "-l".len;
}
if (exe.target.isWindows() and mem.endsWith(u8, lib, ".lib")) {
end_offset = ".lib".len;
}
exe.linkSystemLibrary(lib[start_offset .. lib.len - end_offset]);
}
}
const CMakeConfig = struct {
llvm_linkage: std.build.LibExeObjStep.Linkage,
cmake_binary_dir: []const u8,
@ -716,11 +699,9 @@ const CMakeConfig = struct {
lld_include_dir: []const u8,
lld_libraries: []const u8,
clang_libraries: []const u8,
clang_system_libraries: []const u8,
llvm_lib_dir: []const u8,
llvm_include_dir: []const u8,
llvm_libraries: []const u8,
llvm_system_libraries: []const u8,
dia_guids_lib: []const u8,
};
@ -783,11 +764,9 @@ fn parseConfigH(b: *Builder, config_h_text: []const u8) ?CMakeConfig {
.lld_include_dir = undefined,
.lld_libraries = undefined,
.clang_libraries = undefined,
.clang_system_libraries = undefined,
.llvm_lib_dir = undefined,
.llvm_include_dir = undefined,
.llvm_libraries = undefined,
.llvm_system_libraries = undefined,
.dia_guids_lib = undefined,
};
@ -824,18 +803,10 @@ fn parseConfigH(b: *Builder, config_h_text: []const u8) ?CMakeConfig {
.prefix = "#define ZIG_CLANG_LIBRARIES ",
.field = "clang_libraries",
},
.{
.prefix = "#define ZIG_CLANG_SYSTEM_LIBRARIES ",
.field = "clang_system_libraries",
},
.{
.prefix = "#define ZIG_LLVM_LIBRARIES ",
.field = "llvm_libraries",
},
.{
.prefix = "#define ZIG_LLVM_SYSTEM_LIBRARIES ",
.field = "llvm_system_libraries",
},
.{
.prefix = "#define ZIG_DIA_GUIDS_LIB ",
.field = "dia_guids_lib",

View File

@ -5,7 +5,6 @@
# CLANG_FOUND
# CLANG_INCLUDE_DIRS
# CLANG_LIBRARIES
# CLANG_SYSTEM_LIBRARIES
# CLANG_LIBDIRS
find_path(CLANG_INCLUDE_DIRS NAMES clang/Frontend/ASTUnit.h
@ -70,7 +69,7 @@ else()
endif()
if (MSVC)
set(CLANG_SYSTEM_LIBRARIES "version.lib")
set(CLANG_LIBRARIES ${CLANG_LIBRARIES} "version.lib")
endif()
include(FindPackageHandleStandardArgs)

View File

@ -5,7 +5,6 @@
# LLVM_FOUND
# LLVM_INCLUDE_DIRS
# LLVM_LIBRARIES
# LLVM_SYSTEM_LIBRARIES
# LLVM_LIBDIRS
# LLVM_LINK_MODE
@ -173,9 +172,9 @@ if(ZIG_USE_LLVM_CONFIG)
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE " " ";" LLVM_STATIC_SYSTEM_LIBS "${LLVM_STATIC_SYSTEM_LIBS_SPACES}")
set(LLVM_SYSTEM_LIBRARIES ${LLVM_SYSTEM_LIBS} ${LLVM_STATIC_SYSTEM_LIBS})
set(LLVM_LIBRARIES ${LLVM_LIBRARIES} ${LLVM_SYSTEM_LIBS} ${LLVM_STATIC_SYSTEM_LIBS})
else()
set(LLVM_SYSTEM_LIBRARIES ${LLVM_SYSTEM_LIBS})
set(LLVM_LIBRARIES ${LLVM_LIBRARIES} ${LLVM_SYSTEM_LIBS})
endif()
execute_process(
@ -370,11 +369,7 @@ else()
find_path(LLVM_INCLUDE_DIRS NAMES llvm/IR/IRBuilder.h)
endif()
if(NOT LLVM_SYSTEM_LIBRARIES)
set(LLVM_SYSTEM_LIBRARIES "")
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(llvm DEFAULT_MSG LLVM_LIBRARIES LLVM_INCLUDE_DIRS)
mark_as_advanced(LLVM_INCLUDE_DIRS LLVM_LIBRARIES LLVM_SYSTEM_LIBRARIES LLVM_LIBDIRS)
mark_as_advanced(LLVM_INCLUDE_DIRS LLVM_LIBRARIES LLVM_LIBDIRS)

View File

@ -16,7 +16,6 @@
// Used by build.zig for communicating build information to self hosted build.
#define ZIG_CLANG_LIBRARIES "@CLANG_LIBRARIES@"
#define ZIG_CLANG_SYSTEM_LIBRARIES "@CLANG_SYSTEM_LIBRARIES@"
#define ZIG_CMAKE_BINARY_DIR "@CMAKE_BINARY_DIR@"
#define ZIG_CMAKE_PREFIX_PATH "@ZIG_CMAKE_PREFIX_PATH@"
#define ZIG_CMAKE_STATIC_LIBRARY_PREFIX "@CMAKE_STATIC_LIBRARY_PREFIX@"
@ -29,6 +28,5 @@
#define ZIG_LLVM_LIBRARIES "@LLVM_LIBRARIES@"
#define ZIG_LLVM_LIB_PATH "@LLVM_LIBDIRS@"
#define ZIG_LLVM_LINK_MODE "@LLVM_LINK_MODE@"
#define ZIG_LLVM_SYSTEM_LIBRARIES "@LLVM_SYSTEM_LIBRARIES@"
#endif