projectGenUtils.inc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500
  1. <?php
  2. //-----------------------------------------------------------------------------
  3. // Copyright (c) 2012 GarageGames, LLC
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to
  7. // deal in the Software without restriction, including without limitation the
  8. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9. // sell copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. // IN THE SOFTWARE.
  22. //-----------------------------------------------------------------------------
  23. //--------------------------------------------------------------------------------
  24. //
  25. // This file is now the 'API' which just wraps all the internal stuff nicely.
  26. //
  27. //--------------------------------------------------------------------------------
  28. function beginProject($name, $sharedConfig)
  29. {
  30. // Set the game project name, this is what your game's exe/dll will be called
  31. setGameProjectName($name);
  32. if (T3D_Generator::$platform == "win32" && $sharedConfig)
  33. beginSolutionConfig( $name, '{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}' );
  34. }
  35. function endProject($sharedConfig)
  36. {
  37. if (T3D_Generator::$platform == "win32" && $sharedConfig)
  38. endSolutionConfig();
  39. }
  40. function beginSolutionConfig( $name, $guid = '' )
  41. {
  42. T3D_Generator::beginSolution( $name, $guid );
  43. }
  44. function addSolutionProjectRef( $pname )
  45. {
  46. T3D_Generator::addSolutionProjectRef( $pname );
  47. }
  48. // Add a reference to an external project, this is used for WPF projects currently
  49. // as adding all the various designer/xaml/stuff to the project generator is probably overkill
  50. // However, it is nice to not have to add the project to the solution whenever you run the project generator
  51. function addSolutionProjectRefExt( $pname, $ppath, $pguid )
  52. {
  53. T3D_Generator::addSolutionProjectRefExt( $pname, $ppath, $pguid );
  54. }
  55. function endSolutionConfig()
  56. {
  57. T3D_Generator::endSolution();
  58. }
  59. function setPlatform( $platform )
  60. {
  61. echo(' - Setting platform to: ' . $platform . "\n");
  62. T3D_Generator::$platform = $platform;
  63. }
  64. function includeLib( $libName )
  65. {
  66. //echo( "GLP: " . T3D_Generator::getGeneratorLibsPath() . $libName . "\n" );
  67. T3D_Generator::includeLib( $libName );
  68. }
  69. function includeModule( $modName )
  70. {
  71. require( T3D_Generator::getGeneratorModulesPath() . $modName . '.inc' );
  72. }
  73. function beginActiveXConfig( $lib_name, $guid = '', $gameDir = 'game', $output_name = '' )
  74. {
  75. T3D_Generator::beginActiveXConfig( $lib_name, $guid, $gameDir, $output_name );
  76. }
  77. function endActiveXConfig()
  78. {
  79. T3D_Generator::endActiveXConfig();
  80. }
  81. function beginSafariConfig( $lib_name, $guid = '', $gameDir = 'game', $output_name = '' )
  82. {
  83. T3D_Generator::beginSafariConfig( $lib_name, $guid, $gameDir, $output_name );
  84. }
  85. function endSafariConfig()
  86. {
  87. T3D_Generator::endSafariConfig();
  88. }
  89. function beginSharedLibConfig( $lib_name, $guid = '', $gameDir = 'game', $output_name = '' )
  90. {
  91. T3D_Generator::beginSharedLibConfig( $lib_name, $guid, $gameDir, $output_name );
  92. }
  93. function endSharedLibConfig()
  94. {
  95. T3D_Generator::endSharedLibConfig();
  96. }
  97. function beginNPPluginConfig( $lib_name, $guid = '', $gameDir = 'game', $output_name = '' )
  98. {
  99. T3D_Generator::beginNPPluginConfig( $lib_name, $guid, $gameDir, $output_name );
  100. }
  101. function endNPPluginConfig()
  102. {
  103. T3D_Generator::endNPPluginConfig();
  104. }
  105. function beginLibConfig( $lib_name, $guid = '', $gameDir = 'game', $output_name = '' )
  106. {
  107. T3D_Generator::beginLibConfig( $lib_name, $guid, $gameDir, $output_name );
  108. }
  109. function endLibConfig()
  110. {
  111. T3D_Generator::endLibConfig();
  112. }
  113. function beginAppConfig( $app_name, $guid = '', $game_dir = 'game', $output_name = '' )
  114. {
  115. T3D_Generator::beginAppConfig( $app_name, $guid, $game_dir, $output_name );
  116. }
  117. function endAppConfig()
  118. {
  119. T3D_Generator::endAppConfig();
  120. }
  121. function beginSharedAppConfig( $app_name, $guid = '', $game_dir = 'game', $output_name = '' )
  122. {
  123. T3D_Generator::beginSharedAppConfig( $app_name, $guid, $game_dir, $output_name );
  124. }
  125. function endSharedAppConfig()
  126. {
  127. T3D_Generator::endSharedAppConfig();
  128. }
  129. function beginCSProjectConfig( $app_name, $guid = '', $game_dir = 'game', $output_name = '' )
  130. {
  131. T3D_Generator::beginCSProjectConfig( $app_name, $guid, $game_dir, $output_name );
  132. }
  133. function endCSProjectConfig()
  134. {
  135. T3D_Generator::endCSProjectConfig();
  136. }
  137. ///////////////////////
  138. function beginModule( $name )
  139. {
  140. T3D_Generator::beginModule( $name );
  141. }
  142. function endModule()
  143. {
  144. T3D_Generator::endModule();
  145. }
  146. function addSrcDir( $dir, $recurse = false )
  147. {
  148. //echo( "ADD SRC DIR: " . $dir . "\n" );
  149. T3D_Generator::addSrcDir( $dir, $recurse );
  150. }
  151. function addSrcFile( $file )
  152. {
  153. //echo( "ADD SRC FILE: " . $file . "\n" );
  154. T3D_Generator::addSrcFile( $file );
  155. }
  156. function addEngineSrcDir( $dir )
  157. {
  158. //echo( "ADD ENGINE SRC DIR: " . getEngineSrcDir() . $dir . "\n" );
  159. addSrcDir( getEngineSrcDir() . $dir );
  160. }
  161. function addEngineSrcFile( $file )
  162. {
  163. //echo( "ADD SRC FIL: " . getEngineSrcDir() . $file . "\n" );
  164. addSrcFile( getEngineSrcDir() . $file );
  165. }
  166. function addLibSrcDir( $dir )
  167. {
  168. addSrcDir( T3D_Generator::getLibSrcDir() . $dir );
  169. }
  170. function addLibSrcFile( $file )
  171. {
  172. addSrcDir( T3D_Generator::getLibSrcDir() . $file );
  173. }
  174. function addLibIncludePath( $path )
  175. {
  176. // We need to make the include paths relative to the project file location!
  177. addIncludePath( getAppLibSrcDir() . $path );
  178. }
  179. function getAppLibSrcDir()
  180. {
  181. // We need to make the include paths relative to the project file location!
  182. return "../" . getLibSrcDir();
  183. }
  184. function addAppIncludePath( $path )
  185. {
  186. // We need to make the include paths relative to the project file location!
  187. addIncludePath( getAppEngineSrcDir() . $path );
  188. }
  189. function getAppEngineSrcDir()
  190. {
  191. // We need to make the include paths relative to the project file location!
  192. return "../" . getEngineSrcDir();
  193. }
  194. function getAppEngineBinDir()
  195. {
  196. // We need to make the include paths relative to the project file location!
  197. return "../" . getEngineBinDir();
  198. }
  199. function getEngineSrcDir()
  200. {
  201. return T3D_Generator::getEngineSrcDir();
  202. }
  203. function getLibSrcDir()
  204. {
  205. return T3D_Generator::getLibSrcDir();
  206. }
  207. function getEngineBinDir()
  208. {
  209. return T3D_Generator::getEngineBinDir();
  210. }
  211. function addIncludePath( $path )
  212. {
  213. //echo( "ADD INCLUDE: " . $path . "\n" );
  214. T3D_Generator::addIncludePath( $path );
  215. }
  216. /// Add a preprocessor directive/define
  217. function addProjectDefine( $d, $v = null )
  218. {
  219. T3D_Generator::addProjectDefine( $d, $v );
  220. }
  221. /// Add a list of defines in one call
  222. function addProjectDefines()
  223. {
  224. $args = func_get_args();
  225. $count = func_num_args();
  226. if( $count > 0 )
  227. T3D_Generator::addProjectDefines( $args );
  228. else
  229. echo( "addProjectDefines() - no arguments passed!" );
  230. }
  231. function setProjectGUID( $guid )
  232. {
  233. T3D_Generator::setProjectGUID( $guid );
  234. }
  235. function setProjectModuleDefinitionFile( $mdef )
  236. {
  237. T3D_Generator::setProjectModuleDefinitionFile( $mdef );
  238. }
  239. function addProjectLibDir( $dir )
  240. {
  241. T3D_Generator::addProjectLibDir( $dir );
  242. }
  243. function addProjectLibInput( $lib_name, $libDebug = null )
  244. {
  245. T3D_Generator::addProjectLibInput( $lib_name, $libDebug );
  246. }
  247. function addProjectIgnoreDefaultLib( $lib )
  248. {
  249. T3D_Generator::addProjectIgnoreDefaultLib( $lib );
  250. }
  251. function copyFileToProject( $sourcePath, $projPath )
  252. {
  253. T3D_Generator::copyFileToProject( $sourcePath, $projPath );
  254. }
  255. function addProjectDependency( $pd )
  256. {
  257. T3D_Generator::addProjectDependency( $pd );
  258. }
  259. function removeProjectDependency( $pd )
  260. {
  261. T3D_Generator::removeProjectDependency( $pd );
  262. }
  263. function addProjectReference( $refName, $version = "" )
  264. {
  265. T3D_Generator::addProjectReference( $refName, $version );
  266. }
  267. // disable a specific project compiler warning
  268. function disableProjectWarning( $warning )
  269. {
  270. T3D_Generator::disableProjectWarning( $warning );
  271. }
  272. function setGameProjectName($name)
  273. {
  274. T3D_Generator::setGameProjectName($name);
  275. }
  276. function getGameProjectName()
  277. {
  278. return T3D_Generator::getGameProjectName();
  279. }
  280. function setToolBuild($tb)
  281. {
  282. T3D_Generator::setToolBuild($tb);
  283. }
  284. function getToolBuild()
  285. {
  286. return T3D_Generator::getToolBuild();
  287. }
  288. function setWatermarkBuild($wb)
  289. {
  290. T3D_Generator::setWatermarkBuild($wb);
  291. }
  292. function getWatermarkBuild()
  293. {
  294. return T3D_Generator::getWatermarkBuild();
  295. }
  296. function setPurchaseScreenBuild($psb)
  297. {
  298. T3D_Generator::setPurchaseScreenBuild($psb);
  299. }
  300. function getPurchaseScreenBuild()
  301. {
  302. return T3D_Generator::getPurchaseScreenBuild();
  303. }
  304. function setDemoBuild($db)
  305. {
  306. T3D_Generator::setDemoBuild($db);
  307. }
  308. function getDemoBuild()
  309. {
  310. return T3D_Generator::getDemoBuild();
  311. }
  312. function setObjectLimitBuild($olb)
  313. {
  314. T3D_Generator::setObjectLimitBuild($olb);
  315. }
  316. function getObjectLimitBuild()
  317. {
  318. return T3D_Generator::getObjectLimitBuild();
  319. }
  320. function setTimeOutBuild($tob)
  321. {
  322. T3D_Generator::setTimeOutBuild($tob);
  323. }
  324. function getTimeOutBuild()
  325. {
  326. return T3D_Generator::getTimeOutBuild();
  327. }
  328. function inProjectConfig()
  329. {
  330. return T3D_Generator::inProjectConfig();
  331. }
  332. // On Windows, 1 - Console, 2 - Windows
  333. function setProjectSubSystem( $subSystem )
  334. {
  335. T3D_Generator::setProjectSubSystem( $subSystem );
  336. }
  337. // Sets whether to use /MT or /MD code generation/runtime on Windows
  338. // /MD plays better with multiple dynamic libraries in a project (and with certain libraries (like Qt)
  339. // /MD also generates smaller binaries as the runtime isn't included in each module, memory is handled consistently, etc
  340. // You must include or install via the redistributable package the appropriate VS runtime for end users.
  341. function setDLLRuntime ($val)
  342. {
  343. T3D_Generator::setDLLRuntime( $val );
  344. }
  345. //-------------------------------------------------------------------------------- UTIL
  346. // Some versions of PHP4 are unable to recusively create directories.
  347. // The version of PHP that is distributed with Mac OS 10.4 suffers from this.
  348. function mkdir_r($path, $mode)
  349. {
  350. if( @mkdir( $path, $mode ) or file_exists( $path ) )
  351. return true;
  352. return ( mkdir_r( dirname( $path ), $mode ) and mkdir( $path, $mode ) );
  353. }
  354. // This is used inside an if statement in the smarty templates
  355. function dontCompile( $string, $output )
  356. {
  357. // Skip marking header files to be excluded from the
  358. // build. It confuses VS2010 and it will not put the
  359. // file into the correct filter folder.
  360. //
  361. if ( preg_match( '#^.*\.(h|hpp|hh|inc)$#i', $string ) )
  362. return false;
  363. if( !is_array( $output->dont_compile_patterns ) )
  364. return false;
  365. foreach( $output->dont_compile_patterns as $pattern )
  366. if( preg_match( $pattern, $string ) )
  367. return true;
  368. return false;
  369. }
  370. /// Generates and returns a randomly generated uuid in the form:
  371. ///
  372. /// {xxxxxxxx-xxxx-4xxx-Yxxx-xxxxxxxxxxxx}
  373. ///
  374. /// Where Y is either 8, 9, A, or B. This is known as
  375. /// a v4 UUID. See...
  376. ///
  377. /// http://en.wikipedia.org/wiki/Universally_Unique_Identifier#Version_4_.28random.29
  378. ///
  379. function gen_uuid()
  380. {
  381. return sprintf( '{%04x%04x-%04x-%04x-%04x-%04x%04x%04x}',
  382. // 32 bits for "time_low"
  383. mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
  384. // 16 bits for "time_mid"
  385. mt_rand( 0, 0xffff ),
  386. // 16 bits for "time_hi_and_version",
  387. // four most significant bits holds version number 4
  388. mt_rand( 0, 0x0fff ) | 0x4000,
  389. // 16 bits, 8 bits for "clk_seq_hi_res",
  390. // 8 bits for "clk_seq_low",
  391. // two most significant bits holds zero and one for variant DCE1.1
  392. mt_rand( 0, 0x3fff ) | 0x8000,
  393. // 48 bits for "node"
  394. mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
  395. );
  396. }
  397. ?>