NETProjectGen.cpp 62 KB

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