@@ -1774,11 +1774,10 @@ String Project::print_cpp2()
17741774 else if (pkg.flags [pfExecutable])
17751775 type = " ExecutableTarget" ;
17761776
1777- ctx.beginBlock (" void build(Solution &sln)" );
1778- ctx.addLine (" auto &s = sln.addDirectory(\" demo\" );" );
1777+ ctx.beginBlock (" void build(Solution &s)" );
17791778 ctx.addLine (" auto &" + name + " = s.addTarget<" + type + " >(\" " + pkg.ppath .slice (3 ).toString () + " \" , \" " + pkg.version .toString () + " \" );" );
17801779 auto src = print_source_cpp (source);
1781- ctx.addLine (name + " .Source = " + src + " ;" );
1780+ ctx.addLine (name + " + = " + src + " ;" );
17821781 ctx.emptyLines ();
17831782
17841783 if (checks.checks .size () > 2 )
@@ -1909,125 +1908,69 @@ String Project::print_cpp2()
19091908 return s;
19101909 };
19111910
1912- auto any = options.find (" any" );
1913- if (any != options.end ())
1911+ auto print_def = [&ctx, &name, &escape_str](auto &k, auto &v, const String &type = {})
19141912 {
1915- auto print_def = [&ctx, &name, &escape_str](auto &k, auto &v)
1916- {
1917- if (k == " private" )
1918- ctx.addLine (name + " .Private += \" " + escape_str (v) + " \" _d;" );
1919- else if (k == " public" )
1920- ctx.addLine (name + " .Public += \" " + escape_str (v) + " \" _d;" );
1921- else if (k == " interface" )
1922- ctx.addLine (name + " .Interface += \" " + escape_str (v) + " \" _d;" );
1923- };
1913+ if (k == " private" )
1914+ ctx.addLine (name + " .Private += " + (type.empty () ? " " : (type + " , " )) + " \" " + escape_str (v) + " \" _d;" );
1915+ else if (k == " public" )
1916+ ctx.addLine (name + " .Public += \" " + escape_str (v) + " \" _d;" );
1917+ else if (k == " interface" )
1918+ ctx.addLine (name + " .Interface += \" " + escape_str (v) + " \" _d;" );
1919+ };
19241920
1925- if (!any->second .definitions .empty ())
1926- {
1927- for (auto &[k, v] : any->second .definitions )
1928- print_def (k, v);
1929- }
1930- if (!any->second .system_definitions .empty ())
1931- {
1932- for (auto &[k2, v2] : any->second .system_definitions )
1933- {
1934- if (k2 == " win32" )
1935- {
1936- ctx.beginBlock (" if (s.Settings.TargetOS.Type == OSType::Windows)" );
1937- for (auto &[k, v] : v2)
1938- print_def (k, v);
1939- ctx.endBlock ();
1940- }
1941- else if (k2 == " unix" )
1942- {
1943- ctx.beginBlock (" if (s.Settings.TargetOS.Type != OSType::Windows)" );
1944- for (auto &[k, v] : v2)
1945- print_def (k, v);
1946- ctx.endBlock ();
1947- }
1948- }
1949- }
1950- }
1921+ auto print_co = [&ctx, &name, &escape_str](auto &k, auto &v, const String &type = {})
1922+ {
1923+ /* if (k == "private")
1924+ ctx.addLine(name + ".Private += " + (type.empty() ? "" : (type + ", ")) + "\"" + escape_str(v) + "\"_d;");
1925+ else if (k == "public")
1926+ ctx.addLine(name + ".Public += \"" + escape_str(v) + "\"_d;");
1927+ else if (k == "interface")
1928+ ctx.addLine(name + ".Interface += \"" + escape_str(v) + "\"_d;");*/
1929+ };
19511930
1952- auto shared = options.find (" shared" );
1953- if (shared != options.end ())
1931+ auto print_group = [this , &print_def, &print_co, &ctx](const String &gn, const String &type = {})
19541932 {
1955- auto print_def = [&ctx, &name, &escape_str](auto &k, auto &v)
1956- {
1957- if (k == " private" )
1958- ctx.addLine (name + " .Private += sw::Shared, \" " + escape_str (v) + " \" _d;" );
1959- else if (k == " public" )
1960- ctx.addLine (name + " .Public += sw::Shared, \" " + escape_str (v) + " \" _d;" );
1961- else if (k == " interface" )
1962- ctx.addLine (name + " .Interface += sw::Shared, \" " + escape_str (v) + " \" _d;" );
1963- };
1933+ auto g = options.find (gn);
1934+ if (g == options.end ())
1935+ return ;
19641936
1965- if (!shared-> second . definitions . empty () )
1937+ auto print_obj = [&ctx, &type]( auto &obj, auto &sysobj, auto f )
19661938 {
1967- for (auto &[k, v] : shared->second .definitions )
1968- print_def (k, v);
1969- }
1970- if (!shared->second .system_definitions .empty ())
1971- {
1972- for (auto &[k2, v2] : shared->second .system_definitions )
1939+ for (auto &[k, v] : obj)
1940+ f (k, v, type);
1941+ for (auto &[k2, v2] : sysobj)
19731942 {
19741943 if (k2 == " win32" )
19751944 {
19761945 ctx.beginBlock (" if (s.Settings.TargetOS.Type == OSType::Windows)" );
19771946 for (auto &[k, v] : v2)
1978- print_def (k, v);
1947+ f (k, v);
19791948 ctx.endBlock ();
19801949 }
19811950 else if (k2 == " unix" )
19821951 {
19831952 ctx.beginBlock (" if (s.Settings.TargetOS.Type != OSType::Windows)" );
19841953 for (auto &[k, v] : v2)
1985- print_def (k, v);
1954+ f (k, v);
19861955 ctx.endBlock ();
19871956 }
1988- }
1989- }
1990- }
1991-
1992- auto static_ = options.find (" static" );
1993- if (static_ != options.end ())
1994- {
1995- auto print_def = [&ctx, &name, &escape_str](auto &k, auto &v)
1996- {
1997- if (k == " private" )
1998- ctx.addLine (name + " .Private += sw::Static, \" " + escape_str (v) + " \" _d;" );
1999- else if (k == " public" )
2000- ctx.addLine (name + " .Public += sw::Static, \" " + escape_str (v) + " \" _d;" );
2001- else if (k == " interface" )
2002- ctx.addLine (name + " .Interface. += sw::Static, \" " + escape_str (v) + " \" _d;" );
2003- };
2004-
2005- if (!static_->second .definitions .empty ())
2006- {
2007- for (auto &[k, v] : static_->second .definitions )
2008- print_def (k, v);
2009- }
2010- if (!static_->second .system_definitions .empty ())
2011- {
2012- for (auto &[k2, v2] : static_->second .system_definitions )
2013- {
2014- if (k2 == " win32" )
2015- {
2016- ctx.beginBlock (" if (s.Settings.TargetOS.Type == OSType::Windows)" );
2017- for (auto &[k, v] : v2)
2018- print_def (k, v);
2019- ctx.endBlock ();
2020- }
2021- else if (k2 == " unix" )
1957+ else if (k2 == " msvc" )
20221958 {
2023- ctx.beginBlock (" if (s.Settings.TargetOS.Type != OSType::Windows )" );
1959+ ctx.beginBlock (" if (s.Settings.Native.CompilerType == CompilerType::MSVC )" );
20241960 for (auto &[k, v] : v2)
2025- print_def (k, v);
1961+ f (k, v);
20261962 ctx.endBlock ();
20271963 }
20281964 }
2029- }
2030- }
1965+ };
1966+
1967+ print_obj (g->second .definitions , g->second .system_definitions , print_def);
1968+ print_obj (g->second .compile_options , g->second .system_compile_options , print_co);
1969+ };
1970+
1971+ print_group (" any" );
1972+ print_group (" shared" , " sw::Shared" );
1973+ print_group (" static" , " sw::Static" );
20311974
20321975 ctx.emptyLines ();
20331976
0 commit comments