projectGenUtils.inc 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  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. /// Has a preprocessor directive been defined?
  232. function isDefined( $d )
  233. {
  234. return T3D_Generator::isDefined( $d );
  235. }
  236. function setProjectGUID( $guid )
  237. {
  238. T3D_Generator::setProjectGUID( $guid );
  239. }
  240. function setProjectModuleDefinitionFile( $mdef )
  241. {
  242. T3D_Generator::setProjectModuleDefinitionFile( $mdef );
  243. }
  244. function addProjectLibDir( $dir )
  245. {
  246. T3D_Generator::addProjectLibDir( $dir );
  247. }
  248. function addProjectLibInput( $lib_name, $libDebug = null )
  249. {
  250. T3D_Generator::addProjectLibInput( $lib_name, $libDebug );
  251. }
  252. function addProjectIgnoreDefaultLib( $lib )
  253. {
  254. T3D_Generator::addProjectIgnoreDefaultLib( $lib );
  255. }
  256. function copyFileToProject( $sourcePath, $projPath )
  257. {
  258. T3D_Generator::copyFileToProject( $sourcePath, $projPath );
  259. }
  260. function addProjectDependency( $pd )
  261. {
  262. T3D_Generator::addProjectDependency( $pd );
  263. }
  264. function removeProjectDependency( $pd )
  265. {
  266. T3D_Generator::removeProjectDependency( $pd );
  267. }
  268. function addProjectReference( $refName, $version = "" )
  269. {
  270. T3D_Generator::addProjectReference( $refName, $version );
  271. }
  272. // disable a specific project compiler warning
  273. function disableProjectWarning( $warning )
  274. {
  275. T3D_Generator::disableProjectWarning( $warning );
  276. }
  277. function setGameProjectName($name)
  278. {
  279. T3D_Generator::setGameProjectName($name);
  280. }
  281. function getGameProjectName()
  282. {
  283. return T3D_Generator::getGameProjectName();
  284. }
  285. function setToolBuild($tb)
  286. {
  287. T3D_Generator::setToolBuild($tb);
  288. }
  289. function getToolBuild()
  290. {
  291. return T3D_Generator::getToolBuild();
  292. }
  293. function setWatermarkBuild($wb)
  294. {
  295. T3D_Generator::setWatermarkBuild($wb);
  296. }
  297. function getWatermarkBuild()
  298. {
  299. return T3D_Generator::getWatermarkBuild();
  300. }
  301. function setPurchaseScreenBuild($psb)
  302. {
  303. T3D_Generator::setPurchaseScreenBuild($psb);
  304. }
  305. function getPurchaseScreenBuild()
  306. {
  307. return T3D_Generator::getPurchaseScreenBuild();
  308. }
  309. function setDemoBuild($db)
  310. {
  311. T3D_Generator::setDemoBuild($db);
  312. }
  313. function getDemoBuild()
  314. {
  315. return T3D_Generator::getDemoBuild();
  316. }
  317. function setObjectLimitBuild($olb)
  318. {
  319. T3D_Generator::setObjectLimitBuild($olb);
  320. }
  321. function getObjectLimitBuild()
  322. {
  323. return T3D_Generator::getObjectLimitBuild();
  324. }
  325. function setTimeOutBuild($tob)
  326. {
  327. T3D_Generator::setTimeOutBuild($tob);
  328. }
  329. function getTimeOutBuild()
  330. {
  331. return T3D_Generator::getTimeOutBuild();
  332. }
  333. function inProjectConfig()
  334. {
  335. return T3D_Generator::inProjectConfig();
  336. }
  337. // On Windows, 1 - Console, 2 - Windows
  338. function setProjectSubSystem( $subSystem )
  339. {
  340. T3D_Generator::setProjectSubSystem( $subSystem );
  341. }
  342. // Sets whether to use /MT or /MD code generation/runtime on Windows
  343. // /MD plays better with multiple dynamic libraries in a project (and with certain libraries (like Qt)
  344. // /MD also generates smaller binaries as the runtime isn't included in each module, memory is handled consistently, etc
  345. // You must include or install via the redistributable package the appropriate VS runtime for end users.
  346. function setDLLRuntime ($val)
  347. {
  348. T3D_Generator::setDLLRuntime( $val );
  349. }
  350. //-------------------------------------------------------------------------------- UTIL
  351. // Some versions of PHP4 are unable to recusively create directories.
  352. // The version of PHP that is distributed with Mac OS 10.4 suffers from this.
  353. function mkdir_r($path, $mode)
  354. {
  355. if( @mkdir( $path, $mode ) or file_exists( $path ) )
  356. return true;
  357. return ( mkdir_r( dirname( $path ), $mode ) and mkdir( $path, $mode ) );
  358. }
  359. // This is used inside an if statement in the smarty templates
  360. function dontCompile( $string, $output )
  361. {
  362. // Skip marking header files to be excluded from the
  363. // build. It confuses VS2010 and it will not put the
  364. // file into the correct filter folder.
  365. //
  366. if ( preg_match( '#^.*\.(h|hpp|hh|inc)$#i', $string ) )
  367. return false;
  368. if( !is_array( $output->dont_compile_patterns ) )
  369. return false;
  370. foreach( $output->dont_compile_patterns as $pattern )
  371. if( preg_match( $pattern, $string ) )
  372. return true;
  373. return false;
  374. }
  375. /// Generates and returns a randomly generated uuid in the form:
  376. ///
  377. /// {xxxxxxxx-xxxx-4xxx-Yxxx-xxxxxxxxxxxx}
  378. ///
  379. /// Where Y is either 8, 9, A, or B. This is known as
  380. /// a v4 UUID. See...
  381. ///
  382. /// http://en.wikipedia.org/wiki/Universally_Unique_Identifier#Version_4_.28random.29
  383. ///
  384. function gen_uuid()
  385. {
  386. return sprintf( '{%04x%04x-%04x-%04x-%04x-%04x%04x%04x}',
  387. // 32 bits for "time_low"
  388. mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
  389. // 16 bits for "time_mid"
  390. mt_rand( 0, 0xffff ),
  391. // 16 bits for "time_hi_and_version",
  392. // four most significant bits holds version number 4
  393. mt_rand( 0, 0x0fff ) | 0x4000,
  394. // 16 bits, 8 bits for "clk_seq_hi_res",
  395. // 8 bits for "clk_seq_low",
  396. // two most significant bits holds zero and one for variant DCE1.1
  397. mt_rand( 0, 0x3fff ) | 0x8000,
  398. // 48 bits for "node"
  399. mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff )
  400. );
  401. }
  402. ?>