functions.pri 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. ###########################################################################################
  2. ## Created using Monkey Studio IDE v1.9.0.1 (1.9.0.1)
  3. ##
  4. ## Author : Filipe Azevedo aka Nox P@sNox <pasnox@gmail.com>
  5. ## Project : functions.pri
  6. ## FileName : functions.pri
  7. ## Date : 2012-07-28T13:13:40
  8. ## License : LGPL3
  9. ## Comment : Creating using Monkey Studio RAD
  10. ## Home Page : https://github.com/pasnox/qmake-extensions
  11. ##
  12. ## This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  13. ## WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  14. ##
  15. ###########################################################################################
  16. # Return a list of folders being absolute or relative depending of $$1
  17. # $$1: The path where to list folders ($$1 is included)
  18. # $$2: Optional parameter to forbid some filters
  19. defineReplace( getFolders ) {
  20. q_paths = $$1
  21. q_filters = $$2 .svn
  22. q_folders =
  23. for( q_path, q_paths ) {
  24. command = "ls -RQ1 \"$$q_path\" | grep \":\" | sed \"s/://g\" | sed \"s/'/\\\\\\'/g\""
  25. macx|win32:command = ls -R1 \"$$q_path\" | grep \":\" | sed \"s/://g\" | sed \"s/\'/\\\\\\\'/g\" | sed \"s/\\(.*\\)/\\\"\\1\\\"/g\"
  26. win32:!cb_win32:command = "for /D /R \"$$q_path\" %i in (*) do @echo \"%i\""
  27. _q_folders = $$system( $$command )
  28. _q_folders *= $$1
  29. _q_folders = $$replace( _q_folders, $$Q_BACK_SLASH, $$Q_SLASH )
  30. # loop paths
  31. for( q_folder, _q_folders ) {
  32. # check filters
  33. filtered = false
  34. for( q_filter, q_filters ) {
  35. result = $$find( q_folder, $$q_filter )
  36. !isEmpty( result ):filtered = true
  37. }
  38. #isEqual( filtered, false ):exists( $$q_folder ) {
  39. isEqual( filtered, false ) {
  40. q_folders *= $$q_folder
  41. }
  42. }
  43. }
  44. #message( Getting folders for $$q_paths: $$q_folders )
  45. return( $$q_folders )
  46. }
  47. # Identical to getFolders except that folders are returned relative to $$3
  48. # $$1: The path where to list folders ($$1 is included)
  49. # $$2: Make relative to $$2
  50. # $$3: Replace $$2 by $$3 in final list
  51. # $$4: Optional parameter to forbid some filters
  52. defineReplace( getRelativeFolders ) {
  53. q_folders = $$getFolders( $$1, $$4 )
  54. q_folders = $$replace( q_folders, $$re_escape( $$2 ), $$3 )
  55. #message( Getting relative folders for $$q_paths: $$q_folders )
  56. return( $$q_folders )
  57. }
  58. # Return the project build mode
  59. defineReplace( buildMode ) {
  60. CONFIG( debug, debug|release ) {
  61. return( debug )
  62. } else {
  63. return( release )
  64. }
  65. }
  66. # Return a generated target name according to build mode
  67. # $$1: Base target name
  68. # $$2: Optional build mode, if empty get using buildMode()
  69. defineReplace( targetForMode ) {
  70. q_target = $$1
  71. q_mode = $$2
  72. isEmpty( q_mode ):q_mode = $$buildMode()
  73. isEqual( q_mode, release ) {
  74. q_target = $$quote( $$q_target )
  75. } else {
  76. unix:q_target = $$quote( $$join( q_target, , , _debug ) )
  77. else:q_target = $$quote( $$join( q_target, , , d ) )
  78. }
  79. return( $$q_target )
  80. }
  81. # Set the project template name
  82. # $$1: Project template name
  83. defineTest( setTemplate ) {
  84. TEMPLATE = $$1
  85. export( TEMPLATE )
  86. }
  87. # Set project target name
  88. # $$1: Target name
  89. # $$: Optional build mode, if empty get using buildMode()
  90. defineTest( setTarget ) {
  91. TARGET = $$targetForMode( $$1, $$2 )
  92. export( TARGET )
  93. }
  94. # Set default directories for temporary files (object, rcc, ui, moc)
  95. # $$1: The temporary directory to use as a base
  96. defineTest( setTemporaryDirectories ) {
  97. q_mode = $$buildMode()
  98. OBJECTS_DIR = $$1/$${Q_TARGET_ARCH}/$${q_mode}/obj
  99. UI_DIR = $$1/$${Q_TARGET_ARCH}/$${q_mode}/ui
  100. MOC_DIR = $$1/$${Q_TARGET_ARCH}/$${q_mode}/moc
  101. RCC_DIR = $$1/$${Q_TARGET_ARCH}/$${q_mode}/rcc
  102. export( OBJECTS_DIR )
  103. export( UI_DIR )
  104. export( MOC_DIR )
  105. export( RCC_DIR )
  106. }
  107. # Set project target directory
  108. # $$1: The directory where to generate the project target
  109. defineTest( setTargetDirectory ) {
  110. DESTDIR = $$1
  111. export( DESTDIR )
  112. win32|cb_win32:CONFIG( shared ) {
  113. DLLDESTDIR = $$1
  114. export( DLLDESTDIR )
  115. }
  116. }
  117. # Mimic an auto generated file where the content is replaced with qmake variable values
  118. # $$1 = Template source file path
  119. # $$2 = Generated target file path
  120. defineTest( autoGenerateFile ) {
  121. !build_pass {
  122. generator.source = $${1}
  123. generator.target = $${2}
  124. # Replace slashes by back slashes on native windows host
  125. win32:!cb_win32 {
  126. generator.source = $$replace( generator.source, $${Q_SLASH}, $${Q_BACK_SLASH} )
  127. generator.target = $$replace( generator.target, $${Q_SLASH}, $${Q_BACK_SLASH} )
  128. }
  129. # Delete existing file
  130. exists( $${generator.target} ) {
  131. win32:!cb_win32 {
  132. system( "del $${generator.target}" )
  133. } else {
  134. system( "rm $${generator.target}" )
  135. }
  136. }
  137. # create target path if needed
  138. path = $$dirname( generator.target )
  139. !isEmpty( path ):!exists( $${path} ) {
  140. win32:!cb_win32 {
  141. system( "mkdir $${path}" )
  142. } else {
  143. system( "mkdir -p $${path}" )
  144. }
  145. }
  146. # Get template content
  147. generator.content = $$cat( $${generator.source}, false )
  148. # Find template variables name
  149. #generator.variables = $$find( generator.content, "\\$\\$[^\s\$]+" )
  150. # Generate the find variables command
  151. generator.commands = "grep -E -i -o '\\$\\$[$${Q_OPENING_BRACE}]?[[:alnum:]_-]+[$${Q_CLOSING_BRACE}]?' $${generator.source}"
  152. win32:!cb_win32:generator.commands = "grep command not available."
  153. # Get template variables name
  154. generator.variables = $$system( $${generator.commands} )
  155. #message( cmd: $${generator.commands} )
  156. #message( Variables: $$generator.variables )
  157. # Transform each variable
  158. for( variable, generator.variables ) {
  159. name = $${variable}
  160. name = $$replace( name, $${Q_QUOTE}, "" )
  161. name = $$replace( name, $${Q_DOLLAR}, "" )
  162. name = $$replace( name, $${Q_OPENING_BRACE}, "" )
  163. name = $$replace( name, $${Q_CLOSING_BRACE}, "" )
  164. generator.content = $$replace( generator.content, $${Q_DOLLAR}$${Q_DOLLAR}$${Q_OPENING_BRACE}$${name}$${Q_CLOSING_BRACE}, $$eval( $${name} ) )
  165. generator.content = $$replace( generator.content, $${Q_DOLLAR}$${Q_DOLLAR}$${name}, $$eval( $${name} ) )
  166. #message( --- Found: $$variable ($$name) - $$eval( $$name ) )
  167. }
  168. # escape characters that are special for windows echo command
  169. win32:!cb_win32 {
  170. generator.content = $$replace( generator.content, "\\^", "^^" )
  171. generator.content = $$replace( generator.content, "<", "^<" )
  172. generator.content = $$replace( generator.content, ">", "^>" )
  173. generator.content = $$replace( generator.content, "\\|", "^|" )
  174. generator.content = $$replace( generator.content, "&", "^&" )
  175. # these should be escaped too but qmake values can't be ( or ) so we can't replace...
  176. #generator.content = $$replace( generator.content, "\\(", "^(" )
  177. #generator.content = $$replace( generator.content, "\\)", "^)" )
  178. } else {
  179. #mac:generator.content = $$replace( generator.content, $${Q_BACK_SLASH}, $${Q_BACK_SLASH}$${Q_BACK_SLASH}$${Q_BACK_SLASH} )
  180. #else:generator.content = $$replace( generator.content, $${Q_BACK_SLASH}$${Q_BACK_SLASH}, $${Q_BACK_SLASH}$${Q_BACK_SLASH}$${Q_BACK_SLASH} )
  181. generator.content = $$replace( generator.content, $${Q_BACK_SLASH}$${Q_BACK_SLASH}, $${Q_BACK_SLASH}$${Q_BACK_SLASH}$${Q_BACK_SLASH} )
  182. generator.content = $$replace( generator.content, $${Q_QUOTE}, $${Q_BACK_SLASH}$${Q_QUOTE} )
  183. }
  184. message( Generating $${generator.target}... )
  185. win32:!cb_win32 {
  186. generator.content = $$replace( generator.content, "\\n", ">> $${generator.target} && echo." )
  187. generator.commands = "echo ^ $${generator.content} >> $${generator.target}"
  188. } else {
  189. generator.commands = "echo \" $${generator.content}\" > $${generator.target}"
  190. }
  191. system( $${generator.commands} )
  192. }
  193. }
  194. defineTest( isShadowBuild ) {
  195. q_makefile_pwd = $${_PRO_FILE_PWD_}
  196. q_out_makefile_pwd = $${OUT_PWD}
  197. isEqual( q_makefile_pwd, $${q_out_makefile_pwd} ) {
  198. return( false )
  199. } else {
  200. return( true )
  201. }
  202. }