methods.py 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105
  1. import os
  2. from compat import iteritems
  3. def add_source_files(self, sources, filetype, lib_env=None, shared=False):
  4. import glob
  5. import string
  6. # if not lib_objects:
  7. if not lib_env:
  8. lib_env = self
  9. if type(filetype) == type(""):
  10. dir = self.Dir('.').abspath
  11. list = glob.glob(dir + "/" + filetype)
  12. for f in list:
  13. sources.append(self.Object(f))
  14. else:
  15. for f in filetype:
  16. sources.append(self.Object(f))
  17. class LegacyGLHeaderStruct:
  18. def __init__(self):
  19. self.vertex_lines = []
  20. self.fragment_lines = []
  21. self.uniforms = []
  22. self.attributes = []
  23. self.feedbacks = []
  24. self.fbos = []
  25. self.conditionals = []
  26. self.enums = {}
  27. self.texunits = []
  28. self.texunit_names = []
  29. self.ubos = []
  30. self.ubo_names = []
  31. self.vertex_included_files = []
  32. self.fragment_included_files = []
  33. self.reading = ""
  34. self.line_offset = 0
  35. self.vertex_offset = 0
  36. self.fragment_offset = 0
  37. def include_file_in_legacygl_header(filename, header_data, depth):
  38. fs = open(filename, "r")
  39. line = fs.readline()
  40. while(line):
  41. if (line.find("[vertex]") != -1):
  42. header_data.reading = "vertex"
  43. line = fs.readline()
  44. header_data.line_offset += 1
  45. header_data.vertex_offset = header_data.line_offset
  46. continue
  47. if (line.find("[fragment]") != -1):
  48. header_data.reading = "fragment"
  49. line = fs.readline()
  50. header_data.line_offset += 1
  51. header_data.fragment_offset = header_data.line_offset
  52. continue
  53. while(line.find("#include ") != -1):
  54. includeline = line.replace("#include ", "").strip()[1:-1]
  55. import os.path
  56. included_file = os.path.relpath(os.path.dirname(filename) + "/" + includeline)
  57. if (not included_file in header_data.vertex_included_files and header_data.reading == "vertex"):
  58. header_data.vertex_included_files += [included_file]
  59. if(include_file_in_legacygl_header(included_file, header_data, depth + 1) == None):
  60. print("Error in file '" + filename + "': #include " + includeline + "could not be found!")
  61. elif (not included_file in header_data.fragment_included_files and header_data.reading == "fragment"):
  62. header_data.fragment_included_files += [included_file]
  63. if(include_file_in_legacygl_header(included_file, header_data, depth + 1) == None):
  64. print("Error in file '" + filename + "': #include " + includeline + "could not be found!")
  65. line = fs.readline()
  66. if (line.find("#ifdef ") != -1 or line.find("#elif defined(") != -1):
  67. if (line.find("#ifdef ") != -1):
  68. ifdefline = line.replace("#ifdef ", "").strip()
  69. else:
  70. ifdefline = line.replace("#elif defined(", "").strip()
  71. ifdefline = ifdefline.replace(")", "").strip()
  72. if (line.find("_EN_") != -1):
  73. enumbase = ifdefline[:ifdefline.find("_EN_")]
  74. ifdefline = ifdefline.replace("_EN_", "_")
  75. line = line.replace("_EN_", "_")
  76. if (enumbase not in header_data.enums):
  77. header_data.enums[enumbase] = []
  78. if (ifdefline not in header_data.enums[enumbase]):
  79. header_data.enums[enumbase].append(ifdefline)
  80. elif (not ifdefline in header_data.conditionals):
  81. header_data.conditionals += [ifdefline]
  82. if (line.find("uniform") != -1 and line.lower().find("texunit:") != -1):
  83. # texture unit
  84. texunitstr = line[line.find(":") + 1:].strip()
  85. if (texunitstr == "auto"):
  86. texunit = "-1"
  87. else:
  88. texunit = str(int(texunitstr))
  89. uline = line[:line.lower().find("//")]
  90. uline = uline.replace("uniform", "")
  91. uline = uline.replace("highp", "")
  92. uline = uline.replace(";", "")
  93. lines = uline.split(",")
  94. for x in lines:
  95. x = x.strip()
  96. x = x[x.rfind(" ") + 1:]
  97. if (x.find("[") != -1):
  98. # unfiorm array
  99. x = x[:x.find("[")]
  100. if (not x in header_data.texunit_names):
  101. header_data.texunits += [(x, texunit)]
  102. header_data.texunit_names += [x]
  103. elif (line.find("uniform") != -1 and line.lower().find("ubo:") != -1):
  104. # uniform buffer object
  105. ubostr = line[line.find(":") + 1:].strip()
  106. ubo = str(int(ubostr))
  107. uline = line[:line.lower().find("//")]
  108. uline = uline[uline.find("uniform") + len("uniform"):]
  109. uline = uline.replace("highp", "")
  110. uline = uline.replace(";", "")
  111. uline = uline.replace("{", "").strip()
  112. lines = uline.split(",")
  113. for x in lines:
  114. x = x.strip()
  115. x = x[x.rfind(" ") + 1:]
  116. if (x.find("[") != -1):
  117. # unfiorm array
  118. x = x[:x.find("[")]
  119. if (not x in header_data.ubo_names):
  120. header_data.ubos += [(x, ubo)]
  121. header_data.ubo_names += [x]
  122. elif (line.find("uniform") != -1 and line.find("{") == -1 and line.find(";") != -1):
  123. uline = line.replace("uniform", "")
  124. uline = uline.replace(";", "")
  125. lines = uline.split(",")
  126. for x in lines:
  127. x = x.strip()
  128. x = x[x.rfind(" ") + 1:]
  129. if (x.find("[") != -1):
  130. # unfiorm array
  131. x = x[:x.find("[")]
  132. if (not x in header_data.uniforms):
  133. header_data.uniforms += [x]
  134. if (line.strip().find("attribute ") == 0 and line.find("attrib:") != -1):
  135. uline = line.replace("in ", "")
  136. uline = uline.replace("attribute ", "")
  137. uline = uline.replace("highp ", "")
  138. uline = uline.replace(";", "")
  139. uline = uline[uline.find(" "):].strip()
  140. if (uline.find("//") != -1):
  141. name, bind = uline.split("//")
  142. if (bind.find("attrib:") != -1):
  143. name = name.strip()
  144. bind = bind.replace("attrib:", "").strip()
  145. header_data.attributes += [(name, bind)]
  146. if (line.strip().find("out ") == 0 and line.find("tfb:") != -1):
  147. uline = line.replace("out ", "")
  148. uline = uline.replace("highp ", "")
  149. uline = uline.replace(";", "")
  150. uline = uline[uline.find(" "):].strip()
  151. if (uline.find("//") != -1):
  152. name, bind = uline.split("//")
  153. if (bind.find("tfb:") != -1):
  154. name = name.strip()
  155. bind = bind.replace("tfb:", "").strip()
  156. header_data.feedbacks += [(name, bind)]
  157. line = line.replace("\r", "")
  158. line = line.replace("\n", "")
  159. if (header_data.reading == "vertex"):
  160. header_data.vertex_lines += [line]
  161. if (header_data.reading == "fragment"):
  162. header_data.fragment_lines += [line]
  163. line = fs.readline()
  164. header_data.line_offset += 1
  165. fs.close()
  166. return header_data
  167. def build_legacygl_header(filename, include, class_suffix, output_attribs, gles2=False):
  168. header_data = LegacyGLHeaderStruct()
  169. include_file_in_legacygl_header(filename, header_data, 0)
  170. out_file = filename + ".gen.h"
  171. fd = open(out_file, "w")
  172. enum_constants = []
  173. fd.write("/* WARNING, THIS FILE WAS GENERATED, DO NOT EDIT */\n")
  174. out_file_base = out_file
  175. out_file_base = out_file_base[out_file_base.rfind("/") + 1:]
  176. out_file_base = out_file_base[out_file_base.rfind("\\") + 1:]
  177. out_file_ifdef = out_file_base.replace(".", "_").upper()
  178. fd.write("#ifndef " + out_file_ifdef + class_suffix + "_120\n")
  179. fd.write("#define " + out_file_ifdef + class_suffix + "_120\n")
  180. out_file_class = out_file_base.replace(".glsl.gen.h", "").title().replace("_", "").replace(".", "") + "Shader" + class_suffix
  181. fd.write("\n\n")
  182. fd.write("#include \"" + include + "\"\n\n\n")
  183. fd.write("class " + out_file_class + " : public Shader" + class_suffix + " {\n\n")
  184. fd.write("\t virtual String get_shader_name() const { return \"" + out_file_class + "\"; }\n")
  185. fd.write("public:\n\n")
  186. if (len(header_data.conditionals)):
  187. fd.write("\tenum Conditionals {\n")
  188. for x in header_data.conditionals:
  189. fd.write("\t\t" + x.upper() + ",\n")
  190. fd.write("\t};\n\n")
  191. if (len(header_data.uniforms)):
  192. fd.write("\tenum Uniforms {\n")
  193. for x in header_data.uniforms:
  194. fd.write("\t\t" + x.upper() + ",\n")
  195. fd.write("\t};\n\n")
  196. fd.write("\t_FORCE_INLINE_ int get_uniform(Uniforms p_uniform) const { return _get_uniform(p_uniform); }\n\n")
  197. if (len(header_data.conditionals)):
  198. fd.write("\t_FORCE_INLINE_ void set_conditional(Conditionals p_conditional,bool p_enable) { _set_conditional(p_conditional,p_enable); }\n\n")
  199. fd.write("\t#define _FU if (get_uniform(p_uniform)<0) return; ERR_FAIL_COND( get_active()!=this );\n\n ")
  200. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, float p_value) { _FU glUniform1f(get_uniform(p_uniform),p_value); }\n\n")
  201. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, double p_value) { _FU glUniform1f(get_uniform(p_uniform),p_value); }\n\n")
  202. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, uint8_t p_value) { _FU glUniform1i(get_uniform(p_uniform),p_value); }\n\n")
  203. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, int8_t p_value) { _FU glUniform1i(get_uniform(p_uniform),p_value); }\n\n")
  204. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, uint16_t p_value) { _FU glUniform1i(get_uniform(p_uniform),p_value); }\n\n")
  205. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, int16_t p_value) { _FU glUniform1i(get_uniform(p_uniform),p_value); }\n\n")
  206. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, uint32_t p_value) { _FU glUniform1i(get_uniform(p_uniform),p_value); }\n\n")
  207. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, int32_t p_value) { _FU glUniform1i(get_uniform(p_uniform),p_value); }\n\n")
  208. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, const Color& p_color) { _FU GLfloat col[4]={p_color.r,p_color.g,p_color.b,p_color.a}; glUniform4fv(get_uniform(p_uniform),1,col); }\n\n")
  209. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, const Vector2& p_vec2) { _FU GLfloat vec2[2]={p_vec2.x,p_vec2.y}; glUniform2fv(get_uniform(p_uniform),1,vec2); }\n\n")
  210. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, const Vector3& p_vec3) { _FU GLfloat vec3[3]={p_vec3.x,p_vec3.y,p_vec3.z}; glUniform3fv(get_uniform(p_uniform),1,vec3); }\n\n")
  211. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, float p_a, float p_b) { _FU glUniform2f(get_uniform(p_uniform),p_a,p_b); }\n\n")
  212. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, float p_a, float p_b, float p_c) { _FU glUniform3f(get_uniform(p_uniform),p_a,p_b,p_c); }\n\n")
  213. fd.write("\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, float p_a, float p_b, float p_c, float p_d) { _FU glUniform4f(get_uniform(p_uniform),p_a,p_b,p_c,p_d); }\n\n")
  214. fd.write("""\t_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, const Transform& p_transform) { _FU
  215. const Transform &tr = p_transform;
  216. GLfloat matrix[16]={ /* build a 16x16 matrix */
  217. tr.basis.elements[0][0],
  218. tr.basis.elements[1][0],
  219. tr.basis.elements[2][0],
  220. 0,
  221. tr.basis.elements[0][1],
  222. tr.basis.elements[1][1],
  223. tr.basis.elements[2][1],
  224. 0,
  225. tr.basis.elements[0][2],
  226. tr.basis.elements[1][2],
  227. tr.basis.elements[2][2],
  228. 0,
  229. tr.origin.x,
  230. tr.origin.y,
  231. tr.origin.z,
  232. 1
  233. };
  234. glUniformMatrix4fv(get_uniform(p_uniform),1,false,matrix);
  235. }
  236. """)
  237. fd.write("""_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, const Transform2D& p_transform) { _FU
  238. const Transform2D &tr = p_transform;
  239. GLfloat matrix[16]={ /* build a 16x16 matrix */
  240. tr.elements[0][0],
  241. tr.elements[0][1],
  242. 0,
  243. 0,
  244. tr.elements[1][0],
  245. tr.elements[1][1],
  246. 0,
  247. 0,
  248. 0,
  249. 0,
  250. 1,
  251. 0,
  252. tr.elements[2][0],
  253. tr.elements[2][1],
  254. 0,
  255. 1
  256. };
  257. glUniformMatrix4fv(get_uniform(p_uniform),1,false,matrix);
  258. }
  259. """)
  260. fd.write("""_FORCE_INLINE_ void set_uniform(Uniforms p_uniform, const CameraMatrix& p_matrix) { _FU
  261. GLfloat matrix[16];
  262. for (int i=0;i<4;i++) {
  263. for (int j=0;j<4;j++) {
  264. matrix[i*4+j]=p_matrix.matrix[i][j];
  265. }
  266. }
  267. glUniformMatrix4fv(get_uniform(p_uniform),1,false,matrix);
  268. } """)
  269. fd.write("\n\n#undef _FU\n\n\n")
  270. fd.write("\tvirtual void init() {\n\n")
  271. enum_value_count = 0
  272. if (len(header_data.enums)):
  273. fd.write("\t\t//Written using math, given nonstandarity of 64 bits integer constants..\n")
  274. fd.write("\t\tstatic const Enum _enums[]={\n")
  275. bitofs = len(header_data.conditionals)
  276. enum_vals = []
  277. for xv in header_data.enums:
  278. x = header_data.enums[xv]
  279. bits = 1
  280. amt = len(x)
  281. while(2**bits < amt):
  282. bits += 1
  283. strs = "{"
  284. for i in range(amt):
  285. strs += "\"#define " + x[i] + "\\n\","
  286. v = {}
  287. v["set_mask"] = "uint64_t(" + str(i) + ")<<" + str(bitofs)
  288. v["clear_mask"] = "((uint64_t(1)<<40)-1) ^ (((uint64_t(1)<<" + str(bits) + ") - 1)<<" + str(bitofs) + ")"
  289. enum_vals.append(v)
  290. enum_constants.append(x[i])
  291. strs += "NULL}"
  292. fd.write("\t\t\t{(uint64_t(1<<" + str(bits) + ")-1)<<" + str(bitofs) + "," + str(bitofs) + "," + strs + "},\n")
  293. bitofs += bits
  294. fd.write("\t\t};\n\n")
  295. fd.write("\t\tstatic const EnumValue _enum_values[]={\n")
  296. enum_value_count = len(enum_vals)
  297. for x in enum_vals:
  298. fd.write("\t\t\t{" + x["set_mask"] + "," + x["clear_mask"] + "},\n")
  299. fd.write("\t\t};\n\n")
  300. conditionals_found = []
  301. if (len(header_data.conditionals)):
  302. fd.write("\t\tstatic const char* _conditional_strings[]={\n")
  303. if (len(header_data.conditionals)):
  304. for x in header_data.conditionals:
  305. fd.write("\t\t\t\"#define " + x + "\\n\",\n")
  306. conditionals_found.append(x)
  307. fd.write("\t\t};\n\n")
  308. else:
  309. fd.write("\t\tstatic const char **_conditional_strings=NULL;\n")
  310. if (len(header_data.uniforms)):
  311. fd.write("\t\tstatic const char* _uniform_strings[]={\n")
  312. if (len(header_data.uniforms)):
  313. for x in header_data.uniforms:
  314. fd.write("\t\t\t\"" + x + "\",\n")
  315. fd.write("\t\t};\n\n")
  316. else:
  317. fd.write("\t\tstatic const char **_uniform_strings=NULL;\n")
  318. if output_attribs:
  319. if (len(header_data.attributes)):
  320. fd.write("\t\tstatic AttributePair _attribute_pairs[]={\n")
  321. for x in header_data.attributes:
  322. fd.write("\t\t\t{\"" + x[0] + "\"," + x[1] + "},\n")
  323. fd.write("\t\t};\n\n")
  324. else:
  325. fd.write("\t\tstatic AttributePair *_attribute_pairs=NULL;\n")
  326. feedback_count = 0
  327. if (not gles2 and len(header_data.feedbacks)):
  328. fd.write("\t\tstatic const Feedback _feedbacks[]={\n")
  329. for x in header_data.feedbacks:
  330. name = x[0]
  331. cond = x[1]
  332. if (cond in conditionals_found):
  333. fd.write("\t\t\t{\"" + name + "\"," + str(conditionals_found.index(cond)) + "},\n")
  334. else:
  335. fd.write("\t\t\t{\"" + name + "\",-1},\n")
  336. feedback_count += 1
  337. fd.write("\t\t};\n\n")
  338. else:
  339. if gles2:
  340. pass
  341. else:
  342. fd.write("\t\tstatic const Feedback* _feedbacks=NULL;\n")
  343. if (len(header_data.texunits)):
  344. fd.write("\t\tstatic TexUnitPair _texunit_pairs[]={\n")
  345. for x in header_data.texunits:
  346. fd.write("\t\t\t{\"" + x[0] + "\"," + x[1] + "},\n")
  347. fd.write("\t\t};\n\n")
  348. else:
  349. fd.write("\t\tstatic TexUnitPair *_texunit_pairs=NULL;\n")
  350. if (not gles2 and len(header_data.ubos)):
  351. fd.write("\t\tstatic UBOPair _ubo_pairs[]={\n")
  352. for x in header_data.ubos:
  353. fd.write("\t\t\t{\"" + x[0] + "\"," + x[1] + "},\n")
  354. fd.write("\t\t};\n\n")
  355. else:
  356. if gles2:
  357. pass
  358. else:
  359. fd.write("\t\tstatic UBOPair *_ubo_pairs=NULL;\n")
  360. fd.write("\t\tstatic const char _vertex_code[]={\n")
  361. for x in header_data.vertex_lines:
  362. for i in range(len(x)):
  363. fd.write(str(ord(x[i])) + ",")
  364. fd.write(str(ord('\n')) + ",")
  365. fd.write("\t\t0};\n\n")
  366. fd.write("\t\tstatic const int _vertex_code_start=" + str(header_data.vertex_offset) + ";\n")
  367. fd.write("\t\tstatic const char _fragment_code[]={\n")
  368. for x in header_data.fragment_lines:
  369. for i in range(len(x)):
  370. fd.write(str(ord(x[i])) + ",")
  371. fd.write(str(ord('\n')) + ",")
  372. fd.write("\t\t0};\n\n")
  373. fd.write("\t\tstatic const int _fragment_code_start=" + str(header_data.fragment_offset) + ";\n")
  374. if output_attribs:
  375. if gles2:
  376. fd.write("\t\tsetup(_conditional_strings," + str(len(header_data.conditionals)) + ",_uniform_strings," + str(len(header_data.uniforms)) + ",_attribute_pairs," + str(len(header_data.attributes)) + ", _texunit_pairs," + str(len(header_data.texunits)) + ",_vertex_code,_fragment_code,_vertex_code_start,_fragment_code_start);\n")
  377. else:
  378. fd.write("\t\tsetup(_conditional_strings," + str(len(header_data.conditionals)) + ",_uniform_strings," + str(len(header_data.uniforms)) + ",_attribute_pairs," + str(len(header_data.attributes)) + ", _texunit_pairs," + str(len(header_data.texunits)) + ",_ubo_pairs," + str(len(header_data.ubos)) + ",_feedbacks," + str(feedback_count) + ",_vertex_code,_fragment_code,_vertex_code_start,_fragment_code_start);\n")
  379. else:
  380. if gles2:
  381. fd.write("\t\tsetup(_conditional_strings," + str(len(header_data.conditionals)) + ",_uniform_strings," + str(len(header_data.uniforms)) + ",_texunit_pairs," + str(len(header_data.texunits)) + ",_enums," + str(len(header_data.enums)) + ",_enum_values," + str(enum_value_count) + ",_vertex_code,_fragment_code,_vertex_code_start,_fragment_code_start);\n")
  382. else:
  383. fd.write("\t\tsetup(_conditional_strings," + str(len(header_data.conditionals)) + ",_uniform_strings," + str(len(header_data.uniforms)) + ",_texunit_pairs," + str(len(header_data.texunits)) + ",_enums," + str(len(header_data.enums)) + ",_enum_values," + str(enum_value_count) + ",_ubo_pairs," + str(len(header_data.ubos)) + ",_feedbacks," + str(feedback_count) + ",_vertex_code,_fragment_code,_vertex_code_start,_fragment_code_start);\n")
  384. fd.write("\t}\n\n")
  385. if (len(enum_constants)):
  386. fd.write("\tenum EnumConditionals {\n")
  387. for x in enum_constants:
  388. fd.write("\t\t" + x.upper() + ",\n")
  389. fd.write("\t};\n\n")
  390. fd.write("\tvoid set_enum_conditional(EnumConditionals p_cond) { _set_enum_conditional(p_cond); }\n")
  391. fd.write("};\n\n")
  392. fd.write("#endif\n\n")
  393. fd.close()
  394. def build_gles3_headers(target, source, env):
  395. for x in source:
  396. build_legacygl_header(str(x), include="drivers/gles3/shader_gles3.h", class_suffix="GLES3", output_attribs=True)
  397. def build_gles2_headers(target, source, env):
  398. for x in source:
  399. build_legacygl_header(str(x), include="drivers/gles2/shader_gles2.h", class_suffix="GLES2", output_attribs=True, gles2=True)
  400. def add_module_version_string(self,s):
  401. self.module_version_string += "." + s
  402. def update_version(module_version_string=""):
  403. build_name = "custom_build"
  404. if (os.getenv("BUILD_NAME") != None):
  405. build_name = os.getenv("BUILD_NAME")
  406. print("Using custom build name: " + build_name)
  407. import version
  408. f = open("core/version_generated.gen.h", "w")
  409. f.write("#define VERSION_SHORT_NAME \"" + str(version.short_name) + "\"\n")
  410. f.write("#define VERSION_NAME \"" + str(version.name) + "\"\n")
  411. f.write("#define VERSION_MAJOR " + str(version.major) + "\n")
  412. f.write("#define VERSION_MINOR " + str(version.minor) + "\n")
  413. if (hasattr(version, 'patch')):
  414. f.write("#define VERSION_PATCH " + str(version.patch) + "\n")
  415. f.write("#define VERSION_STATUS \"" + str(version.status) + "\"\n")
  416. f.write("#define VERSION_BUILD \"" + str(build_name) + "\"\n")
  417. f.write("#define VERSION_MODULE_CONFIG \"" + str(version.module_config) + module_version_string + "\"\n")
  418. import datetime
  419. f.write("#define VERSION_YEAR " + str(datetime.datetime.now().year) + "\n")
  420. f.close()
  421. fhash = open("core/version_hash.gen.h", "w")
  422. githash = ""
  423. if os.path.isfile(".git/HEAD"):
  424. head = open(".git/HEAD", "r").readline().strip()
  425. if head.startswith("ref: "):
  426. head = ".git/" + head[5:]
  427. if os.path.isfile(head):
  428. githash = open(head, "r").readline().strip()
  429. else:
  430. githash = head
  431. fhash.write("#define VERSION_HASH \"" + githash + "\"")
  432. fhash.close()
  433. def parse_cg_file(fname, uniforms, sizes, conditionals):
  434. import re
  435. fs = open(fname, "r")
  436. line = fs.readline()
  437. while line:
  438. if re.match(r"^\s*uniform", line):
  439. res = re.match(r"uniform ([\d\w]*) ([\d\w]*)")
  440. type = res.groups(1)
  441. name = res.groups(2)
  442. uniforms.append(name)
  443. if (type.find("texobj") != -1):
  444. sizes.append(1)
  445. else:
  446. t = re.match(r"float(\d)x(\d)", type)
  447. if t:
  448. sizes.append(int(t.groups(1)) * int(t.groups(2)))
  449. else:
  450. t = re.match(r"float(\d)", type)
  451. sizes.append(int(t.groups(1)))
  452. if line.find("[branch]") != -1:
  453. conditionals.append(name)
  454. line = fs.readline()
  455. fs.close()
  456. import glob
  457. def detect_modules():
  458. module_list = []
  459. includes_cpp = ""
  460. register_cpp = ""
  461. unregister_cpp = ""
  462. files = glob.glob("modules/*")
  463. files.sort() # so register_module_types does not change that often, and also plugins are registered in alphabetic order
  464. for x in files:
  465. if (not os.path.isdir(x)):
  466. continue
  467. if (not os.path.exists(x + "/config.py")):
  468. continue
  469. x = x.replace("modules/", "") # rest of world
  470. x = x.replace("modules\\", "") # win32
  471. module_list.append(x)
  472. try:
  473. with open("modules/" + x + "/register_types.h"):
  474. includes_cpp += '#include "modules/' + x + '/register_types.h"\n'
  475. register_cpp += '#ifdef MODULE_' + x.upper() + '_ENABLED\n'
  476. register_cpp += '\tregister_' + x + '_types();\n'
  477. register_cpp += '#endif\n'
  478. unregister_cpp += '#ifdef MODULE_' + x.upper() + '_ENABLED\n'
  479. unregister_cpp += '\tunregister_' + x + '_types();\n'
  480. unregister_cpp += '#endif\n'
  481. except IOError:
  482. pass
  483. modules_cpp = """
  484. // modules.cpp - THIS FILE IS GENERATED, DO NOT EDIT!!!!!!!
  485. #include "register_module_types.h"
  486. """ + includes_cpp + """
  487. void register_module_types() {
  488. """ + register_cpp + """
  489. }
  490. void unregister_module_types() {
  491. """ + unregister_cpp + """
  492. }
  493. """
  494. with open("modules/register_module_types.gen.cpp", "w") as f:
  495. f.write(modules_cpp)
  496. return module_list
  497. def win32_spawn(sh, escape, cmd, args, env):
  498. import subprocess
  499. newargs = ' '.join(args[1:])
  500. cmdline = cmd + " " + newargs
  501. startupinfo = subprocess.STARTUPINFO()
  502. for e in env:
  503. if type(env[e]) != type(""):
  504. env[e] = str(env[e])
  505. proc = subprocess.Popen(cmdline, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
  506. stderr=subprocess.PIPE, startupinfo=startupinfo, shell=False, env=env)
  507. data, err = proc.communicate()
  508. rv = proc.wait()
  509. if rv:
  510. print("=====")
  511. print(err)
  512. print("=====")
  513. return rv
  514. """
  515. def win32_spawn(sh, escape, cmd, args, spawnenv):
  516. import win32file
  517. import win32event
  518. import win32process
  519. import win32security
  520. for var in spawnenv:
  521. spawnenv[var] = spawnenv[var].encode('ascii', 'replace')
  522. sAttrs = win32security.SECURITY_ATTRIBUTES()
  523. StartupInfo = win32process.STARTUPINFO()
  524. newargs = ' '.join(map(escape, args[1:]))
  525. cmdline = cmd + " " + newargs
  526. # check for any special operating system commands
  527. if cmd == 'del':
  528. for arg in args[1:]:
  529. win32file.DeleteFile(arg)
  530. exit_code = 0
  531. else:
  532. # otherwise execute the command.
  533. hProcess, hThread, dwPid, dwTid = win32process.CreateProcess(None, cmdline, None, None, 1, 0, spawnenv, None, StartupInfo)
  534. win32event.WaitForSingleObject(hProcess, win32event.INFINITE)
  535. exit_code = win32process.GetExitCodeProcess(hProcess)
  536. win32file.CloseHandle(hProcess);
  537. win32file.CloseHandle(hThread);
  538. return exit_code
  539. """
  540. def android_add_flat_dir(self, dir):
  541. if (dir not in self.android_flat_dirs):
  542. self.android_flat_dirs.append(dir)
  543. def android_add_maven_repository(self, url):
  544. if (url not in self.android_maven_repos):
  545. self.android_maven_repos.append(url)
  546. def android_add_dependency(self, depline):
  547. if (depline not in self.android_dependencies):
  548. self.android_dependencies.append(depline)
  549. def android_add_java_dir(self, subpath):
  550. base_path = self.Dir(".").abspath + "/modules/" + self.current_module + "/" + subpath
  551. if (base_path not in self.android_java_dirs):
  552. self.android_java_dirs.append(base_path)
  553. def android_add_res_dir(self, subpath):
  554. base_path = self.Dir(".").abspath + "/modules/" + self.current_module + "/" + subpath
  555. if (base_path not in self.android_res_dirs):
  556. self.android_res_dirs.append(base_path)
  557. def android_add_aidl_dir(self, subpath):
  558. base_path = self.Dir(".").abspath + "/modules/" + self.current_module + "/" + subpath
  559. if (base_path not in self.android_aidl_dirs):
  560. self.android_aidl_dirs.append(base_path)
  561. def android_add_jni_dir(self, subpath):
  562. base_path = self.Dir(".").abspath + "/modules/" + self.current_module + "/" + subpath
  563. if (base_path not in self.android_jni_dirs):
  564. self.android_jni_dirs.append(base_path)
  565. def android_add_gradle_plugin(self, plugin):
  566. if (plugin not in self.android_gradle_plugins):
  567. self.android_gradle_plugins.append(plugin)
  568. def android_add_gradle_classpath(self, classpath):
  569. if (classpath not in self.android_gradle_classpath):
  570. self.android_gradle_classpath.append(classpath)
  571. def android_add_default_config(self, config):
  572. if (config not in self.android_default_config):
  573. self.android_default_config.append(config)
  574. def android_add_to_manifest(self, file):
  575. base_path = self.Dir(".").abspath + "/modules/" + self.current_module + "/" + file
  576. with open(base_path, "r") as f:
  577. self.android_manifest_chunk += f.read()
  578. def android_add_to_permissions(self, file):
  579. base_path = self.Dir(".").abspath + "/modules/" + self.current_module + "/" + file
  580. with open(base_path, "r") as f:
  581. self.android_permission_chunk += f.read()
  582. def android_add_to_attributes(self, file):
  583. base_path = self.Dir(".").abspath + "/modules/" + self.current_module + "/" + file
  584. with open(base_path, "r") as f:
  585. self.android_appattributes_chunk += f.read()
  586. def disable_module(self):
  587. self.disabled_modules.append(self.current_module)
  588. def use_windows_spawn_fix(self, platform=None):
  589. if (os.name != "nt"):
  590. return # not needed, only for windows
  591. # On Windows, due to the limited command line length, when creating a static library
  592. # from a very high number of objects SCons will invoke "ar" once per object file;
  593. # that makes object files with same names to be overwritten so the last wins and
  594. # the library looses symbols defined by overwritten objects.
  595. # By enabling quick append instead of the default mode (replacing), libraries will
  596. # got built correctly regardless the invocation strategy.
  597. # Furthermore, since SCons will rebuild the library from scratch when an object file
  598. # changes, no multiple versions of the same object file will be present.
  599. self.Replace(ARFLAGS='q')
  600. import subprocess
  601. def mySubProcess(cmdline, env):
  602. startupinfo = subprocess.STARTUPINFO()
  603. startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
  604. proc = subprocess.Popen(cmdline, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
  605. stderr=subprocess.PIPE, startupinfo=startupinfo, shell=False, env=env)
  606. data, err = proc.communicate()
  607. rv = proc.wait()
  608. if rv:
  609. print("=====")
  610. print(err)
  611. print("=====")
  612. return rv
  613. def mySpawn(sh, escape, cmd, args, env):
  614. newargs = ' '.join(args[1:])
  615. cmdline = cmd + " " + newargs
  616. rv = 0
  617. env = {str(key): str(value) for key, value in iteritems(env)}
  618. if len(cmdline) > 32000 and cmd.endswith("ar"):
  619. cmdline = cmd + " " + args[1] + " " + args[2] + " "
  620. for i in range(3, len(args)):
  621. rv = mySubProcess(cmdline + args[i], env)
  622. if rv:
  623. break
  624. else:
  625. rv = mySubProcess(cmdline, env)
  626. return rv
  627. self['SPAWN'] = mySpawn
  628. def split_lib(self, libname, src_list = None, env_lib = None):
  629. import string
  630. env = self
  631. num = 0
  632. cur_base = ""
  633. max_src = 64
  634. list = []
  635. lib_list = []
  636. if src_list == None:
  637. src_list = getattr(env, libname + "_sources")
  638. if type(env_lib) == type(None):
  639. env_lib = env
  640. for f in src_list:
  641. fname = ""
  642. if type(f) == type(""):
  643. fname = env.File(f).path
  644. else:
  645. fname = env.File(f)[0].path
  646. fname = fname.replace("\\", "/")
  647. base = string.join(fname.split("/")[:2], "/")
  648. if base != cur_base and len(list) > max_src:
  649. if num > 0:
  650. lib = env_lib.add_library(libname + str(num), list)
  651. lib_list.append(lib)
  652. list = []
  653. num = num + 1
  654. cur_base = base
  655. list.append(f)
  656. lib = env_lib.add_library(libname + str(num), list)
  657. lib_list.append(lib)
  658. if len(lib_list) > 0:
  659. import os, sys
  660. if os.name == 'posix' and sys.platform == 'msys':
  661. env.Replace(ARFLAGS=['rcsT'])
  662. lib = env_lib.add_library(libname + "_collated", lib_list)
  663. lib_list = [lib]
  664. lib_base = []
  665. env_lib.add_source_files(lib_base, "*.cpp")
  666. lib = env_lib.add_library(libname, lib_base)
  667. lib_list.insert(0, lib)
  668. env.Prepend(LIBS=lib_list)
  669. def save_active_platforms(apnames, ap):
  670. for x in ap:
  671. names = ['logo']
  672. if os.path.isfile(x + "/run_icon.png"):
  673. names.append('run_icon')
  674. for name in names:
  675. pngf = open(x + "/" + name + ".png", "rb")
  676. b = pngf.read(1)
  677. str = " /* AUTOGENERATED FILE, DO NOT EDIT */ \n"
  678. str += " static const unsigned char _" + x[9:] + "_" + name + "[]={"
  679. while(len(b) == 1):
  680. str += hex(ord(b))
  681. b = pngf.read(1)
  682. if (len(b) == 1):
  683. str += ","
  684. str += "};\n"
  685. pngf.close()
  686. wf = x + "/" + name + ".gen.h"
  687. with open(wf, "w") as pngw:
  688. pngw.write(str)
  689. def no_verbose(sys, env):
  690. colors = {}
  691. # Colors are disabled in non-TTY environments such as pipes. This means
  692. # that if output is redirected to a file, it will not contain color codes
  693. if sys.stdout.isatty():
  694. colors['cyan'] = '\033[96m'
  695. colors['purple'] = '\033[95m'
  696. colors['blue'] = '\033[94m'
  697. colors['green'] = '\033[92m'
  698. colors['yellow'] = '\033[93m'
  699. colors['red'] = '\033[91m'
  700. colors['end'] = '\033[0m'
  701. else:
  702. colors['cyan'] = ''
  703. colors['purple'] = ''
  704. colors['blue'] = ''
  705. colors['green'] = ''
  706. colors['yellow'] = ''
  707. colors['red'] = ''
  708. colors['end'] = ''
  709. compile_source_message = '%sCompiling %s==> %s$SOURCE%s' % (colors['blue'], colors['purple'], colors['yellow'], colors['end'])
  710. java_compile_source_message = '%sCompiling %s==> %s$SOURCE%s' % (colors['blue'], colors['purple'], colors['yellow'], colors['end'])
  711. compile_shared_source_message = '%sCompiling shared %s==> %s$SOURCE%s' % (colors['blue'], colors['purple'], colors['yellow'], colors['end'])
  712. link_program_message = '%sLinking Program %s==> %s$TARGET%s' % (colors['red'], colors['purple'], colors['yellow'], colors['end'])
  713. link_library_message = '%sLinking Static Library %s==> %s$TARGET%s' % (colors['red'], colors['purple'], colors['yellow'], colors['end'])
  714. ranlib_library_message = '%sRanlib Library %s==> %s$TARGET%s' % (colors['red'], colors['purple'], colors['yellow'], colors['end'])
  715. link_shared_library_message = '%sLinking Shared Library %s==> %s$TARGET%s' % (colors['red'], colors['purple'], colors['yellow'], colors['end'])
  716. java_library_message = '%sCreating Java Archive %s==> %s$TARGET%s' % (colors['red'], colors['purple'], colors['yellow'], colors['end'])
  717. env.Append(CXXCOMSTR=[compile_source_message])
  718. env.Append(CCCOMSTR=[compile_source_message])
  719. env.Append(SHCCCOMSTR=[compile_shared_source_message])
  720. env.Append(SHCXXCOMSTR=[compile_shared_source_message])
  721. env.Append(ARCOMSTR=[link_library_message])
  722. env.Append(RANLIBCOMSTR=[ranlib_library_message])
  723. env.Append(SHLINKCOMSTR=[link_shared_library_message])
  724. env.Append(LINKCOMSTR=[link_program_message])
  725. env.Append(JARCOMSTR=[java_library_message])
  726. env.Append(JAVACCOMSTR=[java_compile_source_message])
  727. def detect_visual_c_compiler_version(tools_env):
  728. # tools_env is the variable scons uses to call tools that execute tasks, SCons's env['ENV'] that executes tasks...
  729. # (see the SCons documentation for more information on what it does)...
  730. # in order for this function to be well encapsulated i choose to force it to receive SCons's TOOLS env (env['ENV']
  731. # and not scons setup environment (env)... so make sure you call the right environment on it or it will fail to detect
  732. # the proper vc version that will be called
  733. # There is no flag to give to visual c compilers to set the architecture, ie scons bits argument (32,64,ARM etc)
  734. # There are many different cl.exe files that are run, and each one compiles & links to a different architecture
  735. # As far as I know, the only way to figure out what compiler will be run when Scons calls cl.exe via Program()
  736. # is to check the PATH variable and figure out which one will be called first. Code below does that and returns:
  737. # the following string values:
  738. # "" Compiler not detected
  739. # "amd64" Native 64 bit compiler
  740. # "amd64_x86" 64 bit Cross Compiler for 32 bit
  741. # "x86" Native 32 bit compiler
  742. # "x86_amd64" 32 bit Cross Compiler for 64 bit
  743. # There are other architectures, but Godot does not support them currently, so this function does not detect arm/amd64_arm
  744. # and similar architectures/compilers
  745. # Set chosen compiler to "not detected"
  746. vc_chosen_compiler_index = -1
  747. vc_chosen_compiler_str = ""
  748. # Start with Pre VS 2017 checks which uses VCINSTALLDIR:
  749. if 'VCINSTALLDIR' in tools_env:
  750. # print("Checking VCINSTALLDIR")
  751. # find() works with -1 so big ifs below are needed... the simplest solution, in fact
  752. # First test if amd64 and amd64_x86 compilers are present in the path
  753. vc_amd64_compiler_detection_index = tools_env["PATH"].find(tools_env["VCINSTALLDIR"] + "BIN\\amd64;")
  754. if(vc_amd64_compiler_detection_index > -1):
  755. vc_chosen_compiler_index = vc_amd64_compiler_detection_index
  756. vc_chosen_compiler_str = "amd64"
  757. vc_amd64_x86_compiler_detection_index = tools_env["PATH"].find(tools_env["VCINSTALLDIR"] + "BIN\\amd64_x86;")
  758. if(vc_amd64_x86_compiler_detection_index > -1
  759. and (vc_chosen_compiler_index == -1
  760. or vc_chosen_compiler_index > vc_amd64_x86_compiler_detection_index)):
  761. vc_chosen_compiler_index = vc_amd64_x86_compiler_detection_index
  762. vc_chosen_compiler_str = "amd64_x86"
  763. # Now check the 32 bit compilers
  764. vc_x86_compiler_detection_index = tools_env["PATH"].find(tools_env["VCINSTALLDIR"] + "BIN;")
  765. if(vc_x86_compiler_detection_index > -1
  766. and (vc_chosen_compiler_index == -1
  767. or vc_chosen_compiler_index > vc_x86_compiler_detection_index)):
  768. vc_chosen_compiler_index = vc_x86_compiler_detection_index
  769. vc_chosen_compiler_str = "x86"
  770. vc_x86_amd64_compiler_detection_index = tools_env["PATH"].find(tools_env['VCINSTALLDIR'] + "BIN\\x86_amd64;")
  771. if(vc_x86_amd64_compiler_detection_index > -1
  772. and (vc_chosen_compiler_index == -1
  773. or vc_chosen_compiler_index > vc_x86_amd64_compiler_detection_index)):
  774. vc_chosen_compiler_index = vc_x86_amd64_compiler_detection_index
  775. vc_chosen_compiler_str = "x86_amd64"
  776. # and for VS 2017 and newer we check VCTOOLSINSTALLDIR:
  777. if 'VCTOOLSINSTALLDIR' in tools_env:
  778. # Newer versions have a different path available
  779. vc_amd64_compiler_detection_index = tools_env["PATH"].upper().find(tools_env['VCTOOLSINSTALLDIR'].upper() + "BIN\\HOSTX64\\X64;")
  780. if(vc_amd64_compiler_detection_index > -1):
  781. vc_chosen_compiler_index = vc_amd64_compiler_detection_index
  782. vc_chosen_compiler_str = "amd64"
  783. vc_amd64_x86_compiler_detection_index = tools_env["PATH"].upper().find(tools_env['VCTOOLSINSTALLDIR'].upper() + "BIN\\HOSTX64\\X86;")
  784. if(vc_amd64_x86_compiler_detection_index > -1
  785. and (vc_chosen_compiler_index == -1
  786. or vc_chosen_compiler_index > vc_amd64_x86_compiler_detection_index)):
  787. vc_chosen_compiler_index = vc_amd64_x86_compiler_detection_index
  788. vc_chosen_compiler_str = "amd64_x86"
  789. vc_x86_compiler_detection_index = tools_env["PATH"].upper().find(tools_env['VCTOOLSINSTALLDIR'].upper() + "BIN\\HOSTX86\\X86;")
  790. if(vc_x86_compiler_detection_index > -1
  791. and (vc_chosen_compiler_index == -1
  792. or vc_chosen_compiler_index > vc_x86_compiler_detection_index)):
  793. vc_chosen_compiler_index = vc_x86_compiler_detection_index
  794. vc_chosen_compiler_str = "x86"
  795. vc_x86_amd64_compiler_detection_index = tools_env["PATH"].upper().find(tools_env['VCTOOLSINSTALLDIR'].upper() + "BIN\\HOSTX86\\X64;")
  796. if(vc_x86_amd64_compiler_detection_index > -1
  797. and (vc_chosen_compiler_index == -1
  798. or vc_chosen_compiler_index > vc_x86_amd64_compiler_detection_index)):
  799. vc_chosen_compiler_index = vc_x86_amd64_compiler_detection_index
  800. vc_chosen_compiler_str = "x86_amd64"
  801. return vc_chosen_compiler_str
  802. def find_visual_c_batch_file(env):
  803. from SCons.Tool.MSCommon.vc import get_default_version, get_host_target, find_batch_file
  804. version = get_default_version(env)
  805. (host_platform, target_platform,req_target_platform) = get_host_target(env)
  806. return find_batch_file(env, version, host_platform, target_platform)[0]
  807. def generate_cpp_hint_file(filename):
  808. import os.path
  809. if os.path.isfile(filename):
  810. # Don't overwrite an existing hint file since the user may have customized it.
  811. pass
  812. else:
  813. try:
  814. with open(filename, "w") as fd:
  815. fd.write("#define GDCLASS(m_class, m_inherits)\n")
  816. except IOError:
  817. print("Could not write cpp.hint file.")
  818. def generate_vs_project(env, num_jobs):
  819. batch_file = find_visual_c_batch_file(env)
  820. if batch_file:
  821. def build_commandline(commands):
  822. common_build_prefix = ['cmd /V /C set "plat=$(PlatformTarget)"',
  823. '(if "$(PlatformTarget)"=="x64" (set "plat=x86_amd64"))',
  824. 'set "tools=yes"',
  825. '(if "$(Configuration)"=="release" (set "tools=no"))',
  826. 'call "' + batch_file + '" !plat!']
  827. result = " ^& ".join(common_build_prefix + [commands])
  828. return result
  829. env.AddToVSProject(env.core_sources)
  830. env.AddToVSProject(env.main_sources)
  831. env.AddToVSProject(env.modules_sources)
  832. env.AddToVSProject(env.scene_sources)
  833. env.AddToVSProject(env.servers_sources)
  834. env.AddToVSProject(env.editor_sources)
  835. # windows allows us to have spaces in paths, so we need
  836. # to double quote off the directory. However, the path ends
  837. # in a backslash, so we need to remove this, lest it escape the
  838. # last double quote off, confusing MSBuild
  839. env['MSVSBUILDCOM'] = build_commandline('scons --directory="$(ProjectDir.TrimEnd(\'\\\'))" platform=windows progress=no target=$(Configuration) tools=!tools! -j' + str(num_jobs))
  840. env['MSVSREBUILDCOM'] = build_commandline('scons --directory="$(ProjectDir.TrimEnd(\'\\\'))" platform=windows progress=no target=$(Configuration) tools=!tools! vsproj=yes -j' + str(num_jobs))
  841. env['MSVSCLEANCOM'] = build_commandline('scons --directory="$(ProjectDir.TrimEnd(\'\\\'))" --clean platform=windows progress=no target=$(Configuration) tools=!tools! -j' + str(num_jobs))
  842. # This version information (Win32, x64, Debug, Release, Release_Debug seems to be
  843. # required for Visual Studio to understand that it needs to generate an NMAKE
  844. # project. Do not modify without knowing what you are doing.
  845. debug_variants = ['debug|Win32'] + ['debug|x64']
  846. release_variants = ['release|Win32'] + ['release|x64']
  847. release_debug_variants = ['release_debug|Win32'] + ['release_debug|x64']
  848. variants = debug_variants + release_variants + release_debug_variants
  849. debug_targets = ['bin\\godot.windows.tools.32.exe'] + ['bin\\godot.windows.tools.64.exe']
  850. release_targets = ['bin\\godot.windows.opt.32.exe'] + ['bin\\godot.windows.opt.64.exe']
  851. release_debug_targets = ['bin\\godot.windows.opt.tools.32.exe'] + ['bin\\godot.windows.opt.tools.64.exe']
  852. targets = debug_targets + release_targets + release_debug_targets
  853. msvproj = env.MSVSProject(target=['#godot' + env['MSVSPROJECTSUFFIX']],
  854. incs=env.vs_incs,
  855. srcs=env.vs_srcs,
  856. runfile=targets,
  857. buildtarget=targets,
  858. auto_build_solution=1,
  859. variant=variants)
  860. else:
  861. print("Could not locate Visual Studio batch file for setting up the build environment. Not generating VS project.")
  862. def precious_program(env, program, sources, **args):
  863. program = env.ProgramOriginal(program, sources, **args)
  864. env.Precious(program)
  865. return program
  866. def add_shared_library(env, name, sources, **args):
  867. library = env.SharedLibrary(name, sources, **args)
  868. env.NoCache(library)
  869. return library
  870. def add_library(env, name, sources, **args):
  871. library = env.Library(name, sources, **args)
  872. env.NoCache(library)
  873. return library
  874. def add_program(env, name, sources, **args):
  875. program = env.Program(name, sources, **args)
  876. env.NoCache(program)
  877. return program