Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

379 lines
11 KiB

  1. //====== Copyright � 1996-2005, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #ifndef VCPROJGENERATOR_H
  7. #define VCPROJGENERATOR_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. class CProjectConfiguration;
  12. class CVCProjGenerator;
  13. class CProjectTool;
  14. struct PropertyState_t
  15. {
  16. ToolProperty_t *m_pToolProperty;
  17. CUtlString m_OrdinalString;
  18. CUtlString m_StringValue;
  19. };
  20. // ps3 visual studio integration
  21. enum PS3VSIType_e
  22. {
  23. PS3_VSI_TYPE_UNDEFINED = -1,
  24. PS3_VSI_TYPE_SNC = 0,
  25. PS3_VSI_TYPE_GCC = 1,
  26. };
  27. class CProjectFile
  28. {
  29. public:
  30. CProjectFile( CVCProjGenerator *pGenerator, const char *pFilename );
  31. ~CProjectFile();
  32. bool GetConfiguration( const char *pConfigName, CProjectConfiguration **ppConfig );
  33. bool AddConfiguration( const char *pConfigName, CProjectConfiguration **ppConfig );
  34. bool RemoveConfiguration( CProjectConfiguration *pConfig );
  35. CUtlString m_Name;
  36. CVCProjGenerator *m_pGenerator;
  37. CUtlVector< CProjectConfiguration* > m_Configs;
  38. };
  39. class CProjectFolder
  40. {
  41. public:
  42. CProjectFolder( CVCProjGenerator *pGenerator, const char *pFolderName );
  43. ~CProjectFolder();
  44. bool GetFolder( const char *pFolderName, CProjectFolder **pFolder );
  45. bool AddFolder( const char *pFolderName, CProjectFolder **pFolder );
  46. void AddFile( const char *pFilename, CProjectFile **ppFile );
  47. bool FindFile( const char *pFilename );
  48. bool RemoveFile( const char *pFilename );
  49. CUtlString m_Name;
  50. CVCProjGenerator *m_pGenerator;
  51. CUtlLinkedList< CProjectFolder* > m_Folders;
  52. CUtlLinkedList< CProjectFile* > m_Files;
  53. };
  54. class CPropertyStateLessFunc
  55. {
  56. public:
  57. bool Less( const int& lhs, const int& rhs, void *pContext );
  58. };
  59. class CPropertyStates
  60. {
  61. public:
  62. CPropertyStates();
  63. bool SetProperty( ToolProperty_t *pToolProperty, CProjectTool *pRootTool = NULL );
  64. bool SetBoolProperty( ToolProperty_t *pToolProperty, bool bEnabled );
  65. PropertyState_t *GetProperty( int nPropertyId );
  66. PropertyState_t *GetProperty( const char *pPropertyName );
  67. CUtlVector< PropertyState_t > m_Properties;
  68. CUtlSortVector< int, CPropertyStateLessFunc > m_PropertiesInOutputOrder;
  69. private:
  70. bool SetStringProperty( ToolProperty_t *pToolProperty, CProjectTool *pRootTool = NULL );
  71. bool SetListProperty( ToolProperty_t *pToolProperty, CProjectTool *pRootTool = NULL );
  72. bool SetBoolProperty( ToolProperty_t *pToolProperty, CProjectTool *pRootTool = NULL );
  73. bool SetBoolProperty( ToolProperty_t *pToolProperty, CProjectTool *pRootTool, bool bEnabled );
  74. bool SetIntegerProperty( ToolProperty_t *pToolProperty, CProjectTool *pRootTool = NULL );
  75. };
  76. class CProjectTool
  77. {
  78. public:
  79. CProjectTool( CVCProjGenerator *pGenerator )
  80. {
  81. m_pGenerator = pGenerator;
  82. }
  83. CVCProjGenerator *GetGenerator() { return m_pGenerator; }
  84. // when the property belongs to the root tool (i.e. linker), no root tool is passed in
  85. // when the property is for the file's specific configuration tool, (i.e. compiler/debug), the root tool must be supplied
  86. virtual bool SetProperty( ToolProperty_t *pToolProperty, CProjectTool *pRootTool = NULL );
  87. CPropertyStates m_PropertyStates;
  88. private:
  89. CVCProjGenerator *m_pGenerator;
  90. };
  91. class CDebuggingTool : public CProjectTool
  92. {
  93. public:
  94. CDebuggingTool( CVCProjGenerator *pGenerator ) : CProjectTool( pGenerator ) {}
  95. };
  96. class CCompilerTool : public CProjectTool
  97. {
  98. public:
  99. CCompilerTool( CVCProjGenerator *pGenerator, const char *pConfigName, bool bIsFileConfig ) : CProjectTool( pGenerator )
  100. {
  101. m_ConfigName = pConfigName;
  102. m_bIsFileConfig = bIsFileConfig;
  103. }
  104. bool SetProperty( ToolProperty_t *pToolProperty, CProjectTool *pRootTool = NULL );
  105. private:
  106. CUtlString m_ConfigName;
  107. bool m_bIsFileConfig;
  108. };
  109. class CLibrarianTool : public CProjectTool
  110. {
  111. public:
  112. CLibrarianTool( CVCProjGenerator *pGenerator ) : CProjectTool( pGenerator ) {}
  113. };
  114. class CLinkerTool : public CProjectTool
  115. {
  116. public:
  117. CLinkerTool( CVCProjGenerator *pGenerator ) : CProjectTool( pGenerator ) {}
  118. };
  119. class CManifestTool : public CProjectTool
  120. {
  121. public:
  122. CManifestTool( CVCProjGenerator *pGenerator ) : CProjectTool( pGenerator ) {}
  123. };
  124. class CXMLDocGenTool : public CProjectTool
  125. {
  126. public:
  127. CXMLDocGenTool( CVCProjGenerator *pGenerator ) : CProjectTool( pGenerator ) {}
  128. };
  129. class CBrowseInfoTool : public CProjectTool
  130. {
  131. public:
  132. CBrowseInfoTool( CVCProjGenerator *pGenerator ) : CProjectTool( pGenerator ) {}
  133. };
  134. class CResourcesTool : public CProjectTool
  135. {
  136. public:
  137. CResourcesTool( CVCProjGenerator *pGenerator ) : CProjectTool( pGenerator ) {}
  138. };
  139. class CPreBuildEventTool : public CProjectTool
  140. {
  141. public:
  142. CPreBuildEventTool( CVCProjGenerator *pGenerator ) : CProjectTool( pGenerator ) {}
  143. };
  144. class CPreLinkEventTool : public CProjectTool
  145. {
  146. public:
  147. CPreLinkEventTool( CVCProjGenerator *pGenerator ) : CProjectTool( pGenerator ) {}
  148. };
  149. class CPostBuildEventTool : public CProjectTool
  150. {
  151. public:
  152. CPostBuildEventTool( CVCProjGenerator *pGenerator ) : CProjectTool( pGenerator ) {}
  153. };
  154. class CCustomBuildTool : public CProjectTool
  155. {
  156. public:
  157. CCustomBuildTool( CVCProjGenerator *pGenerator, const char *pConfigName, bool bIsFileConfig ) : CProjectTool( pGenerator )
  158. {
  159. m_ConfigName = pConfigName;
  160. m_bIsFileConfig = bIsFileConfig;
  161. }
  162. bool SetProperty( ToolProperty_t *pToolProperty, CProjectTool *pRootTool = NULL );
  163. private:
  164. CUtlString m_ConfigName;
  165. bool m_bIsFileConfig;
  166. };
  167. class CXboxImageTool : public CProjectTool
  168. {
  169. public:
  170. CXboxImageTool( CVCProjGenerator *pGenerator ) : CProjectTool( pGenerator ) {}
  171. };
  172. class CXboxDeploymentTool : public CProjectTool
  173. {
  174. public:
  175. CXboxDeploymentTool( CVCProjGenerator *pGenerator ) : CProjectTool( pGenerator ) {}
  176. };
  177. class CProjectConfiguration
  178. {
  179. public:
  180. CProjectConfiguration( CVCProjGenerator *pGenerator, const char *pConfigName, const char *pFilename );
  181. ~CProjectConfiguration();
  182. CDebuggingTool *GetDebuggingTool() { return m_pDebuggingTool; }
  183. CCompilerTool *GetCompilerTool() { return m_pCompilerTool; }
  184. CLibrarianTool *GetLibrarianTool() { return m_pLibrarianTool; }
  185. CLinkerTool *GetLinkerTool() { return m_pLinkerTool; }
  186. CManifestTool *GetManifestTool() { return m_pManifestTool; }
  187. CXMLDocGenTool *GetXMLDocGenTool() { return m_pXMLDocGenTool; }
  188. CBrowseInfoTool *GetBrowseInfoTool() { return m_pBrowseInfoTool; }
  189. CResourcesTool *GetResourcesTool() { return m_pResourcesTool; }
  190. CPreBuildEventTool *GetPreBuildEventTool() { return m_pPreBuildEventTool; }
  191. CPreLinkEventTool *GetPreLinkEventTool() { return m_pPreLinkEventTool; }
  192. CPostBuildEventTool *GetPostBuildEventTool() { return m_pPostBuildEventTool; }
  193. CCustomBuildTool *GetCustomBuildTool() { return m_pCustomBuildTool; }
  194. CXboxImageTool *GetXboxImageTool() { return m_pXboxImageTool; }
  195. CXboxDeploymentTool *GetXboxDeploymentTool() { return m_pXboxDeploymentTool; }
  196. bool IsEmpty();
  197. bool SetProperty( ToolProperty_t *pToolProperty );
  198. CVCProjGenerator *m_pGenerator;
  199. // type of config, and config's properties
  200. bool m_bIsFileConfig;
  201. CUtlString m_Name;
  202. CPropertyStates m_PropertyStates;
  203. private:
  204. // the config's tools
  205. CDebuggingTool *m_pDebuggingTool;
  206. CCompilerTool *m_pCompilerTool;
  207. CLibrarianTool *m_pLibrarianTool;
  208. CLinkerTool *m_pLinkerTool;
  209. CManifestTool *m_pManifestTool;
  210. CXMLDocGenTool *m_pXMLDocGenTool;
  211. CBrowseInfoTool *m_pBrowseInfoTool;
  212. CResourcesTool *m_pResourcesTool;
  213. CPreBuildEventTool *m_pPreBuildEventTool;
  214. CPreLinkEventTool *m_pPreLinkEventTool;
  215. CPostBuildEventTool *m_pPostBuildEventTool;
  216. CCustomBuildTool *m_pCustomBuildTool;
  217. CXboxImageTool *m_pXboxImageTool;
  218. CXboxDeploymentTool *m_pXboxDeploymentTool;
  219. };
  220. class IVCProjWriter
  221. {
  222. public:
  223. virtual bool Save( const char *pOutputFilename ) = 0;
  224. };
  225. class CVCProjGenerator : public CBaseProjectDataCollector
  226. {
  227. public:
  228. typedef CBaseProjectDataCollector BaseClass;
  229. CVCProjGenerator();
  230. virtual const char *GetProjectFileExtension();
  231. virtual void StartProject();
  232. virtual void EndProject();
  233. virtual CUtlString GetProjectName();
  234. virtual void SetProjectName( const char *pProjectName );
  235. virtual void GetAllConfigurationNames( CUtlVector< CUtlString > &configurationNames );
  236. virtual void StartConfigurationBlock( const char *pConfigName, bool bFileSpecific );
  237. virtual void EndConfigurationBlock();
  238. virtual bool StartPropertySection( configKeyword_e keyword, bool *pbShouldSkip );
  239. virtual void HandleProperty( const char *pProperty, const char *pCustomScriptData );
  240. virtual void EndPropertySection( configKeyword_e keyword );
  241. virtual void StartFolder( const char *pFolderName );
  242. virtual void EndFolder();
  243. virtual bool StartFile( const char *pFilename, bool bWarnIfAlreadyExists );
  244. virtual void EndFile();
  245. virtual void FileExcludedFromBuild( bool bExcluded );
  246. virtual bool RemoveFile( const char *pFilename );
  247. CGeneratorDefinition *GetGeneratorDefinition() { return m_pGeneratorDefinition; }
  248. void SetupGeneratorDefinition( IVCProjWriter *pVCProjWriter, const char *pDefinitionName, PropertyName_t *pPropertyNames );
  249. PS3VSIType_e GetVSIType() { return m_VSIType; }
  250. CUtlString GetGUIDString() { return m_GUIDString; }
  251. bool GetRootConfiguration( const char *pConfigName, CProjectConfiguration **pConfig );
  252. CProjectFolder *GetRootFolder() { return m_pRootFolder; }
  253. private:
  254. void Clear();
  255. bool Config_GetConfigurations( const char *pszConfigName );
  256. // returns true if found, false otherwise
  257. bool GetFolder( const char *pFolderName, CProjectFolder *pParentFolder, CProjectFolder **pOutFolder );
  258. // returns true if added, false otherwise (duplicate)
  259. bool AddFolder( const char *pFolderName, CProjectFolder *pParentFolder, CProjectFolder **pOutFolder );
  260. // returns true if found, false otherwise
  261. bool FindFile( const char *pFilename, CProjectFile **pFile );
  262. void AddFileToFolder( const char *pFilename, CProjectFolder *pFolder, bool bWarnIfExists, CProjectFile **pFile );
  263. // returns true if removed, false otherwise (not found)
  264. bool RemoveFileFromFolder( const char *pFilename, CProjectFolder *pFolder );
  265. bool IsConfigurationNameValid( const char *pConfigName );
  266. void SetGUID( const char *pOutputFilename );
  267. configKeyword_e SetPS3VisualStudioIntegrationType( configKeyword_e eKeyword );
  268. void ApplyInternalPreprocessorDefinitions();
  269. private:
  270. configKeyword_e m_nActivePropertySection;
  271. CGeneratorDefinition *m_pGeneratorDefinition;
  272. CDebuggingTool *m_pDebuggingTool;
  273. CCompilerTool *m_pCompilerTool;
  274. CLibrarianTool *m_pLibrarianTool;
  275. CLinkerTool *m_pLinkerTool;
  276. CManifestTool *m_pManifestTool;
  277. CXMLDocGenTool *m_pXMLDocGenTool;
  278. CBrowseInfoTool *m_pBrowseInfoTool;
  279. CResourcesTool *m_pResourcesTool;
  280. CPreBuildEventTool *m_pPreBuildEventTool;
  281. CPreLinkEventTool *m_pPreLinkEventTool;
  282. CPostBuildEventTool *m_pPostBuildEventTool;
  283. CCustomBuildTool *m_pCustomBuildTool;
  284. CXboxImageTool *m_pXboxImageTool;
  285. CXboxDeploymentTool *m_pXboxDeploymentTool;
  286. CProjectConfiguration *m_pConfig;
  287. CProjectConfiguration *m_pFileConfig;
  288. CProjectFile *m_pProjectFile;
  289. CSimplePointerStack< CProjectFolder*, CProjectFolder*, 128 > m_spFolderStack;
  290. CSimplePointerStack< CCompilerTool*, CCompilerTool*, 128 > m_spCompilerStack;
  291. CSimplePointerStack< CCustomBuildTool*, CCustomBuildTool*, 128 > m_spCustomBuildToolStack;
  292. CUtlString m_ProjectName;
  293. CUtlString m_OutputFilename;
  294. CProjectFolder *m_pRootFolder;
  295. CUtlVector< CProjectConfiguration* > m_RootConfigurations;
  296. // primary file dictionary
  297. CUtlRBTree< CProjectFile*, int > m_FileDictionary;
  298. CUtlString m_GUIDString;
  299. IVCProjWriter *m_pVCProjWriter;
  300. // ps3 visual studio integration
  301. PS3VSIType_e m_VSIType;
  302. };
  303. #endif // VCPROJGENERATOR_H