NETProjectGen.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. bool Generate();
  60. private:
  61. // Portable Class Library
  62. bool GenerateShared();
  63. bool GenerateStandard();
  64. bool GetRelativeProjectPath(const String& fromPath, const String& toPath, String& output);
  65. bool CreateProjectFolder(const String& path);
  66. void CreateCompileItemGroup(XMLElement &projectRoot);
  67. void CreateReferencesItemGroup(XMLElement &projectRoot);
  68. void CreateProjectReferencesItemGroup(XMLElement & projectRoot);
  69. void CreatePackagesItemGroup(XMLElement &projectRoot);
  70. void CreateMainPropertyGroup(XMLElement &projectRoot);
  71. void CreateDebugPropertyGroup(XMLElement &projectRoot);
  72. void CreateReleasePropertyGroup(XMLElement &projectRoot);
  73. void CreateApplicationItems(XMLElement &projectRoot);
  74. void CreateAndroidItems(XMLElement &projectRoot);
  75. void CreateIOSItems(XMLElement &projectRoot);
  76. void CreateAssemblyInfo();
  77. void GetAssemblySearchPaths(String& paths);
  78. void ProcessDefineConstants(StringVector& constants);
  79. String name_;
  80. String projectGuid_;
  81. String outputType_;
  82. String rootNamespace_;
  83. String assemblyName_;
  84. String assemblyOutputPath_;
  85. String assemblySearchPaths_;
  86. // project paths
  87. String projectPath_;
  88. XMLElement xmlRoot_;
  89. Vector<String> platforms_;
  90. Vector<String> references_;
  91. Vector<String> packages_;
  92. Vector<String> sourceFolders_;
  93. Vector<String> defineConstants_;
  94. Vector<String> projectTypeGuids_;
  95. Vector<String> importProjects_;
  96. Vector<String> libraryProjectZips_;
  97. Vector<String> transformFiles_;
  98. String targetFrameworkProfile_;
  99. Vector<String> sharedReferences_;
  100. bool playerApplication_;
  101. // Android
  102. bool androidApplication_;
  103. // iOS
  104. String objcBindingApiDefinition_;
  105. String codesignEntitlements_;
  106. String infoPList_;
  107. };
  108. class NETSolution : public NETProjectBase
  109. {
  110. ATOMIC_OBJECT(NETSolution, NETProjectBase)
  111. public:
  112. NETSolution(Context* context, NETProjectGen* projectGen, bool rewrite = false);
  113. virtual ~NETSolution();
  114. bool Load(const JSONValue& root);
  115. bool Generate();
  116. const String& GetOutputPath() { return outputPath_; }
  117. String GetOutputFilename() { return outputPath_ + name_ + ".sln"; }
  118. Vector<String>& GetPackages() { return packages_; }
  119. // Registers a NuGet package, returns true if the package hasn't been previously registered
  120. bool RegisterPackage(const String& package);
  121. /// If true, the sln file will rewritten if it exists, default is false
  122. void SetRewriteSolution(bool rewrite) { rewriteSolution_ = rewrite; }
  123. private:
  124. void GenerateSolution(const String& slnPath);
  125. String name_;
  126. String outputPath_;
  127. String solutionGUID_;
  128. Vector<String> packages_;
  129. bool rewriteSolution_;
  130. };
  131. class NETProjectGen : public Object
  132. {
  133. ATOMIC_OBJECT(NETProjectGen, Object)
  134. public:
  135. NETProjectGen(Context* context);
  136. virtual ~NETProjectGen();
  137. NETSolution* GetSolution() { return solution_; }
  138. const Vector<SharedPtr<NETCSProject>>& GetCSProjects() { return projects_; }
  139. NETCSProject* GetCSProjectByName(const String& name);
  140. bool GetCSProjectDependencies(NETCSProject * source, PODVector<NETCSProject*>& depends) const;
  141. const String& GetAtomicProjectPath() const { return atomicProjectPath_; }
  142. bool Generate();
  143. /// Returns true if the generated solution requires NuGet
  144. bool GetRequiresNuGet();
  145. String GenerateUUID();
  146. /// If true, the sln file will rewritten if it exists, default is false
  147. void SetRewriteSolution(bool rewrite);
  148. bool LoadJSONProject(const String& jsonProjectPath);
  149. bool LoadAtomicProject(const String& atomicProjectPath);
  150. void AddGlobalDefineConstant(const String& constant) { globalDefineConstants_.Push(constant); }
  151. const Vector<String>& GetGlobalDefineConstants() const { return globalDefineConstants_; }
  152. void SetSupportedPlatforms(const StringVector& platforms);
  153. bool GetSupportsPlatform(const String& platform) const;
  154. ProjectSettings* GetProjectSettings() { return projectSettings_; }
  155. private:
  156. bool LoadProject(const JSONValue& root);
  157. /// Returns true if a project is included on the specifed platform
  158. bool IncludeProjectOnPlatform(const JSONValue& projectRoot, const String& platform);
  159. // if true, the solution (sln) file will be recreated if it exists
  160. bool rewriteSolution_;
  161. String atomicProjectPath_;
  162. SharedPtr<NETSolution> solution_;
  163. Vector<String> globalDefineConstants_;
  164. Vector<SharedPtr<NETCSProject>> projects_;
  165. SharedPtr<ProjectSettings> projectSettings_;
  166. };
  167. }