NETProjectGen.cpp 67 KB

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