NETProjectGen.cpp 66 KB

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