NETProjectGen.cpp 67 KB

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