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.

345 lines
8.7 KiB

  1. //========= Copyright � 1996-2006, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: VPC
  4. //
  5. //=====================================================================================//
  6. #include "vpc.h"
  7. #define PROPERTYNAME( X, Y ) { X##_##Y, #X, #Y },
  8. static PropertyName_t s_Win32PropertyNames[] =
  9. {
  10. #include "projectgenerator_win32.inc"
  11. { -1, NULL, NULL }
  12. };
  13. IBaseProjectGenerator* GetWin32ProjectGenerator()
  14. {
  15. static CProjectGenerator_Win32 *s_pProjectGenerator = NULL;
  16. if ( !s_pProjectGenerator )
  17. {
  18. s_pProjectGenerator = new CProjectGenerator_Win32();
  19. }
  20. return s_pProjectGenerator->GetProjectGenerator();
  21. }
  22. CProjectGenerator_Win32::CProjectGenerator_Win32()
  23. {
  24. m_pVCProjGenerator = new CVCProjGenerator();
  25. m_pVCProjGenerator->SetupGeneratorDefinition( this, "win32_2005.def", s_Win32PropertyNames );
  26. }
  27. bool CProjectGenerator_Win32::WriteFile( CProjectFile *pFile )
  28. {
  29. m_XMLWriter.PushNode( "File" );
  30. m_XMLWriter.Write( CFmtStrMax( "RelativePath=\"%s\"", pFile->m_Name.Get() ) );
  31. m_XMLWriter.Write( ">" );
  32. for ( int i = 0; i < pFile->m_Configs.Count(); i++ )
  33. {
  34. if ( !WriteConfiguration( pFile->m_Configs[i] ) )
  35. return false;
  36. }
  37. m_XMLWriter.PopNode( true );
  38. return true;
  39. }
  40. bool CProjectGenerator_Win32::WriteFolder( CProjectFolder *pFolder )
  41. {
  42. m_XMLWriter.PushNode( "Filter" );
  43. m_XMLWriter.Write( CFmtStrMax( "Name=\"%s\"", pFolder->m_Name.Get() ) );
  44. m_XMLWriter.Write( ">" );
  45. for ( int iIndex = pFolder->m_Files.Head(); iIndex != pFolder->m_Files.InvalidIndex(); iIndex = pFolder->m_Files.Next( iIndex ) )
  46. {
  47. if ( !WriteFile( pFolder->m_Files[iIndex] ) )
  48. return false;
  49. }
  50. for ( int iIndex = pFolder->m_Folders.Head(); iIndex != pFolder->m_Folders.InvalidIndex(); iIndex = pFolder->m_Folders.Next( iIndex ) )
  51. {
  52. if ( !WriteFolder( pFolder->m_Folders[iIndex] ) )
  53. return false;
  54. }
  55. m_XMLWriter.PopNode( true );
  56. return true;
  57. }
  58. bool CProjectGenerator_Win32::WriteConfiguration( CProjectConfiguration *pConfig )
  59. {
  60. if ( pConfig->m_bIsFileConfig )
  61. {
  62. m_XMLWriter.PushNode( "FileConfiguration" );
  63. }
  64. else
  65. {
  66. m_XMLWriter.PushNode( "Configuration" );
  67. }
  68. const char *pOutputName = "???";
  69. if ( !V_stricmp( pConfig->m_Name.Get(), "debug" ) )
  70. {
  71. pOutputName = "Debug|Win32";
  72. }
  73. else if ( !V_stricmp( pConfig->m_Name.Get(), "release" ) )
  74. {
  75. pOutputName = "Release|Win32";
  76. }
  77. else if ( !V_stricmp( pConfig->m_Name.Get(), "profile" ) )
  78. {
  79. pOutputName = "Profile|Win32";
  80. }
  81. else if ( !V_stricmp( pConfig->m_Name.Get(), "retail" ) )
  82. {
  83. pOutputName = "Retail|Win32";
  84. }
  85. else
  86. {
  87. return false;
  88. }
  89. m_XMLWriter.Write( CFmtStrMax( "Name=\"%s\"", pOutputName ) );
  90. // write configuration properties
  91. for ( int i = 0; i < pConfig->m_PropertyStates.m_PropertiesInOutputOrder.Count(); i++ )
  92. {
  93. int sortedIndex = pConfig->m_PropertyStates.m_PropertiesInOutputOrder[i];
  94. WriteProperty( &pConfig->m_PropertyStates.m_Properties[sortedIndex] );
  95. }
  96. m_XMLWriter.Write( ">" );
  97. if ( !WriteTool( "VCPreBuildEventTool", pConfig->GetPreBuildEventTool() ) )
  98. return false;
  99. if ( !WriteTool( "VCCustomBuildTool", pConfig->GetCustomBuildTool() ) )
  100. return false;
  101. if ( !WriteNULLTool( "VCXMLDataGeneratorTool", pConfig ) )
  102. return false;
  103. if ( !WriteNULLTool( "VCWebServiceProxyGeneratorTool", pConfig ) )
  104. return false;
  105. if ( !WriteNULLTool( "VCMIDLTool", pConfig ) )
  106. return false;
  107. if ( !WriteTool( "VCCLCompilerTool", pConfig->GetCompilerTool() ) )
  108. return false;
  109. if ( !WriteNULLTool( "VCManagedResourceCompilerTool", pConfig ) )
  110. return false;
  111. if ( !WriteTool( "VCResourceCompilerTool", pConfig->GetResourcesTool() ) )
  112. return false;
  113. if ( !WriteTool( "VCPreLinkEventTool", pConfig->GetPreLinkEventTool() ) )
  114. return false;
  115. if ( !WriteTool( "VCLinkerTool", pConfig->GetLinkerTool() ) )
  116. return false;
  117. if ( !WriteTool( "VCLibrarianTool", pConfig->GetLibrarianTool() ) )
  118. return false;
  119. if ( !WriteNULLTool( "VCALinkTool", pConfig ) )
  120. return false;
  121. if ( !WriteTool( "VCManifestTool", pConfig->GetManifestTool() ) )
  122. return false;
  123. if ( !WriteTool( "VCXDCMakeTool", pConfig->GetXMLDocGenTool() ) )
  124. return false;
  125. if ( !WriteTool( "VCBscMakeTool", pConfig->GetBrowseInfoTool() ) )
  126. return false;
  127. if ( !WriteNULLTool( "VCFxCopTool", pConfig ) )
  128. return false;
  129. if ( !pConfig->GetLibrarianTool() )
  130. {
  131. if ( !WriteNULLTool( "VCAppVerifierTool", pConfig ) )
  132. return false;
  133. if ( !WriteNULLTool( "VCWebDeploymentTool", pConfig ) )
  134. return false;
  135. }
  136. if ( !WriteTool( "VCPostBuildEventTool", pConfig->GetPostBuildEventTool() ) )
  137. return false;
  138. m_XMLWriter.PopNode( true );
  139. return true;
  140. }
  141. bool CProjectGenerator_Win32::WriteToXML()
  142. {
  143. m_XMLWriter.PushNode( "VisualStudioProject" );
  144. m_XMLWriter.Write( "ProjectType=\"Visual C++\"" );
  145. m_XMLWriter.Write( "Version=\"8.00\"" );
  146. m_XMLWriter.Write( CFmtStrMax( "Name=\"%s\"", m_pVCProjGenerator->GetProjectName().Get() ) );
  147. m_XMLWriter.Write( CFmtStrMax( "ProjectGUID=\"%s\"", m_pVCProjGenerator->GetGUIDString().Get() ) );
  148. m_XMLWriter.Write( ">" );
  149. m_XMLWriter.PushNode( "Platforms" );
  150. m_XMLWriter.PushNode( "Platform" );
  151. m_XMLWriter.Write( "Name=\"Win32\"" );
  152. m_XMLWriter.PopNode( false );
  153. m_XMLWriter.PopNode( true );
  154. m_XMLWriter.PushNode( "ToolFiles" );
  155. m_XMLWriter.PopNode( true );
  156. CUtlVector< CUtlString > configurationNames;
  157. m_pVCProjGenerator->GetAllConfigurationNames( configurationNames );
  158. // write the root configurations
  159. m_XMLWriter.PushNode( "Configurations" );
  160. for ( int i = 0; i < configurationNames.Count(); i++ )
  161. {
  162. CProjectConfiguration *pConfiguration = NULL;
  163. if ( m_pVCProjGenerator->GetRootConfiguration( configurationNames[i].Get(), &pConfiguration ) )
  164. {
  165. if ( !WriteConfiguration( pConfiguration ) )
  166. return false;
  167. }
  168. }
  169. m_XMLWriter.PopNode( true );
  170. m_XMLWriter.PushNode( "References" );
  171. m_XMLWriter.PopNode( true );
  172. m_XMLWriter.PushNode( "Files" );
  173. CProjectFolder *pRootFolder = m_pVCProjGenerator->GetRootFolder();
  174. for ( int iIndex = pRootFolder->m_Folders.Head(); iIndex != pRootFolder->m_Folders.InvalidIndex(); iIndex = pRootFolder->m_Folders.Next( iIndex ) )
  175. {
  176. if ( !WriteFolder( pRootFolder->m_Folders[iIndex] ) )
  177. return false;
  178. }
  179. for ( int iIndex = pRootFolder->m_Files.Head(); iIndex != pRootFolder->m_Files.InvalidIndex(); iIndex = pRootFolder->m_Files.Next( iIndex ) )
  180. {
  181. if ( !WriteFile( pRootFolder->m_Files[iIndex] ) )
  182. return false;
  183. }
  184. m_XMLWriter.PopNode( true );
  185. m_XMLWriter.PopNode( true );
  186. return true;
  187. }
  188. bool CProjectGenerator_Win32::Save( const char *pOutputFilename )
  189. {
  190. if ( !m_XMLWriter.Open( pOutputFilename ) )
  191. return false;
  192. bool bValid = WriteToXML();
  193. m_XMLWriter.Close();
  194. return bValid;
  195. }
  196. bool CProjectGenerator_Win32::WriteNULLTool( const char *pToolName, const CProjectConfiguration *pConfig )
  197. {
  198. if ( pConfig->m_bIsFileConfig )
  199. return true;
  200. m_XMLWriter.PushNode( "Tool" );
  201. m_XMLWriter.Write( CFmtStr( "Name=\"%s\"", pToolName ) );
  202. m_XMLWriter.PopNode( false );
  203. return true;
  204. }
  205. bool CProjectGenerator_Win32::WriteTool( const char *pToolName, const CProjectTool *pProjectTool )
  206. {
  207. if ( !pProjectTool )
  208. {
  209. // not an error, some tools n/a for a config
  210. return true;
  211. }
  212. m_XMLWriter.PushNode( "Tool" );
  213. m_XMLWriter.Write( CFmtStr( "Name=\"%s\"", pToolName ) );
  214. for ( int i = 0; i < pProjectTool->m_PropertyStates.m_PropertiesInOutputOrder.Count(); i++ )
  215. {
  216. int sortedIndex = pProjectTool->m_PropertyStates.m_PropertiesInOutputOrder[i];
  217. WriteProperty( &pProjectTool->m_PropertyStates.m_Properties[sortedIndex] );
  218. }
  219. m_XMLWriter.PopNode( false );
  220. return true;
  221. }
  222. bool CProjectGenerator_Win32::WriteProperty( const PropertyState_t *pPropertyState, const char *pOutputName, const char *pOutputValue )
  223. {
  224. if ( !pPropertyState )
  225. {
  226. m_XMLWriter.Write( CFmtStrMax( "%s=\"%s\"", pOutputName, pOutputValue ) );
  227. return true;
  228. }
  229. if ( !pOutputName )
  230. {
  231. pOutputName = pPropertyState->m_pToolProperty->m_OutputString.Get();
  232. if ( !pOutputName[0] )
  233. {
  234. pOutputName = pPropertyState->m_pToolProperty->m_ParseString.Get();
  235. if ( pOutputName[0] == '$' )
  236. {
  237. pOutputName++;
  238. }
  239. }
  240. }
  241. if ( pPropertyState )
  242. {
  243. switch ( pPropertyState->m_pToolProperty->m_nType )
  244. {
  245. case PT_BOOLEAN:
  246. {
  247. bool bEnabled = Sys_StringToBool( pPropertyState->m_StringValue.Get() );
  248. if ( pPropertyState->m_pToolProperty->m_bInvertOutput )
  249. {
  250. bEnabled ^= 1;
  251. }
  252. m_XMLWriter.Write( CFmtStrMax( "%s=\"%s\"", pOutputName, bEnabled ? "true" : "false" ) );
  253. }
  254. break;
  255. case PT_STRING:
  256. m_XMLWriter.Write( CFmtStrMax( "%s=\"%s\"", pOutputName, m_XMLWriter.FixupXMLString( pPropertyState->m_StringValue.Get() ) ) );
  257. break;
  258. case PT_LIST:
  259. case PT_INTEGER:
  260. m_XMLWriter.Write( CFmtStrMax( "%s=\"%s\"", pOutputName, pPropertyState->m_StringValue.Get() ) );
  261. break;
  262. case PT_IGNORE:
  263. break;
  264. default:
  265. g_pVPC->VPCError( "CProjectGenerator_Win32: WriteProperty, %s - not implemented", pOutputName );
  266. }
  267. }
  268. return true;
  269. }