XCBuildConfiguration.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. using UnityEngine;
  2. using System.Collections;
  3. namespace cn.sharesdk.unity3d.sdkporter
  4. {
  5. public class XCBuildConfiguration : PBXObject
  6. {
  7. protected const string BUILDSETTINGS_KEY = "buildSettings";
  8. protected const string HEADER_SEARCH_PATHS_KEY = "HEADER_SEARCH_PATHS";
  9. protected const string LIBRARY_SEARCH_PATHS_KEY = "LIBRARY_SEARCH_PATHS";
  10. protected const string FRAMEWORK_SEARCH_PATHS_KEY = "FRAMEWORK_SEARCH_PATHS";
  11. protected const string OTHER_C_FLAGS_KEY = "OTHER_CFLAGS";
  12. protected const string OTHER_LD_FLAGS_KEY = "OTHER_LDFLAGS";
  13. protected const string GCC_ENABLE_CPP_EXCEPTIONS_KEY = "GCC_ENABLE_CPP_EXCEPTIONS";
  14. protected const string GCC_ENABLE_OBJC_EXCEPTIONS_KEY = "GCC_ENABLE_OBJC_EXCEPTIONS";
  15. public XCBuildConfiguration( string guid, PBXDictionary dictionary ) : base( guid, dictionary )
  16. {
  17. }
  18. public PBXDictionary buildSettings {
  19. get {
  20. if( ContainsKey( BUILDSETTINGS_KEY ) )
  21. return (PBXDictionary)_data[BUILDSETTINGS_KEY];
  22. return null;
  23. }
  24. }
  25. protected bool AddSearchPaths( string path, string key, bool recursive = true )
  26. {
  27. PBXList paths = new PBXList();
  28. paths.Add( path );
  29. return AddSearchPaths( paths, key, recursive );
  30. }
  31. protected bool AddSearchPaths( PBXList paths, string key, bool recursive = true )
  32. {
  33. bool modified = false;
  34. if( !ContainsKey( BUILDSETTINGS_KEY ) )
  35. this.Add( BUILDSETTINGS_KEY, new PBXDictionary() );
  36. foreach( string path in paths ) {
  37. string currentPath = path;
  38. if( recursive && !path.EndsWith( "/**" ) )
  39. currentPath += "/**";
  40. // Debug.Log( "adding: " + currentPath );
  41. if( !((PBXDictionary)_data[BUILDSETTINGS_KEY]).ContainsKey( key ) ) {
  42. ((PBXDictionary)_data[BUILDSETTINGS_KEY]).Add( key, new PBXList() );
  43. }
  44. else if( ((PBXDictionary)_data[BUILDSETTINGS_KEY])[key] is string ) {
  45. PBXList list = new PBXList();
  46. list.Add( ((PBXDictionary)_data[BUILDSETTINGS_KEY])[key] );
  47. ((PBXDictionary)_data[BUILDSETTINGS_KEY])[key] = list;
  48. }
  49. currentPath = "\\\"" + currentPath + "\\\"";
  50. if( !((PBXList)((PBXDictionary)_data[BUILDSETTINGS_KEY])[key]).Contains( currentPath ) ) {
  51. ((PBXList)((PBXDictionary)_data[BUILDSETTINGS_KEY])[key]).Add( currentPath );
  52. modified = true;
  53. }
  54. }
  55. return modified;
  56. }
  57. public bool AddHeaderSearchPaths( PBXList paths, bool recursive = true )
  58. {
  59. return this.AddSearchPaths( paths, HEADER_SEARCH_PATHS_KEY, recursive );
  60. }
  61. public bool AddLibrarySearchPaths( PBXList paths, bool recursive = true )
  62. {
  63. return this.AddSearchPaths( paths, LIBRARY_SEARCH_PATHS_KEY, recursive );
  64. }
  65. public bool AddFrameworkSearchPaths(PBXList paths, bool recursive = true)
  66. {
  67. return this.AddSearchPaths(paths, FRAMEWORK_SEARCH_PATHS_KEY, recursive);
  68. }
  69. public bool AddOtherCFlags( string flag )
  70. {
  71. //Debug.Log( "INIZIO 1" );
  72. PBXList flags = new PBXList();
  73. flags.Add( flag );
  74. return AddOtherCFlags( flags );
  75. }
  76. public bool AddOtherCFlags( PBXList flags )
  77. {
  78. //Debug.Log( "INIZIO 2" );
  79. bool modified = false;
  80. if( !ContainsKey( BUILDSETTINGS_KEY ) )
  81. this.Add( BUILDSETTINGS_KEY, new PBXDictionary() );
  82. foreach( string flag in flags ) {
  83. if( !((PBXDictionary)_data[BUILDSETTINGS_KEY]).ContainsKey( OTHER_C_FLAGS_KEY ) ) {
  84. ((PBXDictionary)_data[BUILDSETTINGS_KEY]).Add( OTHER_C_FLAGS_KEY, new PBXList() );
  85. }
  86. else if ( ((PBXDictionary)_data[BUILDSETTINGS_KEY])[ OTHER_C_FLAGS_KEY ] is string ) {
  87. string tempString = (string)((PBXDictionary)_data[BUILDSETTINGS_KEY])[OTHER_C_FLAGS_KEY];
  88. ((PBXDictionary)_data[BUILDSETTINGS_KEY])[ OTHER_C_FLAGS_KEY ] = new PBXList();
  89. ((PBXList)((PBXDictionary)_data[BUILDSETTINGS_KEY])[OTHER_C_FLAGS_KEY]).Add( tempString );
  90. }
  91. if( !((PBXList)((PBXDictionary)_data[BUILDSETTINGS_KEY])[OTHER_C_FLAGS_KEY]).Contains( flag ) ) {
  92. ((PBXList)((PBXDictionary)_data[BUILDSETTINGS_KEY])[OTHER_C_FLAGS_KEY]).Add( flag );
  93. modified = true;
  94. }
  95. }
  96. return modified;
  97. }
  98. public bool AddOtherLDFlags( string flag )
  99. {
  100. //Debug.Log( "INIZIO A" );
  101. PBXList flags = new PBXList();
  102. flags.Add( flag );
  103. return AddOtherLDFlags( flags );
  104. }
  105. public bool AddOtherLDFlags( PBXList flags )
  106. {
  107. //Debug.Log( "INIZIO B" );
  108. bool modified = false;
  109. if( !ContainsKey( BUILDSETTINGS_KEY ) )
  110. this.Add( BUILDSETTINGS_KEY, new PBXDictionary() );
  111. foreach( string flag in flags ) {
  112. if( !((PBXDictionary)_data[BUILDSETTINGS_KEY]).ContainsKey( OTHER_LD_FLAGS_KEY ) ) {
  113. ((PBXDictionary)_data[BUILDSETTINGS_KEY]).Add( OTHER_LD_FLAGS_KEY, new PBXList() );
  114. }
  115. else if ( ((PBXDictionary)_data[BUILDSETTINGS_KEY])[ OTHER_LD_FLAGS_KEY ] is string ) {
  116. string tempString = (string)((PBXDictionary)_data[BUILDSETTINGS_KEY])[OTHER_LD_FLAGS_KEY];
  117. ((PBXDictionary)_data[BUILDSETTINGS_KEY])[ OTHER_LD_FLAGS_KEY ] = new PBXList();
  118. ((PBXList)((PBXDictionary)_data[BUILDSETTINGS_KEY])[OTHER_LD_FLAGS_KEY]).Add( tempString );
  119. }
  120. if( !((PBXList)((PBXDictionary)_data[BUILDSETTINGS_KEY])[OTHER_LD_FLAGS_KEY]).Contains( flag ) ) {
  121. ((PBXList)((PBXDictionary)_data[BUILDSETTINGS_KEY])[OTHER_LD_FLAGS_KEY]).Add( flag );
  122. modified = true;
  123. }
  124. }
  125. return modified;
  126. }
  127. public bool GccEnableCppExceptions (string value)
  128. {
  129. if (!ContainsKey (BUILDSETTINGS_KEY))
  130. this.Add (BUILDSETTINGS_KEY, new PBXDictionary ());
  131. ((PBXDictionary)_data [BUILDSETTINGS_KEY])[GCC_ENABLE_CPP_EXCEPTIONS_KEY] = value;
  132. return true;
  133. }
  134. public bool GccEnableObjCExceptions (string value)
  135. {
  136. if (!ContainsKey (BUILDSETTINGS_KEY))
  137. this.Add (BUILDSETTINGS_KEY, new PBXDictionary ());
  138. ((PBXDictionary)_data [BUILDSETTINGS_KEY])[GCC_ENABLE_OBJC_EXCEPTIONS_KEY] = value;
  139. return true;
  140. }
  141. // class XCBuildConfiguration(PBXType):
  142. // def add_search_paths(self, paths, base, key, recursive=True):
  143. // modified = False
  144. //
  145. // if not isinstance(paths, list):
  146. // paths = [paths]
  147. //
  148. // if not self.has_key(base):
  149. // self[base] = PBXDict()
  150. //
  151. // for path in paths:
  152. // if recursive and not path.endswith('/**'):
  153. // path = os.path.join(path, '**')
  154. //
  155. // if not self[base].has_key(key):
  156. // self[base][key] = PBXList()
  157. // elif isinstance(self[base][key], basestring):
  158. // self[base][key] = PBXList(self[base][key])
  159. //
  160. // if self[base][key].add('\\"%s\\"' % path):
  161. // modified = True
  162. //
  163. // return modified
  164. //
  165. // def add_header_search_paths(self, paths, recursive=True):
  166. // return self.add_search_paths(paths, 'buildSettings', 'HEADER_SEARCH_PATHS', recursive=recursive)
  167. //
  168. // def add_library_search_paths(self, paths, recursive=True):
  169. // return self.add_search_paths(paths, 'buildSettings', 'LIBRARY_SEARCH_PATHS', recursive=recursive)
  170. //
  171. // def add_other_cflags(self, flags):
  172. // modified = False
  173. //
  174. // base = 'buildSettings'
  175. // key = 'OTHER_CFLAGS'
  176. //
  177. // if isinstance(flags, basestring):
  178. // flags = PBXList(flags)
  179. //
  180. // if not self.has_key(base):
  181. // self[base] = PBXDict()
  182. //
  183. // for flag in flags:
  184. //
  185. // if not self[base].has_key(key):
  186. // self[base][key] = PBXList()
  187. // elif isinstance(self[base][key], basestring):
  188. // self[base][key] = PBXList(self[base][key])
  189. //
  190. // if self[base][key].add(flag):
  191. // self[base][key] = [e for e in self[base][key] if e]
  192. // modified = True
  193. //
  194. // return modified
  195. }
  196. }