@@ -48,27 +48,73 @@ toolchain("llvm")
4848 toolchain :add (" runtimes" , " MT" , " MTd" , " MD" , " MDd" )
4949 end
5050
51- -- add march flags
52- local march
51+ -- add target flags
52+ local target
5353 if toolchain :is_plat (" windows" ) and not is_host (" windows" ) then
54- -- cross-compilation for windows
5554 if toolchain :is_arch (" i386" , " x86" ) then
56- march = " -target i386-pc-windows-msvc"
55+ target = " i386-pc-windows-msvc"
5756 else
58- march = " -target x86_64-pc-windows-msvc"
57+ target = " x86_64-pc-windows-msvc"
5958 end
60- toolchain :add (" ldflags" , " -fuse-ld=lld" )
61- toolchain :add (" shflags" , " -fuse-ld=lld" )
59+ elseif toolchain :is_plat (" macosx" ) then
60+ local arch = toolchain :arch ()
61+ local target_minver = toolchain :config (" target_minver" )
62+ local appledev = toolchain :config (" appledev" )
63+ if target_minver then
64+ target = (" %s-apple-macos%s" ):format (arch , target_minver )
65+ if appledev == " catalyst" then
66+ target = (" %s-apple-ios%s-macabi" ):format (arch , target_minver )
67+ end
68+ end
69+ elseif toolchain :is_plat (" cross" ) then
70+ target = toolchain :cross ():gsub (" (.*)%-$" , " %1" )
71+ end
72+ local target_flags
73+ if target then
74+ target_flags = " --target=" .. target
6275 elseif toolchain :is_arch (" x86_64" , " x64" ) then
63- march = " -m64"
76+ target_flags = " -m64"
6477 elseif toolchain :is_arch (" i386" , " x86" ) then
65- march = " -m32"
78+ target_flags = " -m32"
79+ end
80+ if target_flags then
81+ toolchain :add (" cxflags" , target_flags )
82+ toolchain :add (" mxflags" , target_flags )
83+ toolchain :add (" asflags" , target_flags )
84+ toolchain :add (" ldflags" , target_flags )
85+ toolchain :add (" shflags" , target_flags )
86+ end
87+
88+ -- init flags for platform
89+ if toolchain :is_plat (" windows" ) and not is_host (" windows" ) then
90+ toolchain :add (" ldflags" , " -fuse-ld=lld" )
91+ toolchain :add (" shflags" , " -fuse-ld=lld" )
92+ elseif toolchain :is_plat (" macosx" ) then
93+ local xcode_dir = get_config (" xcode" )
94+ local xcode_sdkver = toolchain :config (" xcode_sdkver" )
95+ local xcode_sdkdir = nil
96+ if xcode_dir and xcode_sdkver then
97+ xcode_sdkdir = xcode_dir .. " /Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. xcode_sdkver .. " .sdk"
98+ toolchain :add (" cxflags" , {" -isysroot" , xcode_sdkdir })
99+ toolchain :add (" mxflags" , {" -isysroot" , xcode_sdkdir })
100+ toolchain :add (" ldflags" , {" -isysroot" , xcode_sdkdir })
101+ toolchain :add (" shflags" , {" -isysroot" , xcode_sdkdir })
102+ else
103+ -- @see https://github.com/xmake-io/xmake/issues/1179
104+ local macsdk = " /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"
105+ if os.exists (macsdk ) then
106+ toolchain :add (" cxflags" , {" -isysroot" , macsdk })
107+ toolchain :add (" mxflags" , {" -isysroot" , macsdk })
108+ toolchain :add (" ldflags" , {" -isysroot" , macsdk })
109+ toolchain :add (" shflags" , {" -isysroot" , macsdk })
110+ end
111+ end
112+ toolchain :add (" mxflags" , " -fobjc-arc" )
66113 elseif toolchain :is_plat (" cross" ) then
67114 local sysroot
68115 local sdkdir = toolchain :sdkdir ()
69116 local bindir = toolchain :bindir ()
70117 local cross = toolchain :cross ():gsub (" (.*)%-$" , " %1" )
71- march = " --target=" .. cross
72118 if bindir and os .isexec (path.join (bindir , cross .. " -gcc" .. (is_host (" windows" ) and " .exe" or " " ))) then
73119 local gcc_toolchain = path.directory (bindir )
74120 toolchain :add (" cxflags" , " --gcc-toolchain=" .. gcc_toolchain )
@@ -91,41 +137,11 @@ toolchain("llvm")
91137 toolchain :add (" shflags" , " --sysroot=" .. sysroot )
92138 end
93139 end
94- if march then
95- toolchain :add (" cxflags" , march )
96- toolchain :add (" mxflags" , march )
97- toolchain :add (" asflags" , march )
98- toolchain :add (" ldflags" , march )
99- toolchain :add (" shflags" , march )
100- end
101-
102- -- init flags for macOS
103- if toolchain :is_plat (" macosx" ) then
104- local xcode_dir = get_config (" xcode" )
105- local xcode_sdkver = toolchain :config (" xcode_sdkver" )
106- local xcode_sdkdir = nil
107- if xcode_dir and xcode_sdkver then
108- xcode_sdkdir = xcode_dir .. " /Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX" .. xcode_sdkver .. " .sdk"
109- toolchain :add (" cxflags" , {" -isysroot" , xcode_sdkdir })
110- toolchain :add (" mxflags" , {" -isysroot" , xcode_sdkdir })
111- toolchain :add (" ldflags" , {" -isysroot" , xcode_sdkdir })
112- toolchain :add (" shflags" , {" -isysroot" , xcode_sdkdir })
113- else
114- -- @see https://github.com/xmake-io/xmake/issues/1179
115- local macsdk = " /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk"
116- if os.exists (macsdk ) then
117- toolchain :add (" cxflags" , {" -isysroot" , macsdk })
118- toolchain :add (" mxflags" , {" -isysroot" , macsdk })
119- toolchain :add (" ldflags" , {" -isysroot" , macsdk })
120- toolchain :add (" shflags" , {" -isysroot" , macsdk })
121- end
122- end
123- toolchain :add (" mxflags" , " -fobjc-arc" )
124- end
125140
126141 -- add bin search library for loading some dependent .dll files windows
127142 local bindir = toolchain :bindir ()
128143 if bindir and is_host (" windows" ) then
129144 toolchain :add (" runenvs" , " PATH" , bindir )
130145 end
131146 end )
147+
0 commit comments