NETProjectGen.cpp 62 KB

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