@@ -27,12 +27,261 @@ static ::cl::opt<String> build_binary_dir("B", ::cl::desc("Explicitly specify a
2727
2828static ::cl::opt<bool > build_fetch (" fetch" , ::cl::desc(" Fetch sources, then build" ), ::cl::sub(subcommand_build));
2929
30+ // //////////////////////////////////////////////////////////////////////////////
31+ //
32+ // build configs
33+ //
34+ // //////////////////////////////////////////////////////////////////////////////
35+
36+ // static cl::opt<bool> append_configs("append-configs", cl::desc("Append configs for generation"));
37+
38+ static cl::list<String> libc (" libc" , cl::CommaSeparated);
39+ static cl::list<String> libcpp (" libcpp" , cl::CommaSeparated);
40+ static cl::list<String> target_os (" target-os" , cl::CommaSeparated);
41+ static cl::list<String> compiler (" compiler" , cl::desc(" Set compiler" ), cl::CommaSeparated);
42+ static cl::list<String> configuration (" configuration" , cl::desc(" Set build configuration" ), cl::CommaSeparated);
43+ cl::alias configuration2 (" config" , cl::desc(" Alias for -configuration" ), cl::aliasopt(configuration));
44+ static cl::list<String> platform (" platform" , cl::desc(" Set build platform" ), cl::CommaSeparated);
45+ // static cl::opt<String> arch("arch", cl::desc("Set arch")/*, cl::sub(subcommand_ide)*/);
46+
47+ // static/shared
48+ static cl::opt<bool > static_build (" static-build" , cl::desc(" Set static build" ));
49+ cl::alias static_build2 (" static" , cl::desc(" Alias for -static-build" ), cl::aliasopt(static_build));
50+ static cl::opt<bool > shared_build (" shared-build" , cl::desc(" Set shared build (default)" ));
51+ cl::alias shared_build2 (" shared" , cl::desc(" Alias for -shared-build" ), cl::aliasopt(shared_build));
52+
53+ // mt/md
54+ static cl::opt<bool > win_mt (" win-mt" , cl::desc(" Set /MT build" ));
55+ cl::alias win_mt2 (" mt" , cl::desc(" Alias for -win-mt" ), cl::aliasopt(win_mt));
56+ static cl::opt<bool > win_md (" win-md" , cl::desc(" Set /MD build (default)" ));
57+ cl::alias win_md2 (" md" , cl::desc(" Alias for -win-md" ), cl::aliasopt(win_md));
58+
59+ // //////////////////////////////////////////////////////////////////////////////
60+
3061SUBCOMMAND_DECL (build)
3162{
3263 auto swctx = createSwContext ();
3364 cli_build (*swctx);
3465}
3566
67+ static bool hasAnyUserProvidedInformation ()
68+ {
69+ return 0
70+ || !configuration.empty ()
71+ || static_build
72+ || shared_build
73+ || win_mt
74+ || win_md
75+ || !platform.empty ()
76+ || !compiler.empty ()
77+ || !target_os.empty ()
78+ || !libc.empty ()
79+ ;
80+
81+ // || (static_build && shared_build) // when both; but maybe ignore?
82+ // || (win_mt && win_md) // when both; but maybe ignore?
83+
84+ }
85+
86+ static bool hasUserProvidedInformationStrong ()
87+ {
88+ return 0
89+ || !configuration.empty ()
90+ || !compiler.empty ()
91+ || !target_os.empty ()
92+ ;
93+ }
94+
95+ static sw::TargetSettings compilerTypeFromStringCaseI (const String &in)
96+ {
97+ auto compiler = boost::to_lower_copy (in);
98+
99+ sw::TargetSettings ts;
100+
101+ if (0 );
102+ // exact
103+ /* else if (boost::iequals(compiler, "clang"))
104+ return CompilerType::Clang;
105+ else if (boost::iequals(compiler, "clangcl") || boost::iequals(compiler, "clang-cl"))
106+ return CompilerType::ClangCl;
107+ // starts with
108+ else if (boost::istarts_with(compiler, "appleclang") || boost::iequals(compiler, "apple-clang"))
109+ return CompilerType::AppleClang;
110+ else if (boost::istarts_with(compiler, "gnu") || boost::iequals(compiler, "gcc") || boost::iequals(compiler, "g++"))
111+ return CompilerType::GNU;*/
112+ else if (compiler == " msvc" || compiler == " vs" )
113+ {
114+ ts[" native" ][" program" ][" c" ] = " com.Microsoft.VisualStudio.VC.cl" ;
115+ ts[" native" ][" program" ][" cpp" ] = " com.Microsoft.VisualStudio.VC.cl" ;
116+ ts[" native" ][" program" ][" asm" ] = " com.Microsoft.VisualStudio.VC.ml" ;
117+ }
118+ return ts;
119+ }
120+
121+ static String configurationTypeFromStringCaseI (const String &in)
122+ {
123+ auto configuration = boost::to_lower_copy (in);
124+ if (configuration == " d" )
125+ return " debug" ;
126+ else if (configuration == " r" )
127+ return " release" ;
128+ else if (
129+ configuration == " minsizerel" ||
130+ configuration == " msr" )
131+ return " minimalsizerelease" ;
132+ else if (configuration == " relwithdebinfo" ||
133+ configuration == " rwdi" ||
134+ configuration == " releasewithdebinfo" )
135+ return " releasewithdebuginformation" ;
136+ return configuration;
137+ }
138+
139+ static String OSTypeFromStringCaseI (const String &in)
140+ {
141+ auto target_os = boost::to_lower_copy (in);
142+ if (target_os == " win" || target_os == " windows" )
143+ return " com.Microsoft.Windows.NT" ;
144+ return target_os;
145+ }
146+
147+ static String archTypeFromStringCaseI (const String &in)
148+ {
149+ auto platform = boost::to_lower_copy (in);
150+ if (platform == " win32" ||
151+ platform == " x86" )
152+ return " x86" ;
153+ else if (
154+ platform == " win64" ||
155+ platform == " x64" ||
156+ platform == " x64_86" )
157+ return " x86_64" ;
158+ else if (platform == " arm32" )
159+ return " arm" ;
160+ else if (platform == " arm64" )
161+ return " aarch64" ;
162+ return platform;
163+ }
164+
165+ std::vector<sw::TargetSettings> create_settings (const sw::SwCoreContext &swctx)
166+ {
167+ std::vector<sw::TargetSettings> settings;
168+ settings.push_back (swctx.getHostSettings ());
169+
170+ if (!hasAnyUserProvidedInformation ())
171+ return settings;
172+
173+ auto times = [&settings](int n)
174+ {
175+ if (n <= 1 )
176+ return ;
177+ auto s2 = settings;
178+ for (int i = 1 ; i < n; i++)
179+ {
180+ for (auto &s : s2)
181+ settings.push_back (s);
182+ }
183+ };
184+
185+ auto mult_and_action = [&settings, ×](int n, auto f)
186+ {
187+ times (n);
188+ for (int i = 0 ; i < n; i++)
189+ {
190+ int mult = settings.size () / n;
191+ for (int j = i * mult; j < (i + 1 ) * mult; j++)
192+ f (*(settings.begin () + j), i);
193+ }
194+ };
195+
196+ // configuration
197+ Strings configs;
198+ for (auto &c : configuration)
199+ {
200+ /* if (used_configs.find(c) == used_configs.end())
201+ {
202+ if (isConfigSelected(c))
203+ LOG_WARN(logger, "config was not used: " + c);
204+ }
205+ if (!isConfigSelected(c))*/
206+ configs.push_back (c);
207+ }
208+ mult_and_action (configs.size (), [&configs](auto &s, int i)
209+ {
210+ s[" native" ][" configuration" ] = configurationTypeFromStringCaseI (configs[i]);
211+ });
212+
213+ // static/shared
214+ if (static_build && shared_build)
215+ {
216+ mult_and_action (2 , [](auto &s, int i)
217+ {
218+ if (i == 0 )
219+ s[" native" ][" library" ] = " static" ;
220+ if (i == 1 )
221+ s[" native" ][" library" ] = " shared" ;
222+ });
223+ }
224+ else
225+ {
226+ for (auto &s : settings)
227+ {
228+ if (static_build)
229+ s[" native" ][" library" ] = " static" ;
230+ if (shared_build)
231+ s[" native" ][" library" ] = " shared" ;
232+ }
233+ }
234+
235+ // mt/md
236+ if (win_mt && win_md)
237+ {
238+ mult_and_action (2 , [&settings](auto &s, int i)
239+ {
240+ if (i == 0 )
241+ s[" native" ][" mt" ] = " true" ;
242+ });
243+ }
244+ else
245+ {
246+ for (auto &s : settings)
247+ {
248+ if (win_mt)
249+ s[" native" ][" mt" ] = " true" ;
250+ }
251+ }
252+
253+ // platform
254+ mult_and_action (platform.size (), [](auto &s, int i)
255+ {
256+ s[" os" ][" arch" ] = archTypeFromStringCaseI (platform[i]);
257+ });
258+
259+ // compiler
260+ mult_and_action (compiler.size (), [](auto &s, int i)
261+ {
262+ s.merge (compilerTypeFromStringCaseI (compiler[i]));
263+ });
264+
265+ // target_os
266+ mult_and_action (target_os.size (), [](auto &s, int i)
267+ {
268+ s[" os" ][" kernel" ] = OSTypeFromStringCaseI (target_os[i]);
269+ });
270+
271+ // libc
272+ // auto set_libc = [](auto &s, const String &libc)
273+ // {
274+ // s.Settings.Native.libc = libc;
275+ // };
276+
277+ // mult_and_action(libc.size(), [&set_libc](auto &s, int i)
278+ // {
279+ // set_libc(s, libc[i]);
280+ // });
281+
282+ return settings;
283+ }
284+
36285SUBCOMMAND_DECL2 (build)
37286{
38287 if (build_fetch)
@@ -51,6 +300,11 @@ SUBCOMMAND_DECL2(build)
51300 // if -B specified, it is used as is
52301
53302 for (auto &a : build_arg)
54- swctx.addInput (a);
303+ {
304+ auto &i = swctx.addInput (a);
305+ for (auto &s : create_settings (swctx))
306+ i.addSettings (s);
307+ swctx.load ();
308+ }
55309 swctx.build ();
56310}
0 commit comments