@@ -552,6 +552,7 @@ fn addCmakeCfgOptionsToExe(
552552 addCMakeLibraryList (exe , cfg .clang_libraries );
553553 addCMakeLibraryList (exe , cfg .lld_libraries );
554554 addCMakeLibraryList (exe , cfg .llvm_libraries );
555+ addCMakeSystemLibraryList (exe , cfg .llvm_system_libraries );
555556
556557 if (use_zig_libcxx ) {
557558 exe .linkLibCpp ();
@@ -679,6 +680,23 @@ fn addCMakeLibraryList(exe: *std.build.LibExeObjStep, list: []const u8) void {
679680 }
680681}
681682
683+ fn addCMakeSystemLibraryList (exe : * std.build.LibExeObjStep , list : []const u8 ) void {
684+ var it = mem .tokenize (u8 , list , ";" );
685+ while (it .next ()) | lib | {
686+ var start_offset : usize = 0 ;
687+ var end_offset : usize = 0 ;
688+ if (mem .startsWith (u8 , lib , "-l" )) {
689+ start_offset = "-l" .len ;
690+ }
691+
692+ if (exe .target .isWindows () and mem .endsWith (u8 , lib , ".lib" )) {
693+ end_offset = ".lib" .len ;
694+ }
695+
696+ exe .linkSystemLibrary (lib [start_offset .. lib .len - end_offset ]);
697+ }
698+ }
699+
682700const CMakeConfig = struct {
683701 llvm_linkage : std.build.LibExeObjStep.Linkage ,
684702 cmake_binary_dir : []const u8 ,
@@ -692,6 +710,7 @@ const CMakeConfig = struct {
692710 llvm_lib_dir : []const u8 ,
693711 llvm_include_dir : []const u8 ,
694712 llvm_libraries : []const u8 ,
713+ llvm_system_libraries : []const u8 ,
695714 dia_guids_lib : []const u8 ,
696715};
697716
@@ -757,6 +776,7 @@ fn parseConfigH(b: *Builder, config_h_text: []const u8) ?CMakeConfig {
757776 .llvm_lib_dir = undefined ,
758777 .llvm_include_dir = undefined ,
759778 .llvm_libraries = undefined ,
779+ .llvm_system_libraries = undefined ,
760780 .dia_guids_lib = undefined ,
761781 };
762782
@@ -797,6 +817,10 @@ fn parseConfigH(b: *Builder, config_h_text: []const u8) ?CMakeConfig {
797817 .prefix = "#define ZIG_LLVM_LIBRARIES " ,
798818 .field = "llvm_libraries" ,
799819 },
820+ .{
821+ .prefix = "#define ZIG_LLVM_SYSTEM_LIBRARIES " ,
822+ .field = "llvm_system_libraries" ,
823+ },
800824 .{
801825 .prefix = "#define ZIG_DIA_GUIDS_LIB " ,
802826 .field = "dia_guids_lib" ,
0 commit comments