NETProjectGen.h 7.0 KB

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