NETProjectGen.cpp 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915
  1. //
  2. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include <Poco/UUID.h>
  23. #include <Poco/UUIDGenerator.h>
  24. #include <Atomic/IO/Log.h>
  25. #include <Atomic/IO/File.h>
  26. #include <Atomic/IO/FileSystem.h>
  27. #include "../ToolEnvironment.h"
  28. #include "../ToolSystem.h"
  29. #include "../Project/ProjectSettings.h"
  30. #include "../Project/Project.h"
  31. #include "NETProjectGen.h"
  32. #include "NETProjectSystem.h"
  33. namespace ToolCore
  34. {
  35. NETProjectBase::NETProjectBase(Context* context, NETProjectGen* projectGen) :
  36. Object(context), xmlFile_(new XMLFile(context)), projectGen_(projectGen)
  37. {
  38. }
  39. NETProjectBase::~NETProjectBase()
  40. {
  41. }
  42. void NETProjectBase::ReplacePathStrings(String& path)
  43. {
  44. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  45. String atomicRoot = tenv->GetRootSourceDir();
  46. atomicRoot = RemoveTrailingSlash(atomicRoot);
  47. path.Replace("$ATOMIC_ROOT$", atomicRoot, false);
  48. String atomicProjectPath = projectGen_->GetAtomicProjectPath();
  49. // TODO: This is the cause of a bunch of "GetSanitizedPath" calls,
  50. // It should be removed, and the few places in csproj/sln that need backslash
  51. // adjusted there
  52. atomicProjectPath.Replace("/", "\\");
  53. if (atomicProjectPath.Length())
  54. {
  55. path.Replace("$ATOMIC_PROJECT_ROOT$", atomicProjectPath, false);
  56. }
  57. }
  58. NETCSProject::NETCSProject(Context* context, NETProjectGen* projectGen) : NETProjectBase(context, projectGen),
  59. genAssemblyDocFile_(false),
  60. playerApplication_(false),
  61. androidApplication_(false)
  62. {
  63. }
  64. NETCSProject::~NETCSProject()
  65. {
  66. }
  67. bool NETCSProject::SupportsDesktop() const
  68. {
  69. if (!platforms_.Size())
  70. return true;
  71. if (platforms_.Contains("desktop") || platforms_.Contains("windows") || platforms_.Contains("macosx") || platforms_.Contains("linux"))
  72. return true;
  73. return false;
  74. }
  75. bool NETCSProject::SupportsPlatform(const String& platform, bool explicitCheck) const
  76. {
  77. if (!explicitCheck && !platforms_.Size())
  78. return true;
  79. if (platforms_.Contains(platform.ToLower()))
  80. return true;
  81. return false;
  82. }
  83. bool NETCSProject::CreateProjectFolder(const String& path)
  84. {
  85. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  86. if (fileSystem->DirExists(path))
  87. return true;
  88. fileSystem->CreateDirsRecursive(path);
  89. if (!fileSystem->DirExists(path))
  90. {
  91. ATOMIC_LOGERRORF("Unable to create dir: %s", path.CString());
  92. return false;
  93. }
  94. return true;
  95. }
  96. void NETCSProject::CreateCompileItemGroup(XMLElement &projectRoot)
  97. {
  98. FileSystem* fs = GetSubsystem<FileSystem>();
  99. XMLElement igroup = projectRoot.CreateChild("ItemGroup");
  100. // Compile AssemblyInfo.cs
  101. if (!GetIsPCL() && !sharedReferences_.Size() && outputType_ != "Shared")
  102. igroup.CreateChild("Compile").SetAttribute("Include", "Properties\\AssemblyInfo.cs");
  103. for (unsigned i = 0; i < sourceFolders_.Size(); i++)
  104. {
  105. const String& sourceFolder = sourceFolders_[i];
  106. Vector<String> result;
  107. fs->ScanDir(result, sourceFolder, "*.cs", SCAN_FILES, true);
  108. for (unsigned j = 0; j < result.Size(); j++)
  109. {
  110. XMLElement compile = igroup.CreateChild("Compile");
  111. String path = sourceFolder + result[j];
  112. String relativePath;
  113. if (GetRelativePath(projectPath_, GetPath(path), relativePath))
  114. {
  115. path = relativePath + GetFileName(path) + GetExtension(path);
  116. }
  117. // IMPORTANT: / Slash direction breaks intellisense :/
  118. path.Replace('/', '\\');
  119. compile.SetAttribute("Include", path.CString());
  120. // put generated files into generated folder
  121. if (sourceFolder.Contains("Generated") && sourceFolder.Contains("CSharp") && sourceFolder.Contains("Packages"))
  122. {
  123. compile.CreateChild("Link").SetValue("Generated\\" + result[j]);
  124. }
  125. else
  126. {
  127. compile.CreateChild("Link").SetValue(result[j]);
  128. }
  129. }
  130. }
  131. }
  132. void NETProjectBase::CopyXMLElementRecursive(XMLElement source, XMLElement dest)
  133. {
  134. Vector<String> attrNames = source.GetAttributeNames();
  135. for (unsigned i = 0; i < attrNames.Size(); i++)
  136. {
  137. String value = source.GetAttribute(attrNames[i]);
  138. dest.SetAttribute(attrNames[i], value);
  139. }
  140. dest.SetValue(source.GetValue());
  141. XMLElement child = source.GetChild();
  142. while (child.NotNull() && child.GetName().Length())
  143. {
  144. XMLElement childDest = dest.CreateChild(child.GetName());
  145. CopyXMLElementRecursive(child, childDest);
  146. child = child.GetNext();
  147. }
  148. }
  149. void NETCSProject::CreateReferencesItemGroup(XMLElement &projectRoot)
  150. {
  151. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  152. const String atomicProjectPath = projectGen_->GetAtomicProjectPath();
  153. XMLElement xref;
  154. XMLElement igroup = projectRoot.CreateChild("ItemGroup");
  155. for (unsigned i = 0; i < references_.Size(); i++)
  156. {
  157. String ref = references_[i];
  158. String platform;
  159. if (ref.StartsWith("AtomicNET"))
  160. {
  161. if (GetIsPCL())
  162. {
  163. ref = "AtomicNET";
  164. platform = "Portable";
  165. }
  166. else if (SupportsDesktop())
  167. {
  168. ref = "AtomicNET";
  169. platform = "Desktop";
  170. }
  171. else if (SupportsPlatform("android"))
  172. {
  173. if (ref != "AtomicNET.Android.SDL")
  174. ref = "AtomicNET";
  175. platform = "Android";
  176. }
  177. else if (SupportsPlatform("ios"))
  178. {
  179. ref = "AtomicNET";
  180. platform = "iOS";
  181. }
  182. // When building Atomic Projects, assemblies will be in the Lib folder
  183. String config = "Lib";
  184. // If we're not building a project, assemblies will be either Debug or Release
  185. if (!atomicProjectPath.Length())
  186. {
  187. #ifdef ATOMIC_DEBUG
  188. config = "Debug";
  189. #else
  190. config = "Release";
  191. #endif
  192. }
  193. if (platform.Length())
  194. {
  195. String relativeAssemblyPath;
  196. if (GetRelativePath(projectPath_, GetParentPath(projectGen_->GetSolution()->GetOutputPath()), relativeAssemblyPath))
  197. {
  198. xref = igroup.CreateChild("Reference");
  199. xref.SetAttribute("Include", ref);
  200. // Specify the assembly path, which is the same based on native build
  201. String assemblyPath = relativeAssemblyPath + ToString("%s/%s/%s.dll", config.CString(), platform.CString(), ref.CString());
  202. // Setup hint paths with both release/debug config, although they point to same assembly, they don't need to
  203. XMLElement hintPath = xref.CreateChild("HintPath");
  204. hintPath.SetAttribute("Condition", "'$(Configuration)' == 'Release'");
  205. hintPath.SetValue(assemblyPath);
  206. hintPath = xref.CreateChild("HintPath");
  207. hintPath.SetAttribute("Condition", "'$(Configuration)' == 'Debug'");
  208. hintPath.SetValue(assemblyPath);
  209. }
  210. else
  211. {
  212. ATOMIC_LOGERRORF("NETCSProject::CreateReferencesItemGroup - Unable to get relative path from %s to solution", projectPath_.CString());
  213. }
  214. }
  215. continue;
  216. }
  217. // NuGet project
  218. if (ref.StartsWith("<"))
  219. {
  220. XMLFile xmlFile(context_);
  221. if (!xmlFile.FromString(ref))
  222. {
  223. ATOMIC_LOGERROR("NETCSProject::CreateReferencesItemGroup - Unable to parse reference XML");
  224. }
  225. xref = igroup.CreateChild("Reference");
  226. CopyXMLElementRecursive(xmlFile.GetRoot(), xref);
  227. continue;
  228. }
  229. xref = igroup.CreateChild("Reference");
  230. xref.SetAttribute("Include", ref);
  231. }
  232. if (atomicProjectPath.Length())
  233. {
  234. String resourceDir = AddTrailingSlash(atomicProjectPath) + "Resources/";
  235. Vector<String> result;
  236. GetSubsystem<FileSystem>()->ScanDir(result, resourceDir , "*.dll", SCAN_FILES, true);
  237. for (unsigned j = 0; j < result.Size(); j++)
  238. {
  239. String path = resourceDir + result[j];
  240. String relativePath;
  241. if (GetRelativePath(projectPath_, GetPath(path), relativePath))
  242. {
  243. if (projectGen_->GetCSProjectByName(GetFileName(path)))
  244. continue;
  245. path = relativePath + GetFileName(path) + GetExtension(path);
  246. }
  247. xref = igroup.CreateChild("Reference");
  248. xref.SetAttribute("Include", path);
  249. }
  250. }
  251. }
  252. void NETCSProject::CreatePackagesItemGroup(XMLElement &projectRoot)
  253. {
  254. if (!packages_.Size())
  255. return;
  256. XMLElement xref;
  257. XMLElement igroup = projectRoot.CreateChild("ItemGroup");
  258. xref = igroup.CreateChild("None");
  259. xref.SetAttribute("Include", "packages.config");
  260. XMLFile packageConfig(context_);
  261. XMLElement packageRoot = packageConfig.CreateRoot("packages");
  262. for (unsigned i = 0; i < packages_.Size(); i++)
  263. {
  264. XMLFile xmlFile(context_);
  265. if (!xmlFile.FromString(packages_[i]))
  266. {
  267. ATOMIC_LOGERROR("NETCSProject::CreatePackagesItemGroup - Unable to parse package xml");
  268. }
  269. xref = packageRoot.CreateChild("package");
  270. CopyXMLElementRecursive(xmlFile.GetRoot(), xref);
  271. }
  272. SharedPtr<File> output(new File(context_, GetSanitizedPath(projectPath_ + "packages.config"), FILE_WRITE));
  273. String source = packageConfig.ToString();
  274. output->Write(source.CString(), source.Length());
  275. }
  276. void NETCSProject::GetAssemblySearchPaths(String& paths)
  277. {
  278. paths.Clear();
  279. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  280. Vector<String> searchPaths;
  281. if (assemblySearchPaths_.Length())
  282. searchPaths.Push(assemblySearchPaths_);
  283. paths.Join(searchPaths, ";");
  284. }
  285. void NETCSProject::ProcessDefineConstants(StringVector& constants)
  286. {
  287. const Vector<String>& globalConstants = projectGen_->GetGlobalDefineConstants();
  288. constants += globalConstants;
  289. if (constants.Contains("ATOMIC_IOS") || constants.Contains("ATOMIC_ANDROID"))
  290. constants.Push("ATOMIC_MOBILE");
  291. }
  292. void NETCSProject::CreateReleasePropertyGroup(XMLElement &projectRoot)
  293. {
  294. XMLElement pgroup = projectRoot.CreateChild("PropertyGroup");
  295. if (playerApplication_ && SupportsPlatform("ios"))
  296. pgroup.SetAttribute("Condition", " '$(Configuration)|$(Platform)' == 'Release|iPhone' ");
  297. else
  298. pgroup.SetAttribute("Condition", " '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ");
  299. pgroup.CreateChild("Optimize").SetValue("true");
  300. String outputPath = assemblyOutputPath_;
  301. outputPath.Replace("$ATOMIC_CONFIG$", "Release");
  302. String atomicProjectPath = projectGen_->GetAtomicProjectPath();
  303. if (atomicProjectPath.Length())
  304. {
  305. if (!GetRelativeProjectPath(outputPath, projectPath_, outputPath))
  306. {
  307. ATOMIC_LOGERRORF("NETCSProject::CreateReleasePropertyGroup - unable to get relative output path");
  308. }
  309. }
  310. pgroup.CreateChild("OutputPath").SetValue(outputPath);
  311. Vector<String> constants;
  312. constants.Push("TRACE");
  313. constants += defineConstants_;
  314. ProcessDefineConstants(constants);
  315. pgroup.CreateChild("DefineConstants").SetValue(String::Joined(constants, ";").CString());
  316. pgroup.CreateChild("ErrorReport").SetValue("prompt");
  317. pgroup.CreateChild("WarningLevel").SetValue("4");
  318. pgroup.CreateChild("ConsolePause").SetValue("false");
  319. pgroup.CreateChild("AllowUnsafeBlocks").SetValue("true");
  320. // Don't warn on missing XML documentation
  321. pgroup.CreateChild("NoWarn").SetValue("1591");
  322. if (genAssemblyDocFile_)
  323. {
  324. pgroup.CreateChild("DocumentationFile").SetValue(outputPath + assemblyName_ + ".xml");
  325. }
  326. if (SupportsDesktop())
  327. {
  328. pgroup.CreateChild("DebugType").SetValue(GetIsPCL() ? "pdbonly": "full");
  329. if (!GetIsPCL())
  330. pgroup.CreateChild("PlatformTarget").SetValue("x64");
  331. #ifndef ATOMIC_PLATFORM_WINDOWS
  332. String startArguments;
  333. #ifndef ATOMIC_DEV_BUILD
  334. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  335. #ifdef ATOMIC_PLATFORM_OSX
  336. startArguments += ToString("--resourcePrefix \"%s\" ", (fileSystem->GetProgramDir() + "../Resources/").CString());
  337. #else
  338. startArguments += ToString("--resourcePrefix \"%s\" ", (fileSystem->GetProgramDir() + "Resources/").CString());
  339. #endif
  340. #endif
  341. startArguments += ToString("--project \"%s\"", projectGen_->GetAtomicProjectPath().CString());
  342. pgroup.CreateChild("Commandlineparameters").SetValue(startArguments);
  343. #endif
  344. }
  345. else
  346. {
  347. if (SupportsPlatform("android"))
  348. {
  349. pgroup.CreateChild("DebugType").SetValue("pdbonly");
  350. if (outputType_.ToLower() != "library")
  351. {
  352. pgroup.CreateChild("AndroidUseSharedRuntime").SetValue("False");
  353. pgroup.CreateChild("AndroidLinkMode").SetValue("SdkOnly");
  354. }
  355. }
  356. else if (playerApplication_ && SupportsPlatform("ios"))
  357. {
  358. pgroup.CreateChild("DebugType").SetValue("none");
  359. pgroup.CreateChild("MtouchArch").SetValue("ARMv7, ARM64");
  360. pgroup.CreateChild("CodesignEntitlements").SetValue(GetSanitizedPath(codesignEntitlements_));
  361. pgroup.CreateChild("CodesignKey").SetValue("iPhone Developer");
  362. pgroup.CreateChild("MtouchDebug").SetValue("true");
  363. pgroup.CreateChild("MtouchOptimizePNGs").SetValue("False");
  364. }
  365. }
  366. }
  367. void NETCSProject::CreateDebugPropertyGroup(XMLElement &projectRoot)
  368. {
  369. XMLElement pgroup = projectRoot.CreateChild("PropertyGroup");
  370. if (playerApplication_ && SupportsPlatform("ios"))
  371. pgroup.SetAttribute("Condition", " '$(Configuration)|$(Platform)' == 'Debug|iPhone' ");
  372. else
  373. pgroup.SetAttribute("Condition", " '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ");
  374. pgroup.CreateChild("Optimize").SetValue("false");
  375. String outputPath = assemblyOutputPath_;
  376. outputPath.Replace("$ATOMIC_CONFIG$", "Debug");
  377. String atomicProjectPath = projectGen_->GetAtomicProjectPath();
  378. if (atomicProjectPath.Length())
  379. {
  380. if (!GetRelativeProjectPath(outputPath, projectPath_, outputPath))
  381. {
  382. ATOMIC_LOGERRORF("NETCSProject::CreateDebugPropertyGroup - unable to get relative output path");
  383. }
  384. }
  385. pgroup.CreateChild("OutputPath").SetValue(outputPath);
  386. Vector<String> constants;
  387. constants.Push("DEBUG");
  388. constants.Push("TRACE");
  389. constants += defineConstants_;
  390. ProcessDefineConstants(constants);
  391. pgroup.CreateChild("DefineConstants").SetValue(String::Joined(constants, ";").CString());
  392. pgroup.CreateChild("ErrorReport").SetValue("prompt");
  393. pgroup.CreateChild("WarningLevel").SetValue("4");
  394. pgroup.CreateChild("ConsolePause").SetValue("false");
  395. pgroup.CreateChild("AllowUnsafeBlocks").SetValue("true");
  396. // Don't warn on missing XML documentation
  397. pgroup.CreateChild("NoWarn").SetValue("1591");
  398. pgroup.CreateChild("DebugSymbols").SetValue("true");
  399. if (genAssemblyDocFile_)
  400. {
  401. pgroup.CreateChild("DocumentationFile").SetValue(outputPath + assemblyName_ + ".xml");
  402. }
  403. if (SupportsDesktop())
  404. {
  405. pgroup.CreateChild("DebugType").SetValue(GetIsPCL() ? "pdbonly": "full");
  406. if (!GetIsPCL())
  407. pgroup.CreateChild("PlatformTarget").SetValue("x64");
  408. #ifndef ATOMIC_PLATFORM_WINDOWS
  409. String startArguments;
  410. #ifndef ATOMIC_DEV_BUILD
  411. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  412. #ifdef ATOMIC_PLATFORM_OSX
  413. startArguments += ToString("--resourcePrefix \"%s\" ", (fileSystem->GetProgramDir() + "../Resources/").CString());
  414. #else
  415. startArguments += ToString("--resourcePrefix \"%s\" ", (fileSystem->GetProgramDir() + "Resources/").CString());
  416. #endif
  417. #endif
  418. startArguments += ToString("--project \"%s\"", projectGen_->GetAtomicProjectPath().CString());
  419. pgroup.CreateChild("Commandlineparameters").SetValue(startArguments);
  420. #endif
  421. }
  422. else
  423. {
  424. pgroup.CreateChild("DebugType").SetValue(GetIsPCL() ? "pdbonly": "full");
  425. if (androidApplication_)
  426. {
  427. pgroup.CreateChild("AndroidUseSharedRuntime").SetValue("False");
  428. pgroup.CreateChild("AndroidLinkMode").SetValue("None");
  429. pgroup.CreateChild("EmbedAssembliesIntoApk").SetValue("True");
  430. pgroup.CreateChild("BundleAssemblies").SetValue("False");
  431. pgroup.CreateChild("AndroidCreatePackagePerAbi").SetValue("False");
  432. pgroup.CreateChild("Debugger").SetValue("Xamarin");
  433. pgroup.CreateChild("AndroidEnableMultiDex").SetValue("False");
  434. pgroup.CreateChild("AndroidSupportedAbis").SetValue("armeabi-v7a");
  435. }
  436. else if (playerApplication_ && SupportsPlatform("ios"))
  437. {
  438. pgroup.CreateChild("MtouchArch").SetValue("ARMv7, ARM64");
  439. pgroup.CreateChild("CodesignEntitlements").SetValue(GetSanitizedPath(codesignEntitlements_));
  440. pgroup.CreateChild("CodesignKey").SetValue("iPhone Developer");
  441. pgroup.CreateChild("MtouchDebug").SetValue("true");
  442. pgroup.CreateChild("MtouchFastDev").SetValue("true");
  443. pgroup.CreateChild("IpaPackageName").SetValue("");
  444. pgroup.CreateChild("OptimizePNGs").SetValue("false");
  445. pgroup.CreateChild("MtouchOptimizePNGs").SetValue("False");
  446. }
  447. }
  448. }
  449. void NETCSProject::CreateApplicationItems(XMLElement &projectRoot)
  450. {
  451. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  452. XMLElement itemGroup = projectRoot.CreateChild("ItemGroup");
  453. if (SupportsDesktop())
  454. {
  455. // AtomicNETNative
  456. XMLElement atomicNETNativeDLL = itemGroup.CreateChild("None");
  457. #ifdef ATOMIC_DEBUG
  458. String config = "Debug";
  459. #else
  460. String config = "Release";
  461. #endif
  462. #ifdef ATOMIC_PLATFORM_WINDOWS
  463. String platform = "Windows";
  464. String filename = "AtomicNETNative.dll";
  465. #elif defined(ATOMIC_PLATFORM_OSX)
  466. String platform = "Mac";
  467. String filename = "libAtomicNETNative.dylib";
  468. #elif defined(ATOMIC_PLATFORM_LINUX)
  469. String platform = "Linux";
  470. String filename = "libAtomicNETNative.so";
  471. #endif
  472. String relativeNativePath;
  473. String configPath = config;
  474. if (projectGen_->GetAtomicProjectPath().Length())
  475. configPath = "Lib";
  476. if (GetRelativePath(projectPath_, GetParentPath(projectGen_->GetSolution()->GetOutputPath()), relativeNativePath))
  477. {
  478. String nativePath = relativeNativePath + configPath + "/Native/" + platform + "/" + filename;
  479. atomicNETNativeDLL.SetAttribute("Include", nativePath);
  480. atomicNETNativeDLL.CreateChild("Link").SetValue(filename);
  481. atomicNETNativeDLL.CreateChild("CopyToOutputDirectory").SetValue("PreserveNewest");
  482. #ifdef ATOMIC_PLATFORM_WINDOWS
  483. XMLElement d3dCompilerDLL = itemGroup.CreateChild("None");
  484. String d3dCompilerPath = relativeNativePath + configPath + "/Native/" + platform + "/D3DCompiler_47.dll";
  485. d3dCompilerDLL.SetAttribute("Include", d3dCompilerPath);
  486. d3dCompilerDLL.CreateChild("Link").SetValue("D3DCompiler_47.dll");
  487. d3dCompilerDLL.CreateChild("CopyToOutputDirectory").SetValue("PreserveNewest");
  488. #endif
  489. }
  490. }
  491. else
  492. {
  493. const String& projectPath = projectGen_->GetAtomicProjectPath();
  494. if (!playerApplication_ || !projectPath.Length())
  495. return;
  496. if (androidApplication_)
  497. {
  498. XMLElement androidAsset = itemGroup.CreateChild("AndroidAsset");
  499. androidAsset.SetAttribute("Include", projectPath + "AtomicNET/Resources/AtomicResources.pak");
  500. androidAsset.CreateChild("Link").SetValue("Assets\\AtomicResources.pak");
  501. }
  502. else
  503. {
  504. XMLElement bundleResource = itemGroup.CreateChild("BundleResource");
  505. bundleResource.SetAttribute("Include", projectPath + "AtomicNET/Resources/AtomicResources.pak");
  506. bundleResource.CreateChild("Link").SetValue("Resources\\AtomicResources.pak");
  507. bundleResource.CreateChild("CopyToOutputDirectory").SetValue("PreserveNewest");
  508. }
  509. }
  510. }
  511. void NETCSProject::CreateIOSItems(XMLElement &projectRoot)
  512. {
  513. XMLElement iosGroup = projectRoot.CreateChild("ItemGroup");
  514. if (objcBindingApiDefinition_.Length())
  515. {
  516. iosGroup.CreateChild("ObjcBindingApiDefinition").SetAttribute("Include", GetSanitizedPath(objcBindingApiDefinition_));
  517. }
  518. if (name_ == "AtomicNET.iOS")
  519. {
  520. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  521. #ifdef ATOMIC_DEBUG
  522. String config = "Debug";
  523. #else
  524. String config = "Release";
  525. #endif
  526. String nativePath = AddTrailingSlash(tenv->GetAtomicNETRootDir()) + config + "/Native/iOS/AtomicNETNative.framework";
  527. iosGroup.CreateChild("ObjcBindingNativeFramework").SetAttribute("Include", GetSanitizedPath(nativePath));
  528. // framework copy
  529. XMLElement none = iosGroup.CreateChild("None");
  530. none.SetAttribute("Include", nativePath + ".zip");
  531. none.CreateChild("Link").SetValue("AtomicNETNative.framework.zip");
  532. none.CreateChild("CopyToOutputDirectory").SetValue("Always");
  533. }
  534. else if (playerApplication_)
  535. {
  536. XMLElement plist = iosGroup.CreateChild("None");
  537. plist.SetAttribute("Include", GetSanitizedPath(infoPList_));
  538. plist.CreateChild("Link").SetValue("Info.plist");
  539. XMLElement entitlements = iosGroup.CreateChild("Content");
  540. entitlements.SetAttribute("Include", GetSanitizedPath(codesignEntitlements_));
  541. entitlements.CreateChild("Link").SetValue("Entitlements.plist");
  542. }
  543. }
  544. void NETCSProject::CreateAndroidItems(XMLElement &projectRoot)
  545. {
  546. if (!libraryProjectZips_.Size())
  547. {
  548. }
  549. if (libraryProjectZips_.Size())
  550. {
  551. XMLElement libraryGroup = projectRoot.CreateChild("ItemGroup");
  552. for (unsigned i = 0; i < libraryProjectZips_.Size(); i++)
  553. {
  554. libraryGroup.CreateChild("LibraryProjectZip").SetAttribute("Include", libraryProjectZips_[i].CString());
  555. }
  556. }
  557. if (transformFiles_.Size())
  558. {
  559. XMLElement transformGroup = projectRoot.CreateChild("ItemGroup");
  560. for (unsigned i = 0; i < transformFiles_.Size(); i++)
  561. {
  562. transformGroup.CreateChild("TransformFile").SetAttribute("Include", transformFiles_[i].CString());
  563. }
  564. }
  565. if (!importProjects_.Size())
  566. {
  567. projectRoot.CreateChild("Import").SetAttribute("Project", "$(MSBuildExtensionsPath)\\Xamarin\\Android\\Xamarin.Android.CSharp.targets");
  568. }
  569. if (androidApplication_)
  570. {
  571. // TODO: other abi
  572. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  573. #ifdef ATOMIC_DEBUG
  574. String config = "Debug";
  575. #else
  576. String config = "Release";
  577. #endif
  578. // TODO: more than armeabi-v7a (which this is)
  579. String nativePath = AddTrailingSlash(tenv->GetAtomicNETRootDir()) + config + "/Native/Android/libAtomicNETNative.so";
  580. XMLElement nativeLibrary = projectRoot.CreateChild("ItemGroup").CreateChild("AndroidNativeLibrary");
  581. nativeLibrary.SetAttribute("Include", nativePath);
  582. nativeLibrary.CreateChild("Link").SetValue("Libs\\armeabi-v7a\\libAtomicNETNative.so");
  583. XMLElement resourceGroup = projectRoot.CreateChild("ItemGroup");
  584. String relativePath;
  585. if (GetRelativeProjectPath("$ATOMIC_PROJECT_ROOT$/Project/AtomicNET/Platforms/Android/Resources/values/Strings.xml", projectPath_, relativePath))
  586. {
  587. relativePath.Replace("/", "\\");
  588. XMLElement strings = resourceGroup.CreateChild("AndroidResource");
  589. strings.SetAttribute("Include", relativePath);
  590. // Link has to exist for manifest to find resource!
  591. strings.CreateChild("Link").SetValue("Resources\\values\\Strings.xml");
  592. }
  593. else
  594. {
  595. ATOMIC_LOGERROR("Unabled to get relative path for Strings.xml");
  596. }
  597. if (GetRelativeProjectPath("$ATOMIC_PROJECT_ROOT$/Project/AtomicNET/Platforms/Android/Resources/drawable/icon.png", projectPath_, relativePath))
  598. {
  599. relativePath.Replace("/", "\\");
  600. XMLElement icon = resourceGroup.CreateChild("AndroidResource");
  601. icon.SetAttribute("Include", relativePath);
  602. // Link has to exist for manifest to find resource!
  603. icon.CreateChild("Link").SetValue("Resources\\drawable\\icon.png");
  604. }
  605. else
  606. {
  607. ATOMIC_LOGERROR("Unabled to get relative path for Icon.png");
  608. }
  609. }
  610. }
  611. void NETCSProject::CreateAssemblyInfo()
  612. {
  613. String info = "using System.Reflection;\nusing System.Runtime.CompilerServices;\nusing System.Runtime.InteropServices;\n\n\n";
  614. info += ToString("[assembly:AssemblyTitle(\"%s\")]\n", name_.CString());
  615. info += "[assembly:AssemblyDescription(\"\")]\n";
  616. info += "[assembly:AssemblyConfiguration(\"\")]\n";
  617. info += "[assembly:AssemblyCompany(\"\")]\n";
  618. info += ToString("[assembly:AssemblyProduct(\"%s\")]\n", name_.CString());
  619. info += "\n\n\n";
  620. info += "[assembly:ComVisible(false)]\n";
  621. info += "\n\n";
  622. info += ToString("[assembly:Guid(\"%s\")]\n", projectGuid_.CString());
  623. info += "\n\n";
  624. info += "[assembly:AssemblyVersion(\"1.0.0.0\")]\n";
  625. info += "[assembly:AssemblyFileVersion(\"1.0.0.0\")]\n";
  626. SharedPtr<File> output(new File(context_, GetSanitizedPath(projectPath_ + "Properties/AssemblyInfo.cs"), FILE_WRITE));
  627. output->Write(info.CString(), info.Length());
  628. }
  629. bool NETCSProject::GetRelativeProjectPath(const String& fromPath, const String& toPath, String& output)
  630. {
  631. String path = fromPath;
  632. ReplacePathStrings(path);
  633. path = GetSanitizedPath(path);
  634. String relativePath;
  635. if (GetRelativePath(projectPath_, GetPath(path), relativePath))
  636. {
  637. path = relativePath + GetFileName(path) + GetExtension(path);
  638. output = path;
  639. return true;
  640. }
  641. output = fromPath;
  642. return false;
  643. }
  644. void NETCSProject::CreateMainPropertyGroup(XMLElement& projectRoot)
  645. {
  646. XMLElement pgroup = projectRoot.CreateChild("PropertyGroup");
  647. // Configuration
  648. XMLElement config = pgroup.CreateChild("Configuration");
  649. config.SetAttribute("Condition", " '$(Configuration)' == '' ");
  650. config.SetValue("Debug");
  651. // Platform
  652. XMLElement platform = pgroup.CreateChild("Platform");
  653. platform.SetAttribute("Condition", " '$(Platform)' == '' ");
  654. if (playerApplication_ && SupportsPlatform("ios"))
  655. platform.SetValue("iPhone");
  656. else
  657. platform.SetValue("AnyCPU");
  658. // ProjectGuid
  659. XMLElement guid = pgroup.CreateChild("ProjectGuid");
  660. guid.SetValue("{" + projectGuid_ + "}");
  661. // OutputType
  662. XMLElement outputType = pgroup.CreateChild("OutputType");
  663. String oType = outputType_;
  664. #ifdef ATOMIC_PLATFORM_WINDOWS
  665. #ifndef ATOMIC_DEBUG
  666. if (oType.ToLower() == "exe")
  667. {
  668. // use windows subsystem for release builds
  669. // TODO: make this an option in the json?
  670. oType = "WinExe";
  671. }
  672. #endif
  673. #endif
  674. outputType.SetValue(oType);
  675. pgroup.CreateChild("AppDesignerFolder").SetValue("Properties");
  676. // RootNamespace
  677. XMLElement rootNamespace = pgroup.CreateChild("RootNamespace");
  678. rootNamespace.SetValue(rootNamespace_);
  679. // AssemblyName
  680. XMLElement assemblyName = pgroup.CreateChild("AssemblyName");
  681. assemblyName.SetValue(assemblyName_);
  682. pgroup.CreateChild("FileAlignment").SetValue("512");
  683. if (projectTypeGuids_.Size())
  684. {
  685. pgroup.CreateChild("ProjectTypeGuids").SetValue(String::Joined(projectTypeGuids_, ";"));
  686. }
  687. if (SupportsDesktop())
  688. {
  689. pgroup.CreateChild("TargetFrameworkVersion").SetValue("v4.5");
  690. }
  691. else
  692. {
  693. pgroup.CreateChild("ProductVersion").SetValue("8.0.30703");
  694. pgroup.CreateChild("SchemaVersion").SetValue("2.0");
  695. if (SupportsPlatform("ios"))
  696. {
  697. pgroup.CreateChild("IPhoneResourcePrefix").SetValue("Resources");
  698. }
  699. else
  700. {
  701. pgroup.CreateChild("TargetFrameworkVersion").SetValue("v6.0");
  702. }
  703. if (SupportsPlatform("android"))
  704. {
  705. if (!projectTypeGuids_.Size())
  706. {
  707. pgroup.CreateChild("ProjectTypeGuids").SetValue("{EFBA0AD7-5A72-4C68-AF49-83D382785DCF};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}");
  708. }
  709. pgroup.CreateChild("AndroidUseLatestPlatformSdk").SetValue("True");
  710. if (!androidApplication_)
  711. {
  712. // 10368E6C-D01B-4462-8E8B-01FC667A7035 is a binding library
  713. if (!projectTypeGuids_.Contains("{10368E6C-D01B-4462-8E8B-01FC667A7035}"))
  714. pgroup.CreateChild("GenerateSerializationAssemblies").SetValue("Off");
  715. }
  716. else
  717. {
  718. // Android Application
  719. pgroup.CreateChild("AndroidApplication").SetValue("true");
  720. // AndroidManifest.xml must reside in Properties/AndroidManifest.xml, which introduces sync issues :/
  721. pgroup.CreateChild("AndroidManifest").SetValue("Properties\\AndroidManifest.xml");
  722. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  723. String manifestSourceFile = "$ATOMIC_PROJECT_ROOT$/Project/AtomicNET/Platforms/Android/Properties/AndroidManifest.xml";
  724. ReplacePathStrings(manifestSourceFile);
  725. manifestSourceFile = GetSanitizedPath(manifestSourceFile);
  726. if (fileSystem->FileExists(manifestSourceFile))
  727. {
  728. String manifestDest = GetSanitizedPath(projectPath_ + "Properties/");
  729. if (!fileSystem->DirExists(manifestDest))
  730. {
  731. fileSystem->CreateDirs(GetSanitizedPath(projectGen_->GetAtomicProjectPath()), ToString("/AtomicNET/Solution/%s/Properties/", name_.CString()));
  732. }
  733. if (fileSystem->DirExists(manifestDest))
  734. {
  735. if (!fileSystem->Copy(manifestSourceFile, manifestDest + "AndroidManifest.xml"))
  736. {
  737. ATOMIC_LOGERRORF("Unable to copy AndroidManifest from %s to %s", manifestSourceFile.CString(), manifestDest.CString());
  738. }
  739. }
  740. else
  741. {
  742. ATOMIC_LOGERRORF("Unable to create folder %s for AndroidManifest.xml", manifestDest.CString());
  743. }
  744. }
  745. else
  746. {
  747. ATOMIC_LOGERRORF("No AndroidManifest.xml, project will not deploy (%s)", manifestSourceFile.CString());
  748. }
  749. String relativePath;
  750. if (GetRelativeProjectPath("$ATOMIC_PROJECT_ROOT$/Project/AtomicNET/Platforms/Android/Resources/Resource.Designer.cs", projectPath_, relativePath))
  751. {
  752. relativePath.Replace("/", "\\");
  753. pgroup.CreateChild("AndroidResgenFile").SetValue(relativePath);
  754. }
  755. else
  756. {
  757. ATOMIC_LOGERROR("Unabled to get relative path for AndroidResgenFile");
  758. }
  759. pgroup.CreateChild("GenerateSerializationAssemblies").SetValue("Off");
  760. }
  761. }
  762. }
  763. if (targetFrameworkProfile_.Length())
  764. {
  765. pgroup.CreateChild("TargetFrameworkProfile").SetValue(targetFrameworkProfile_);
  766. }
  767. }
  768. bool NETCSProject::GenerateShared()
  769. {
  770. // .shproj
  771. XMLElement project = xmlFile_->CreateRoot("Project");
  772. project.SetAttribute("DefaultTargets", "Build");
  773. project.SetAttribute("ToolsVersion", "14.0");
  774. project.SetAttribute("DefaultTargets", "Build");
  775. project.SetAttribute("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  776. // Project Group
  777. XMLElement projectGroup = project.CreateChild("PropertyGroup");
  778. projectGroup.SetAttribute("Label", "Globals");
  779. projectGroup.CreateChild("ProjectGuid").SetValue(projectGuid_);
  780. projectGroup.CreateChild("MinimumVisualStudioVersion").SetValue("14.0");
  781. XMLElement import = project.CreateChild("Import");
  782. import.SetAttribute("Project", "$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props");
  783. import.SetAttribute("Condition", "Exists('$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props')");
  784. import = project.CreateChild("Import");
  785. import.SetAttribute("Project", "$(MSBuildExtensionsPath32)\\Microsoft\\VisualStudio\\v$(VisualStudioVersion)\\CodeSharing\\Microsoft.CodeSharing.Common.Default.props");
  786. import = project.CreateChild("Import");
  787. import.SetAttribute("Project", "$(MSBuildExtensionsPath32)\\Microsoft\\VisualStudio\\v$(VisualStudioVersion)\\CodeSharing\\Microsoft.CodeSharing.Common.props");
  788. import = project.CreateChild("Import");
  789. import.SetAttribute("Project", ToString("%s.projitems", name_.CString()));
  790. import.SetAttribute("Label", "Shared");
  791. import = project.CreateChild("Import");
  792. import.SetAttribute("Project", "$(MSBuildExtensionsPath32)\\Microsoft\\VisualStudio\\v$(VisualStudioVersion)\\CodeSharing\\Microsoft.CodeSharing.CSharp.targets");
  793. String projectSource = xmlFile_->ToString();
  794. SharedPtr<File> output(new File(context_, GetSanitizedPath(projectPath_ + name_ + ".shproj"), FILE_WRITE));
  795. output->Write(projectSource.CString(), projectSource.Length());
  796. // projitems
  797. SharedPtr<XMLFile> itemsXMLFile(new XMLFile(context_));
  798. XMLElement itemsProject = itemsXMLFile->CreateRoot("Project");
  799. itemsProject.SetAttribute("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  800. XMLElement propertyGroup = itemsProject.CreateChild("PropertyGroup");
  801. propertyGroup.CreateChild("MSBuildAllProjects").SetValue("$(MSBuildAllProjects);$(MSBuildThisFileFullPath)");
  802. propertyGroup.CreateChild("HasSharedItems").SetValue("true");
  803. propertyGroup.CreateChild("SharedGUID").SetValue(projectGuid_);
  804. propertyGroup = itemsProject.CreateChild("PropertyGroup");
  805. propertyGroup.SetAttribute("Label", "Configuration");
  806. propertyGroup.CreateChild("Import_RootNamespace").SetValue("AtomicEngine");
  807. CreateCompileItemGroup(itemsProject);
  808. String itemSource = itemsXMLFile->ToString();
  809. SharedPtr<File> itemsOutput(new File(context_, GetSanitizedPath(projectPath_ + name_ + ".projitems"), FILE_WRITE));
  810. itemsOutput->Write(itemSource.CString(), itemSource.Length());
  811. return true;
  812. }
  813. bool NETCSProject::GenerateStandard()
  814. {
  815. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  816. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  817. NETSolution* solution = projectGen_->GetSolution();
  818. XMLElement project = xmlFile_->CreateRoot("Project");
  819. project.SetAttribute("DefaultTargets", "Build");
  820. project.SetAttribute("ToolsVersion", "14.0");
  821. project.SetAttribute("DefaultTargets", "Build");
  822. project.SetAttribute("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  823. XMLElement import = project.CreateChild("Import");
  824. import.SetAttribute("Project", "$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props");
  825. import.SetAttribute("Condition", "Exists('$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props')");
  826. CreateMainPropertyGroup(project);
  827. CreateDebugPropertyGroup(project);
  828. CreateReleasePropertyGroup(project);
  829. CreateReferencesItemGroup(project);
  830. CreateCompileItemGroup(project);
  831. CreatePackagesItemGroup(project);
  832. if (SupportsPlatform("android"))
  833. {
  834. CreateAndroidItems(project);
  835. }
  836. if (SupportsPlatform("ios"))
  837. {
  838. CreateIOSItems(project);
  839. }
  840. if (SupportsDesktop() && !GetIsPCL())
  841. project.CreateChild("Import").SetAttribute("Project", "$(MSBuildToolsPath)\\Microsoft.CSharp.targets");
  842. if (outputType_.ToLower() == "exe" || androidApplication_)
  843. {
  844. CreateApplicationItems(project);
  845. }
  846. if (!GetIsPCL() && !sharedReferences_.Size() && outputType_ != "Shared")
  847. CreateAssemblyInfo();
  848. const String& atomicProjectPath = projectGen_->GetAtomicProjectPath();
  849. if (atomicProjectPath.Length())
  850. {
  851. // Create the AtomicProject.csproj.user file if it doesn't exist
  852. String userSettingsFilename = projectPath_ + name_ + ".csproj.user";
  853. if (!fileSystem->FileExists(userSettingsFilename))
  854. {
  855. SharedPtr<XMLFile> userSettings(new XMLFile(context_));
  856. XMLElement project = userSettings->CreateRoot("Project");
  857. project.SetAttribute("ToolsVersion", "14.0");
  858. project.SetAttribute("xmlns", "http://schemas.microsoft.com/developer/msbuild/2003");
  859. StringVector configs;
  860. configs.Push("Debug");
  861. configs.Push("Release");
  862. for (unsigned i = 0; i < configs.Size(); i++)
  863. {
  864. String cfg = configs[i];
  865. XMLElement propertyGroup = project.CreateChild("PropertyGroup");
  866. propertyGroup.SetAttribute("Condition", ToString("'$(Configuration)|$(Platform)' == '%s|AnyCPU'", cfg.CString()));
  867. String startArguments;
  868. #ifndef ATOMIC_DEV_BUILD
  869. #ifdef ATOMIC_PLATFORM_OSX
  870. startArguments += ToString("--resourcePrefix \"%s\" ", (fileSystem->GetProgramDir() + "../Resources/").CString());
  871. #else
  872. startArguments += ToString("--resourcePrefix \"%s\" ", (fileSystem->GetProgramDir() + "Resources/").CString());
  873. #endif
  874. #endif
  875. propertyGroup.CreateChild("StartAction").SetValue("Project");
  876. startArguments += ToString("--project \"%s\"", atomicProjectPath.CString());
  877. propertyGroup.CreateChild("StartArguments").SetValue(startArguments);
  878. #ifdef ATOMIC_DEBUG
  879. // When building a debug build, default native code debugging to true
  880. if (cfg == "Debug")
  881. {
  882. propertyGroup.CreateChild("EnableUnmanagedDebugging").SetValue("true");
  883. }
  884. #endif
  885. }
  886. String userSettingsSource = userSettings->ToString();
  887. SharedPtr<File> output(new File(context_, GetSanitizedPath(userSettingsFilename), FILE_WRITE));
  888. output->Write(userSettingsSource.CString(), userSettingsSource.Length());
  889. output->Close();
  890. }
  891. }
  892. for (unsigned i = 0; i < sharedReferences_.Size(); i++)
  893. {
  894. NETCSProject* sharedProject = projectGen_->GetCSProjectByName(sharedReferences_[i]);
  895. if (!sharedProject)
  896. {
  897. ATOMIC_LOGERRORF("Unable to get shared project %s", sharedReferences_[i].CString());
  898. continue;
  899. }
  900. String path = sharedProject->projectPath_ + sharedReferences_[i] + ".projitems";
  901. String relativePath;
  902. if (GetRelativePath(projectPath_, GetPath(path), relativePath))
  903. {
  904. path = relativePath + GetFileName(path) + GetExtension(path);
  905. }
  906. XMLElement shared = project.CreateChild("Import");
  907. shared.SetAttribute("Project", path);
  908. shared.SetAttribute("Label", "Shared");
  909. }
  910. for (unsigned i = 0; i < importProjects_.Size(); i++)
  911. {
  912. project.CreateChild("Import").SetAttribute("Project", importProjects_[i].CString());
  913. }
  914. // Have to come after the imports, so AfterBuild exists
  915. String projectName = "AtomicProject";
  916. if (projectGen_->GetProjectSettings())
  917. projectName = projectGen_->GetProjectSettings()->GetName();
  918. if (name_ == projectName)
  919. {
  920. XMLElement afterBuild = project.CreateChild("Target");
  921. afterBuild.SetAttribute("Name", "AfterBuild");
  922. XMLElement copy = afterBuild.CreateChild("Copy");
  923. copy.SetAttribute("SourceFiles", "$(TargetPath)");
  924. String destPath = projectPath_ + "../../../Resources/";
  925. String relativePath;
  926. String resourceDir = AddTrailingSlash(atomicProjectPath) + "Resources/";
  927. if (GetRelativePath(projectPath_, resourceDir, relativePath))
  928. {
  929. destPath = AddTrailingSlash(relativePath);
  930. }
  931. copy.SetAttribute("DestinationFolder", destPath);
  932. }
  933. String projectSource = xmlFile_->ToString();
  934. SharedPtr<File> output(new File(context_, GetSanitizedPath(projectPath_ + name_ + ".csproj"), FILE_WRITE));
  935. output->Write(projectSource.CString(), projectSource.Length());
  936. return true;
  937. }
  938. bool NETCSProject::Generate()
  939. {
  940. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  941. NETSolution* solution = projectGen_->GetSolution();
  942. projectPath_ = solution->GetOutputPath() + name_ + "/";
  943. if (!CreateProjectFolder(projectPath_))
  944. return false;
  945. if (!CreateProjectFolder(projectPath_ + "Properties"))
  946. return false;
  947. if (outputType_ == "Shared")
  948. {
  949. return GenerateShared();
  950. }
  951. return GenerateStandard();
  952. }
  953. bool NETCSProject::Load(const JSONValue& root)
  954. {
  955. name_ = root["name"].GetString();
  956. projectGuid_ = root["projectGuid"].GetString();
  957. if (!projectGuid_.Length())
  958. {
  959. ATOMIC_LOGINFOF("GUID not provided for project %s, generating one", name_.CString());
  960. projectGuid_ = projectGen_->GenerateUUID();
  961. }
  962. outputType_ = root["outputType"].GetString();
  963. androidApplication_ = root["androidApplication"].GetBool();
  964. playerApplication_ = root["playerApplication"].GetBool();
  965. genAssemblyDocFile_ = root["assemblyDocFile"].GetBool();
  966. rootNamespace_ = root["rootNamespace"].GetString();
  967. assemblyName_ = root["assemblyName"].GetString();
  968. assemblyOutputPath_ = root["assemblyOutputPath"].GetString();
  969. ReplacePathStrings(assemblyOutputPath_);
  970. assemblyOutputPath_ = GetSanitizedPath(assemblyOutputPath_);
  971. assemblySearchPaths_ = root["assemblySearchPaths"].GetString();
  972. ReplacePathStrings(assemblySearchPaths_);
  973. assemblySearchPaths_ = GetSanitizedPath(assemblySearchPaths_);
  974. const JSONArray& platforms = root["platforms"].GetArray();
  975. for (unsigned i = 0; i < platforms.Size(); i++)
  976. {
  977. String platform = platforms[i].GetString();
  978. platforms_.Push(platform.ToLower());
  979. }
  980. const JSONArray& references = root["references"].GetArray();
  981. for (unsigned i = 0; i < references.Size(); i++)
  982. {
  983. String reference = references[i].GetString();
  984. ReplacePathStrings(reference);
  985. references_.Push(reference);
  986. }
  987. const JSONArray& packages = root["packages"].GetArray();
  988. for (unsigned i = 0; i < packages.Size(); i++)
  989. {
  990. String package = packages[i].GetString();
  991. if (packages_.Find(package) != packages_.End())
  992. {
  993. ATOMIC_LOGERRORF("Duplicate package found %s", package.CString());
  994. continue;
  995. }
  996. projectGen_->GetSolution()->RegisterPackage(package);
  997. packages_.Push(package);
  998. }
  999. const JSONArray& sources = root["sources"].GetArray();
  1000. for (unsigned i = 0; i < sources.Size(); i++)
  1001. {
  1002. String source = sources[i].GetString();
  1003. ReplacePathStrings(source);
  1004. sourceFolders_.Push(AddTrailingSlash(source));
  1005. }
  1006. const JSONArray& defineConstants = root["defineConstants"].GetArray();
  1007. for (unsigned i = 0; i < defineConstants.Size(); i++)
  1008. {
  1009. defineConstants_.Push(defineConstants[i].GetString());
  1010. }
  1011. const JSONArray& projectTypeGuids = root["projectTypeGuids"].GetArray();
  1012. for (unsigned i = 0; i < projectTypeGuids.Size(); i++)
  1013. {
  1014. String guid = projectTypeGuids[i].GetString();
  1015. projectTypeGuids_.Push(ToString("{%s}", guid.CString()));
  1016. }
  1017. const JSONArray& importProjects = root["importProjects"].GetArray();
  1018. for (unsigned i = 0; i < importProjects.Size(); i++)
  1019. {
  1020. importProjects_.Push(importProjects[i].GetString());
  1021. }
  1022. const JSONArray& libraryProjectZips = root["libraryProjectZips"].GetArray();
  1023. for (unsigned i = 0; i < libraryProjectZips.Size(); i++)
  1024. {
  1025. String zipPath = libraryProjectZips[i].GetString();
  1026. ReplacePathStrings(zipPath);
  1027. libraryProjectZips_.Push(zipPath);
  1028. }
  1029. const JSONArray& transformFiles = root["transformFiles"].GetArray();
  1030. for (unsigned i = 0; i < transformFiles.Size(); i++)
  1031. {
  1032. String transformFile = transformFiles[i].GetString();
  1033. ReplacePathStrings(transformFile);
  1034. transformFiles_.Push(transformFile);
  1035. }
  1036. const JSONArray& sharedReferences = root["sharedReferences"].GetArray();
  1037. for (unsigned i = 0; i < sharedReferences.Size(); i++)
  1038. {
  1039. sharedReferences_.Push(sharedReferences[i].GetString());
  1040. }
  1041. targetFrameworkProfile_ = root["targetFrameworkProfile"].GetString();
  1042. // iOS
  1043. objcBindingApiDefinition_ = root["objcBindingApiDefinition"].GetString();
  1044. ReplacePathStrings(objcBindingApiDefinition_);
  1045. codesignEntitlements_ = root["codesignEntitlements"].GetString();
  1046. ReplacePathStrings(codesignEntitlements_);
  1047. infoPList_ = root["infoPList"].GetString();
  1048. ReplacePathStrings(infoPList_);
  1049. return true;
  1050. }
  1051. NETSolution::NETSolution(Context* context, NETProjectGen* projectGen, bool rewrite) : NETProjectBase(context, projectGen),
  1052. rewriteSolution_(rewrite)
  1053. {
  1054. }
  1055. NETSolution::~NETSolution()
  1056. {
  1057. }
  1058. bool NETSolution::Generate()
  1059. {
  1060. String slnPath = outputPath_ + name_ + ".sln";
  1061. GenerateSolution(slnPath);
  1062. return true;
  1063. }
  1064. void NETSolution::GenerateSolution(const String &slnPath)
  1065. {
  1066. String source = "Microsoft Visual Studio Solution File, Format Version 12.00\n";
  1067. source += "# Visual Studio 14\n";
  1068. source += "VisualStudioVersion = 14.0.25420.1\n";
  1069. source += "MinimumVisualStudioVersion = 10.0.40219.1\n";
  1070. solutionGUID_ = projectGen_->GenerateUUID();
  1071. PODVector<NETCSProject*> depends;
  1072. const Vector<SharedPtr<NETCSProject>>& projects = projectGen_->GetCSProjects();
  1073. for (unsigned i = 0; i < projects.Size(); i++)
  1074. {
  1075. NETCSProject* p = projects.At(i);
  1076. const String& projectName = p->GetName();
  1077. const String& projectGUID = p->GetProjectGUID();
  1078. String CSharpProjectGUID = "FAE04EC0-301F-11D3-BF4B-00C04F79EFBC";
  1079. String ext = "csproj";
  1080. if (p->outputType_ == "Shared")
  1081. {
  1082. CSharpProjectGUID = "D954291E-2A0B-460D-934E-DC6B0785DB48";
  1083. ext = "shproj";
  1084. }
  1085. source += ToString("Project(\"{%s}\") = \"%s\", \"%s\\%s.%s\", \"{%s}\"\n",
  1086. CSharpProjectGUID.CString(), projectName.CString(), projectName.CString(),
  1087. projectName.CString(), ext.CString(), projectGUID.CString());
  1088. projectGen_->GetCSProjectDependencies(p, depends);
  1089. if (depends.Size())
  1090. {
  1091. source += "\tProjectSection(ProjectDependencies) = postProject\n";
  1092. for (unsigned j = 0; j < depends.Size(); j++)
  1093. {
  1094. source += ToString("\t{%s} = {%s}\n",
  1095. depends[j]->GetProjectGUID().CString(), depends[j]->GetProjectGUID().CString());
  1096. }
  1097. source += "\tEndProjectSection\n";
  1098. }
  1099. source += "EndProject\n";
  1100. }
  1101. source += "Global\n";
  1102. // SharedMSBuildProjectFiles
  1103. source += " GlobalSection(SharedMSBuildProjectFiles) = preSolution\n";
  1104. for (unsigned i = 0; i < projects.Size(); i++)
  1105. {
  1106. NETCSProject* p = projects.At(i);
  1107. if (p->outputType_ == "Shared")
  1108. {
  1109. for (unsigned j = 0; j < projects.Size(); j++)
  1110. {
  1111. NETCSProject* p2 = projects.At(j);
  1112. if (p == p2)
  1113. {
  1114. source += ToString(" %s\\%s.projitems*{%s}*SharedItemsImports = 13\n", p->name_.CString(), p->name_.CString(), p->projectGuid_.CString());
  1115. }
  1116. else
  1117. {
  1118. if (p2->sharedReferences_.Contains(p->name_))
  1119. {
  1120. source += ToString(" %s\\%s.projitems*{%s}*SharedItemsImports = 4\n", p->name_.CString(), p->name_.CString(), p2->projectGuid_.CString());
  1121. }
  1122. }
  1123. }
  1124. }
  1125. }
  1126. source += " EndGlobalSection\n";
  1127. source += " GlobalSection(SolutionConfigurationPlatforms) = preSolution\n";
  1128. source += " Debug|Any CPU = Debug|Any CPU\n";
  1129. source += " Release|Any CPU = Release|Any CPU\n";
  1130. source += " Debug|iPhone = Debug|iPhone\n";
  1131. source += " Release|iPhone = Release|iPhone\n";
  1132. source += " EndGlobalSection\n";
  1133. source += " GlobalSection(ProjectConfigurationPlatforms) = postSolution\n";
  1134. for (unsigned i = 0; i < projects.Size(); i++)
  1135. {
  1136. NETCSProject* p = projects.At(i);
  1137. if (p->outputType_ == "Shared")
  1138. continue;
  1139. String cpu = "Any CPU";
  1140. if (p->GetIsPlayerApp() && p->SupportsPlatform("ios"))
  1141. cpu = "iPhone";
  1142. source += ToString(" {%s}.Debug|%s.ActiveCfg = Debug|%s\n", p->GetProjectGUID().CString(), cpu.CString(), cpu.CString());
  1143. source += ToString(" {%s}.Debug|%s.Build.0 = Debug|%s\n", p->GetProjectGUID().CString(), cpu.CString(), cpu.CString());
  1144. source += ToString(" {%s}.Release|%s.ActiveCfg = Release|%s\n", p->GetProjectGUID().CString(), cpu.CString(), cpu.CString());
  1145. source += ToString(" {%s}.Release|%s.Build.0 = Release|%s\n", p->GetProjectGUID().CString(), cpu.CString(), cpu.CString());
  1146. if (cpu != "iPhone" && (p->SupportsPlatform("ios", false)))
  1147. {
  1148. source += ToString(" {%s}.Debug|iPhone.ActiveCfg = Debug|Any CPU\n", p->GetProjectGUID().CString());
  1149. source += ToString(" {%s}.Debug|iPhone.Build.0 = Debug|Any CPU\n", p->GetProjectGUID().CString());
  1150. source += ToString(" {%s}.Release|iPhone.ActiveCfg = Release|Any CPU\n", p->GetProjectGUID().CString());
  1151. source += ToString(" {%s}.Release|iPhone.Build.0 = Release|Any CPU\n", p->GetProjectGUID().CString());
  1152. }
  1153. }
  1154. source += " EndGlobalSection\n";
  1155. source += "EndGlobal\n";
  1156. if (!rewriteSolution_)
  1157. {
  1158. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  1159. if (fileSystem->Exists(slnPath))
  1160. return;
  1161. }
  1162. SharedPtr<File> output(new File(context_, GetSanitizedPath(slnPath), FILE_WRITE));
  1163. output->Write(source.CString(), source.Length());
  1164. output->Close();
  1165. }
  1166. bool NETSolution::Load(const JSONValue& root)
  1167. {
  1168. FileSystem* fs = GetSubsystem<FileSystem>();
  1169. name_ = root["name"].GetString();
  1170. outputPath_ = AddTrailingSlash(root["outputPath"].GetString());
  1171. ReplacePathStrings(outputPath_);
  1172. // TODO: use poco mkdirs
  1173. if (!fs->DirExists(outputPath_))
  1174. fs->CreateDirsRecursive(outputPath_);
  1175. return true;
  1176. }
  1177. bool NETSolution::RegisterPackage(const String& package)
  1178. {
  1179. if (packages_.Find(package) != packages_.End())
  1180. return false;
  1181. packages_.Push(package);
  1182. return true;
  1183. }
  1184. NETProjectGen::NETProjectGen(Context* context) : Object(context),
  1185. rewriteSolution_(false)
  1186. {
  1187. }
  1188. NETProjectGen::~NETProjectGen()
  1189. {
  1190. }
  1191. NETCSProject* NETProjectGen::GetCSProjectByName(const String & name)
  1192. {
  1193. for (unsigned i = 0; i < projects_.Size(); i++)
  1194. {
  1195. if (projects_[i]->GetName() == name)
  1196. return projects_[i];
  1197. }
  1198. return nullptr;
  1199. }
  1200. bool NETProjectGen::GetCSProjectDependencies(NETCSProject* source, PODVector<NETCSProject*>& depends) const
  1201. {
  1202. depends.Clear();
  1203. const Vector<String>& references = source->GetReferences();
  1204. for (unsigned i = 0; i < projects_.Size(); i++)
  1205. {
  1206. NETCSProject* pdepend = projects_.At(i);
  1207. if (source == pdepend)
  1208. continue;
  1209. for (unsigned j = 0; j < references.Size(); j++)
  1210. {
  1211. if (pdepend->GetName() == references[j])
  1212. {
  1213. depends.Push(pdepend);
  1214. }
  1215. }
  1216. }
  1217. return depends.Size() != 0;
  1218. }
  1219. bool NETProjectGen::Generate()
  1220. {
  1221. solution_->Generate();
  1222. for (unsigned i = 0; i < projects_.Size(); i++)
  1223. {
  1224. if (!projects_[i]->Generate())
  1225. return false;
  1226. }
  1227. return true;
  1228. }
  1229. void NETProjectGen::SetRewriteSolution(bool rewrite)
  1230. {
  1231. rewriteSolution_ = rewrite;
  1232. if (solution_.NotNull())
  1233. solution_->SetRewriteSolution(rewrite);
  1234. }
  1235. bool NETProjectGen::IncludeProjectOnPlatform(const JSONValue& projectRoot, const String& platform)
  1236. {
  1237. const JSONArray& platforms = projectRoot["platforms"].GetArray();
  1238. if (!platforms.Size())
  1239. return true; // all platforms
  1240. String scriptPlatform = platform.ToLower();
  1241. for (unsigned i = 0; i < platforms.Size(); i++)
  1242. {
  1243. String platform = platforms[i].GetString().ToLower();
  1244. if (platform == "desktop")
  1245. {
  1246. if (scriptPlatform == "windows" || scriptPlatform == "macosx" || scriptPlatform == "linux")
  1247. return true;
  1248. return false;
  1249. }
  1250. if (platform == "android" && scriptPlatform != "android")
  1251. return false;
  1252. }
  1253. return true;
  1254. }
  1255. bool NETProjectGen::LoadProject(const JSONValue &root)
  1256. {
  1257. solution_ = new NETSolution(context_, this, rewriteSolution_);
  1258. solution_->Load(root["solution"]);
  1259. const JSONValue& jprojects = root["projects"];
  1260. if (!jprojects.IsArray() || !jprojects.Size())
  1261. return false;
  1262. for (unsigned i = 0; i < jprojects.Size(); i++)
  1263. {
  1264. const JSONValue& jproject = jprojects[i];
  1265. if (!jproject.IsObject())
  1266. return false;
  1267. JSONArray platforms = jproject["platforms"].GetArray();
  1268. if (platforms.Size())
  1269. {
  1270. bool found = false;
  1271. for (unsigned j = 0; j < platforms.Size(); j++)
  1272. {
  1273. if (GetSupportsPlatform(platforms[j].GetString()))
  1274. {
  1275. found = true;
  1276. break;
  1277. }
  1278. }
  1279. if (!found)
  1280. {
  1281. continue;
  1282. }
  1283. }
  1284. // HACK! Do not generate AtomicNETService in the AtomicProject solution
  1285. if (jproject["name"].GetString() == "AtomicNETService" && atomicProjectPath_.Length())
  1286. {
  1287. continue;
  1288. }
  1289. SharedPtr<NETCSProject> csProject(new NETCSProject(context_, this));
  1290. if (!csProject->Load(jproject))
  1291. return false;
  1292. projects_.Push(csProject);
  1293. }
  1294. return true;
  1295. }
  1296. bool NETProjectGen::LoadJSONProject(const String& jsonProjectPath)
  1297. {
  1298. SharedPtr<File> file(new File(context_));
  1299. if (!file->Open(GetSanitizedPath(jsonProjectPath)))
  1300. return false;
  1301. String json;
  1302. file->ReadText(json);
  1303. JSONValue jvalue;
  1304. if (!JSONFile::ParseJSON(json, jvalue))
  1305. return false;
  1306. return LoadProject(jvalue);
  1307. }
  1308. \
  1309. bool NETProjectGen::LoadAtomicProject(const String& atomicProjectPath)
  1310. {
  1311. ToolEnvironment* tenv = GetSubsystem<ToolEnvironment>();
  1312. ToolSystem* tsystem = GetSubsystem<ToolSystem>();
  1313. String pathname, filename, ext;
  1314. SplitPath(atomicProjectPath, pathname, filename, ext);
  1315. if (ext == ".atomic")
  1316. {
  1317. atomicProjectPath_ = AddTrailingSlash(pathname);
  1318. }
  1319. else
  1320. {
  1321. atomicProjectPath_ = AddTrailingSlash(atomicProjectPath);
  1322. }
  1323. // Do we have a loaded project?
  1324. if (Project* project = tsystem->GetProject())
  1325. {
  1326. // If so, use loaded project settings
  1327. projectSettings_ = project->GetProjectSettings();
  1328. }
  1329. else
  1330. {
  1331. // Nope, load them up
  1332. projectSettings_ = SharedPtr<ProjectSettings>(new ProjectSettings(context_));
  1333. projectSettings_->Load(atomicProjectPath_ + "Settings/Project.json");
  1334. }
  1335. #ifdef ATOMIC_DEV_BUILD
  1336. JSONValue netJSON;
  1337. SharedPtr<File> netJSONFile(new File(context_));
  1338. String atomicNETProject = tenv->GetRootSourceDir() + "Script/AtomicNET/AtomicNETProject.json";
  1339. if (!netJSONFile->Open(GetSanitizedPath(atomicNETProject)))
  1340. return false;
  1341. String netJSONString;
  1342. netJSONFile->ReadText(netJSONString);
  1343. if (!JSONFile::ParseJSON(netJSONString, netJSON))
  1344. return false;
  1345. #else
  1346. AtomicNETCopyAssemblies(context_, atomicProjectPath_ + "AtomicNET/Lib/");
  1347. #endif
  1348. #ifdef ATOMIC_DEV_BUILD
  1349. String projectPath = tenv->GetRootSourceDir() + "Script/AtomicNET/AtomicProject.json";
  1350. #else
  1351. String projectPath = tenv->GetAtomicNETRootDir() + "Build/Projects/AtomicProject.json";
  1352. #endif
  1353. SharedPtr<File> file(new File(context_));
  1354. if (!file->Open(GetSanitizedPath(projectPath)))
  1355. return false;
  1356. String json;
  1357. file->ReadText(json);
  1358. json.Replace("$ATOMIC_PROJECT_NAME$", projectSettings_->GetName());
  1359. JSONValue jvalue;
  1360. if (!JSONFile::ParseJSON(json, jvalue))
  1361. return false;
  1362. #ifdef ATOMIC_DEV_BUILD
  1363. // patch projects
  1364. JSONArray netProjects = netJSON["projects"].GetArray();
  1365. JSONArray projects = jvalue["projects"].GetArray();
  1366. for (unsigned i = 0; i < projects.Size(); i++)
  1367. {
  1368. netProjects.Push(JSONValue(projects[i].GetObject()));
  1369. }
  1370. jvalue["projects"] = netProjects;
  1371. return LoadProject(jvalue);
  1372. #else
  1373. return LoadProject(jvalue);
  1374. #endif
  1375. }
  1376. void NETProjectGen::SetSupportedPlatforms(const StringVector& platforms)
  1377. {
  1378. projectSettings_ = SharedPtr<ProjectSettings>(new ProjectSettings(context_));
  1379. for (unsigned i = 0; i < platforms.Size(); i++)
  1380. {
  1381. projectSettings_->AddSupportedPlatform(platforms[i]);
  1382. }
  1383. }
  1384. bool NETProjectGen::GetSupportsPlatform(const String& platform) const
  1385. {
  1386. // If no project platform settings are loaded, always supports
  1387. if (projectSettings_.Null())
  1388. {
  1389. return true;
  1390. }
  1391. return projectSettings_->GetSupportsPlatform(platform);
  1392. }
  1393. bool NETProjectGen::GetRequiresNuGet()
  1394. {
  1395. if (solution_.Null())
  1396. {
  1397. ATOMIC_LOGERROR("NETProjectGen::GetRequiresNuGet() - called without a solution loaded");
  1398. return false;
  1399. }
  1400. return solution_->GetPackages().Size() != 0;
  1401. }
  1402. String NETProjectGen::GenerateUUID()
  1403. {
  1404. Poco::UUIDGenerator& generator = Poco::UUIDGenerator::defaultGenerator();
  1405. Poco::UUID uuid(generator.create()); // time based
  1406. return String(uuid.toString().c_str()).ToUpper();
  1407. }
  1408. }