NETProjectGen.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. #pragma once
  23. #include <Atomic/Core/Object.h>
  24. #include <Atomic/Resource/XMLFile.h>
  25. #include <Atomic/Resource/JSONFile.h>
  26. using namespace Atomic;
  27. namespace ToolCore
  28. {
  29. class ProjectSettings;
  30. class NETProjectGen;
  31. class NETProjectBase : public Object
  32. {
  33. ATOMIC_OBJECT(NETProjectBase, Object)
  34. public:
  35. NETProjectBase(Context* context, NETProjectGen* projectGen);
  36. virtual ~NETProjectBase();
  37. void ReplacePathStrings(String& path);
  38. void CopyXMLElementRecursive(XMLElement source, XMLElement dest);
  39. protected:
  40. SharedPtr<XMLFile> xmlFile_;
  41. WeakPtr<NETProjectGen> projectGen_;
  42. };
  43. class NETCSProject : public NETProjectBase
  44. {
  45. friend class NETSolution;
  46. ATOMIC_OBJECT(NETCSProject, NETProjectBase)
  47. public:
  48. NETCSProject(Context* context, NETProjectGen* projectGen);
  49. virtual ~NETCSProject();
  50. bool Load(const JSONValue& root);
  51. const String& GetName() { return name_; }
  52. const String& GetProjectGUID() { return projectGuid_; }
  53. const Vector<String>& GetReferences() const { return references_; }
  54. const Vector<String>& GetPackages() const { return packages_; }
  55. bool GetIsPCL() const { return projectTypeGuids_.Contains("{786C830F-07A1-408B-BD7F-6EE04809D6DB}"); }
  56. bool GetIsPlayerApp() const { return playerApplication_; }
  57. bool SupportsDesktop() const;
  58. bool SupportsPlatform(const String& platform, bool explicitCheck = true) const;
  59. /// Returns true if this project is part of core AtomicNET
  60. bool GetAtomicNETProject() const { return atomicNETProject_; }
  61. bool Generate();
  62. private:
  63. /// Returns true if this project is part of core AtomicNET
  64. void SetAtomicNETProject(bool value) { atomicNETProject_ = value; }
  65. // Portable Class Library
  66. bool GenerateShared();
  67. bool GenerateStandard();
  68. bool GetRelativeProjectPath(const String& fromPath, const String& toPath, String& output);
  69. bool CreateProjectFolder(const String& path);
  70. void CreateCompileItemGroup(XMLElement &projectRoot);
  71. void CreateReferencesItemGroup(XMLElement &projectRoot);
  72. void CreatePackagesItemGroup(XMLElement &projectRoot);
  73. void CreateMainPropertyGroup(XMLElement &projectRoot);
  74. void CreateDebugPropertyGroup(XMLElement &projectRoot);
  75. void CreateReleasePropertyGroup(XMLElement &projectRoot);
  76. void CreateApplicationItems(XMLElement &projectRoot);
  77. void CreateAndroidItems(XMLElement &projectRoot);
  78. void CreateIOSItems(XMLElement &projectRoot);
  79. void CreateAssemblyInfo();
  80. void GetAssemblySearchPaths(String& paths);
  81. void ProcessDefineConstants(StringVector& constants);
  82. String name_;
  83. String projectGuid_;
  84. String outputType_;
  85. String rootNamespace_;
  86. String assemblyName_;
  87. String assemblyOutputPath_;
  88. String assemblySearchPaths_;
  89. bool atomicNETProject_;
  90. // project paths
  91. String projectPath_;
  92. XMLElement xmlRoot_;
  93. Vector<String> platforms_;
  94. Vector<String> references_;
  95. Vector<String> packages_;
  96. Vector<String> sourceFolders_;
  97. Vector<String> defineConstants_;
  98. Vector<String> projectTypeGuids_;
  99. Vector<String> importProjects_;
  100. Vector<String> libraryProjectZips_;
  101. Vector<String> transformFiles_;
  102. String targetFrameworkProfile_;
  103. Vector<String> sharedReferences_;
  104. bool genAssemblyDocFile_;
  105. bool playerApplication_;
  106. // Android
  107. bool androidApplication_;
  108. // iOS
  109. String objcBindingApiDefinition_;
  110. String codesignEntitlements_;
  111. String infoPList_;
  112. };
  113. class NETSolution : public NETProjectBase
  114. {
  115. ATOMIC_OBJECT(NETSolution, NETProjectBase)
  116. public:
  117. NETSolution(Context* context, NETProjectGen* projectGen, bool rewrite = false);
  118. virtual ~NETSolution();
  119. bool Load(const JSONValue& root);
  120. bool Generate();
  121. const String& GetOutputPath() { return outputPath_; }
  122. String GetOutputFilename() { return outputPath_ + name_ + ".sln"; }
  123. Vector<String>& GetPackages() { return packages_; }
  124. // Registers a NuGet package, returns true if the package hasn't been previously registered
  125. bool RegisterPackage(const String& package);
  126. /// If true, the sln file will rewritten if it exists, default is false
  127. void SetRewriteSolution(bool rewrite) { rewriteSolution_ = rewrite; }
  128. private:
  129. void GenerateSolution(const String& slnPath);
  130. String name_;
  131. String outputPath_;
  132. String solutionGUID_;
  133. Vector<String> packages_;
  134. bool rewriteSolution_;
  135. };
  136. class NETProjectGen : public Object
  137. {
  138. ATOMIC_OBJECT(NETProjectGen, Object)
  139. public:
  140. NETProjectGen(Context* context);
  141. virtual ~NETProjectGen();
  142. NETSolution* GetSolution() { return solution_; }
  143. const Vector<SharedPtr<NETCSProject>>& GetCSProjects() { return projects_; }
  144. NETCSProject* GetCSProjectByName(const String& name);
  145. bool GetCSProjectDependencies(NETCSProject * source, PODVector<NETCSProject*>& depends) const;
  146. const String& GetAtomicProjectPath() const { return atomicProjectPath_; }
  147. bool Generate();
  148. /// Returns true if the generated solution requires NuGet
  149. bool GetRequiresNuGet();
  150. String GenerateUUID();
  151. /// If true, the sln file will rewritten if it exists, default is false
  152. void SetRewriteSolution(bool rewrite);
  153. bool LoadJSONProject(const String& jsonProjectPath);
  154. bool LoadAtomicProject(const String& atomicProjectPath);
  155. void AddGlobalDefineConstant(const String& constant) { globalDefineConstants_.Push(constant); }
  156. const Vector<String>& GetGlobalDefineConstants() const { return globalDefineConstants_; }
  157. void SetSupportedPlatforms(const StringVector& platforms);
  158. bool GetSupportsPlatform(const String& platform) const;
  159. ProjectSettings* GetProjectSettings() { return projectSettings_; }
  160. private:
  161. bool LoadProject(const JSONValue& root);
  162. /// Returns true if a project is included on the specifed platform
  163. bool IncludeProjectOnPlatform(const JSONValue& projectRoot, const String& platform);
  164. // if true, the solution (sln) file will be recreated if it exists
  165. bool rewriteSolution_;
  166. String atomicProjectPath_;
  167. SharedPtr<NETSolution> solution_;
  168. Vector<String> globalDefineConstants_;
  169. Vector<SharedPtr<NETCSProject>> projects_;
  170. SharedPtr<ProjectSettings> projectSettings_;
  171. };
  172. }