methods.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. import os
  2. import os.path
  3. import sys
  4. import re
  5. import glob
  6. import string
  7. import subprocess
  8. from compat import iteritems, isbasestring, decode_utf8
  9. def add_source_files(self, sources, filetype, lib_env=None, shared=False):
  10. if isbasestring(filetype):
  11. dir_path = self.Dir('.').abspath
  12. filetype = sorted(glob.glob(dir_path + "/" + filetype))
  13. for path in filetype:
  14. sources.append(self.Object(path))
  15. def disable_warnings(self):
  16. # 'self' is the environment
  17. if self.msvc:
  18. # We have to remove existing warning level defines before appending /w,
  19. # otherwise we get: "warning D9025 : overriding '/W3' with '/w'"
  20. warn_flags = ['/Wall', '/W4', '/W3', '/W2', '/W1', '/WX']
  21. self.Append(CCFLAGS=['/w'])
  22. self.Append(CFLAGS=['/w'])
  23. self.Append(CXXFLAGS=['/w'])
  24. self['CCFLAGS'] = [x for x in self['CCFLAGS'] if not x in warn_flags]
  25. self['CFLAGS'] = [x for x in self['CFLAGS'] if not x in warn_flags]
  26. self['CXXFLAGS'] = [x for x in self['CXXFLAGS'] if not x in warn_flags]
  27. else:
  28. self.Append(CCFLAGS=['-w'])
  29. self.Append(CFLAGS=['-w'])
  30. self.Append(CXXFLAGS=['-w'])
  31. def add_module_version_string(self,s):
  32. self.module_version_string += "." + s
  33. def update_version(module_version_string=""):
  34. build_name = "custom_build"
  35. if os.getenv("BUILD_NAME") != None:
  36. build_name = os.getenv("BUILD_NAME")
  37. print("Using custom build name: " + build_name)
  38. import version
  39. # NOTE: It is safe to generate this file here, since this is still executed serially
  40. f = open("core/version_generated.gen.h", "w")
  41. f.write("#define VERSION_SHORT_NAME \"" + str(version.short_name) + "\"\n")
  42. f.write("#define VERSION_NAME \"" + str(version.name) + "\"\n")
  43. f.write("#define VERSION_MAJOR " + str(version.major) + "\n")
  44. f.write("#define VERSION_MINOR " + str(version.minor) + "\n")
  45. if hasattr(version, 'patch'):
  46. f.write("#define VERSION_PATCH " + str(version.patch) + "\n")
  47. f.write("#define VERSION_STATUS \"" + str(version.status) + "\"\n")
  48. f.write("#define VERSION_BUILD \"" + str(build_name) + "\"\n")
  49. f.write("#define VERSION_MODULE_CONFIG \"" + str(version.module_config) + module_version_string + "\"\n")
  50. f.write("#define VERSION_YEAR " + str(version.year) + "\n")
  51. f.write("#define VERSION_WEBSITE \"" + str(version.website) + "\"\n")
  52. f.close()
  53. # NOTE: It is safe to generate this file here, since this is still executed serially
  54. fhash = open("core/version_hash.gen.h", "w")
  55. githash = ""
  56. gitfolder = ".git"
  57. if os.path.isfile(".git"):
  58. module_folder = open(".git", "r").readline().strip()
  59. if module_folder.startswith("gitdir: "):
  60. gitfolder = module_folder[8:]
  61. if os.path.isfile(os.path.join(gitfolder, "HEAD")):
  62. head = open(os.path.join(gitfolder, "HEAD"), "r").readline().strip()
  63. if head.startswith("ref: "):
  64. head = os.path.join(gitfolder, head[5:])
  65. if os.path.isfile(head):
  66. githash = open(head, "r").readline().strip()
  67. else:
  68. githash = head
  69. fhash.write("#define VERSION_HASH \"" + githash + "\"")
  70. fhash.close()
  71. def parse_cg_file(fname, uniforms, sizes, conditionals):
  72. fs = open(fname, "r")
  73. line = fs.readline()
  74. while line:
  75. if re.match(r"^\s*uniform", line):
  76. res = re.match(r"uniform ([\d\w]*) ([\d\w]*)")
  77. type = res.groups(1)
  78. name = res.groups(2)
  79. uniforms.append(name)
  80. if type.find("texobj") != -1:
  81. sizes.append(1)
  82. else:
  83. t = re.match(r"float(\d)x(\d)", type)
  84. if t:
  85. sizes.append(int(t.groups(1)) * int(t.groups(2)))
  86. else:
  87. t = re.match(r"float(\d)", type)
  88. sizes.append(int(t.groups(1)))
  89. if line.find("[branch]") != -1:
  90. conditionals.append(name)
  91. line = fs.readline()
  92. fs.close()
  93. def detect_modules():
  94. module_list = []
  95. includes_cpp = ""
  96. register_cpp = ""
  97. unregister_cpp = ""
  98. files = glob.glob("modules/*")
  99. files.sort() # so register_module_types does not change that often, and also plugins are registered in alphabetic order
  100. for x in files:
  101. if not os.path.isdir(x):
  102. continue
  103. if not os.path.exists(x + "/config.py"):
  104. continue
  105. x = x.replace("modules/", "") # rest of world
  106. x = x.replace("modules\\", "") # win32
  107. module_list.append(x)
  108. try:
  109. with open("modules/" + x + "/register_types.h"):
  110. includes_cpp += '#include "modules/' + x + '/register_types.h"\n'
  111. register_cpp += '#ifdef MODULE_' + x.upper() + '_ENABLED\n'
  112. register_cpp += '\tregister_' + x + '_types();\n'
  113. register_cpp += '#endif\n'
  114. unregister_cpp += '#ifdef MODULE_' + x.upper() + '_ENABLED\n'
  115. unregister_cpp += '\tunregister_' + x + '_types();\n'
  116. unregister_cpp += '#endif\n'
  117. except IOError:
  118. pass
  119. modules_cpp = """
  120. // modules.cpp - THIS FILE IS GENERATED, DO NOT EDIT!!!!!!!
  121. #include "register_module_types.h"
  122. """ + includes_cpp + """
  123. void register_module_types() {
  124. """ + register_cpp + """
  125. }
  126. void unregister_module_types() {
  127. """ + unregister_cpp + """
  128. }
  129. """
  130. # NOTE: It is safe to generate this file here, since this is still executed serially
  131. with open("modules/register_module_types.gen.cpp", "w") as f:
  132. f.write(modules_cpp)
  133. return module_list
  134. def win32_spawn(sh, escape, cmd, args, env):
  135. import subprocess
  136. newargs = ' '.join(args[1:])
  137. cmdline = cmd + " " + newargs
  138. startupinfo = subprocess.STARTUPINFO()
  139. for e in env:
  140. if type(env[e]) != type(""):
  141. env[e] = str(env[e])
  142. proc = subprocess.Popen(cmdline, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
  143. stderr=subprocess.PIPE, startupinfo=startupinfo, shell=False, env=env)
  144. _, err = proc.communicate()
  145. rv = proc.wait()
  146. if rv:
  147. print("=====")
  148. print(err)
  149. print("=====")
  150. return rv
  151. """
  152. def win32_spawn(sh, escape, cmd, args, spawnenv):
  153. import win32file
  154. import win32event
  155. import win32process
  156. import win32security
  157. for var in spawnenv:
  158. spawnenv[var] = spawnenv[var].encode('ascii', 'replace')
  159. sAttrs = win32security.SECURITY_ATTRIBUTES()
  160. StartupInfo = win32process.STARTUPINFO()
  161. newargs = ' '.join(map(escape, args[1:]))
  162. cmdline = cmd + " " + newargs
  163. # check for any special operating system commands
  164. if cmd == 'del':
  165. for arg in args[1:]:
  166. win32file.DeleteFile(arg)
  167. exit_code = 0
  168. else:
  169. # otherwise execute the command.
  170. hProcess, hThread, dwPid, dwTid = win32process.CreateProcess(None, cmdline, None, None, 1, 0, spawnenv, None, StartupInfo)
  171. win32event.WaitForSingleObject(hProcess, win32event.INFINITE)
  172. exit_code = win32process.GetExitCodeProcess(hProcess)
  173. win32file.CloseHandle(hProcess);
  174. win32file.CloseHandle(hThread);
  175. return exit_code
  176. """
  177. def disable_module(self):
  178. self.disabled_modules.append(self.current_module)
  179. def use_windows_spawn_fix(self, platform=None):
  180. if (os.name != "nt"):
  181. return # not needed, only for windows
  182. # On Windows, due to the limited command line length, when creating a static library
  183. # from a very high number of objects SCons will invoke "ar" once per object file;
  184. # that makes object files with same names to be overwritten so the last wins and
  185. # the library looses symbols defined by overwritten objects.
  186. # By enabling quick append instead of the default mode (replacing), libraries will
  187. # got built correctly regardless the invocation strategy.
  188. # Furthermore, since SCons will rebuild the library from scratch when an object file
  189. # changes, no multiple versions of the same object file will be present.
  190. self.Replace(ARFLAGS='q')
  191. def mySubProcess(cmdline, env):
  192. startupinfo = subprocess.STARTUPINFO()
  193. startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
  194. proc = subprocess.Popen(cmdline, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
  195. stderr=subprocess.PIPE, startupinfo=startupinfo, shell=False, env=env)
  196. _, err = proc.communicate()
  197. rv = proc.wait()
  198. if rv:
  199. print("=====")
  200. print(err)
  201. print("=====")
  202. return rv
  203. def mySpawn(sh, escape, cmd, args, env):
  204. newargs = ' '.join(args[1:])
  205. cmdline = cmd + " " + newargs
  206. rv = 0
  207. env = {str(key): str(value) for key, value in iteritems(env)}
  208. if len(cmdline) > 32000 and cmd.endswith("ar"):
  209. cmdline = cmd + " " + args[1] + " " + args[2] + " "
  210. for i in range(3, len(args)):
  211. rv = mySubProcess(cmdline + args[i], env)
  212. if rv:
  213. break
  214. else:
  215. rv = mySubProcess(cmdline, env)
  216. return rv
  217. self['SPAWN'] = mySpawn
  218. def split_lib(self, libname, src_list = None, env_lib = None):
  219. env = self
  220. num = 0
  221. cur_base = ""
  222. max_src = 64
  223. list = []
  224. lib_list = []
  225. if src_list is None:
  226. src_list = getattr(env, libname + "_sources")
  227. if type(env_lib) == type(None):
  228. env_lib = env
  229. for f in src_list:
  230. fname = ""
  231. if type(f) == type(""):
  232. fname = env.File(f).path
  233. else:
  234. fname = env.File(f)[0].path
  235. fname = fname.replace("\\", "/")
  236. base = string.join(fname.split("/")[:2], "/")
  237. if base != cur_base and len(list) > max_src:
  238. if num > 0:
  239. lib = env_lib.add_library(libname + str(num), list)
  240. lib_list.append(lib)
  241. list = []
  242. num = num + 1
  243. cur_base = base
  244. list.append(f)
  245. lib = env_lib.add_library(libname + str(num), list)
  246. lib_list.append(lib)
  247. if len(lib_list) > 0:
  248. if os.name == 'posix' and sys.platform == 'msys':
  249. env.Replace(ARFLAGS=['rcsT'])
  250. lib = env_lib.add_library(libname + "_collated", lib_list)
  251. lib_list = [lib]
  252. lib_base = []
  253. env_lib.add_source_files(lib_base, "*.cpp")
  254. lib = env_lib.add_library(libname, lib_base)
  255. lib_list.insert(0, lib)
  256. env.Prepend(LIBS=lib_list)
  257. def save_active_platforms(apnames, ap):
  258. for x in ap:
  259. names = ['logo']
  260. if os.path.isfile(x + "/run_icon.png"):
  261. names.append('run_icon')
  262. for name in names:
  263. pngf = open(x + "/" + name + ".png", "rb")
  264. b = pngf.read(1)
  265. str = " /* AUTOGENERATED FILE, DO NOT EDIT */ \n"
  266. str += " static const unsigned char _" + x[9:] + "_" + name + "[]={"
  267. while len(b) == 1:
  268. str += hex(ord(b))
  269. b = pngf.read(1)
  270. if (len(b) == 1):
  271. str += ","
  272. str += "};\n"
  273. pngf.close()
  274. # NOTE: It is safe to generate this file here, since this is still executed serially
  275. wf = x + "/" + name + ".gen.h"
  276. with open(wf, "w") as pngw:
  277. pngw.write(str)
  278. def no_verbose(sys, env):
  279. colors = {}
  280. # Colors are disabled in non-TTY environments such as pipes. This means
  281. # that if output is redirected to a file, it will not contain color codes
  282. if sys.stdout.isatty():
  283. colors['cyan'] = '\033[96m'
  284. colors['purple'] = '\033[95m'
  285. colors['blue'] = '\033[94m'
  286. colors['green'] = '\033[92m'
  287. colors['yellow'] = '\033[93m'
  288. colors['red'] = '\033[91m'
  289. colors['end'] = '\033[0m'
  290. else:
  291. colors['cyan'] = ''
  292. colors['purple'] = ''
  293. colors['blue'] = ''
  294. colors['green'] = ''
  295. colors['yellow'] = ''
  296. colors['red'] = ''
  297. colors['end'] = ''
  298. compile_source_message = '%sCompiling %s==> %s$SOURCE%s' % (colors['blue'], colors['purple'], colors['yellow'], colors['end'])
  299. java_compile_source_message = '%sCompiling %s==> %s$SOURCE%s' % (colors['blue'], colors['purple'], colors['yellow'], colors['end'])
  300. compile_shared_source_message = '%sCompiling shared %s==> %s$SOURCE%s' % (colors['blue'], colors['purple'], colors['yellow'], colors['end'])
  301. link_program_message = '%sLinking Program %s==> %s$TARGET%s' % (colors['red'], colors['purple'], colors['yellow'], colors['end'])
  302. link_library_message = '%sLinking Static Library %s==> %s$TARGET%s' % (colors['red'], colors['purple'], colors['yellow'], colors['end'])
  303. ranlib_library_message = '%sRanlib Library %s==> %s$TARGET%s' % (colors['red'], colors['purple'], colors['yellow'], colors['end'])
  304. link_shared_library_message = '%sLinking Shared Library %s==> %s$TARGET%s' % (colors['red'], colors['purple'], colors['yellow'], colors['end'])
  305. java_library_message = '%sCreating Java Archive %s==> %s$TARGET%s' % (colors['red'], colors['purple'], colors['yellow'], colors['end'])
  306. env.Append(CXXCOMSTR=[compile_source_message])
  307. env.Append(CCCOMSTR=[compile_source_message])
  308. env.Append(SHCCCOMSTR=[compile_shared_source_message])
  309. env.Append(SHCXXCOMSTR=[compile_shared_source_message])
  310. env.Append(ARCOMSTR=[link_library_message])
  311. env.Append(RANLIBCOMSTR=[ranlib_library_message])
  312. env.Append(SHLINKCOMSTR=[link_shared_library_message])
  313. env.Append(LINKCOMSTR=[link_program_message])
  314. env.Append(JARCOMSTR=[java_library_message])
  315. env.Append(JAVACCOMSTR=[java_compile_source_message])
  316. def detect_visual_c_compiler_version(tools_env):
  317. # tools_env is the variable scons uses to call tools that execute tasks, SCons's env['ENV'] that executes tasks...
  318. # (see the SCons documentation for more information on what it does)...
  319. # in order for this function to be well encapsulated i choose to force it to receive SCons's TOOLS env (env['ENV']
  320. # and not scons setup environment (env)... so make sure you call the right environment on it or it will fail to detect
  321. # the proper vc version that will be called
  322. # There is no flag to give to visual c compilers to set the architecture, ie scons bits argument (32,64,ARM etc)
  323. # There are many different cl.exe files that are run, and each one compiles & links to a different architecture
  324. # As far as I know, the only way to figure out what compiler will be run when Scons calls cl.exe via Program()
  325. # is to check the PATH variable and figure out which one will be called first. Code below does that and returns:
  326. # the following string values:
  327. # "" Compiler not detected
  328. # "amd64" Native 64 bit compiler
  329. # "amd64_x86" 64 bit Cross Compiler for 32 bit
  330. # "x86" Native 32 bit compiler
  331. # "x86_amd64" 32 bit Cross Compiler for 64 bit
  332. # There are other architectures, but Godot does not support them currently, so this function does not detect arm/amd64_arm
  333. # and similar architectures/compilers
  334. # Set chosen compiler to "not detected"
  335. vc_chosen_compiler_index = -1
  336. vc_chosen_compiler_str = ""
  337. # Start with Pre VS 2017 checks which uses VCINSTALLDIR:
  338. if 'VCINSTALLDIR' in tools_env:
  339. # print("Checking VCINSTALLDIR")
  340. # find() works with -1 so big ifs below are needed... the simplest solution, in fact
  341. # First test if amd64 and amd64_x86 compilers are present in the path
  342. vc_amd64_compiler_detection_index = tools_env["PATH"].find(tools_env["VCINSTALLDIR"] + "BIN\\amd64;")
  343. if(vc_amd64_compiler_detection_index > -1):
  344. vc_chosen_compiler_index = vc_amd64_compiler_detection_index
  345. vc_chosen_compiler_str = "amd64"
  346. vc_amd64_x86_compiler_detection_index = tools_env["PATH"].find(tools_env["VCINSTALLDIR"] + "BIN\\amd64_x86;")
  347. if(vc_amd64_x86_compiler_detection_index > -1
  348. and (vc_chosen_compiler_index == -1
  349. or vc_chosen_compiler_index > vc_amd64_x86_compiler_detection_index)):
  350. vc_chosen_compiler_index = vc_amd64_x86_compiler_detection_index
  351. vc_chosen_compiler_str = "amd64_x86"
  352. # Now check the 32 bit compilers
  353. vc_x86_compiler_detection_index = tools_env["PATH"].find(tools_env["VCINSTALLDIR"] + "BIN;")
  354. if(vc_x86_compiler_detection_index > -1
  355. and (vc_chosen_compiler_index == -1
  356. or vc_chosen_compiler_index > vc_x86_compiler_detection_index)):
  357. vc_chosen_compiler_index = vc_x86_compiler_detection_index
  358. vc_chosen_compiler_str = "x86"
  359. vc_x86_amd64_compiler_detection_index = tools_env["PATH"].find(tools_env['VCINSTALLDIR'] + "BIN\\x86_amd64;")
  360. if(vc_x86_amd64_compiler_detection_index > -1
  361. and (vc_chosen_compiler_index == -1
  362. or vc_chosen_compiler_index > vc_x86_amd64_compiler_detection_index)):
  363. vc_chosen_compiler_index = vc_x86_amd64_compiler_detection_index
  364. vc_chosen_compiler_str = "x86_amd64"
  365. # and for VS 2017 and newer we check VCTOOLSINSTALLDIR:
  366. if 'VCTOOLSINSTALLDIR' in tools_env:
  367. # Newer versions have a different path available
  368. vc_amd64_compiler_detection_index = tools_env["PATH"].upper().find(tools_env['VCTOOLSINSTALLDIR'].upper() + "BIN\\HOSTX64\\X64;")
  369. if(vc_amd64_compiler_detection_index > -1):
  370. vc_chosen_compiler_index = vc_amd64_compiler_detection_index
  371. vc_chosen_compiler_str = "amd64"
  372. vc_amd64_x86_compiler_detection_index = tools_env["PATH"].upper().find(tools_env['VCTOOLSINSTALLDIR'].upper() + "BIN\\HOSTX64\\X86;")
  373. if(vc_amd64_x86_compiler_detection_index > -1
  374. and (vc_chosen_compiler_index == -1
  375. or vc_chosen_compiler_index > vc_amd64_x86_compiler_detection_index)):
  376. vc_chosen_compiler_index = vc_amd64_x86_compiler_detection_index
  377. vc_chosen_compiler_str = "amd64_x86"
  378. vc_x86_compiler_detection_index = tools_env["PATH"].upper().find(tools_env['VCTOOLSINSTALLDIR'].upper() + "BIN\\HOSTX86\\X86;")
  379. if(vc_x86_compiler_detection_index > -1
  380. and (vc_chosen_compiler_index == -1
  381. or vc_chosen_compiler_index > vc_x86_compiler_detection_index)):
  382. vc_chosen_compiler_index = vc_x86_compiler_detection_index
  383. vc_chosen_compiler_str = "x86"
  384. vc_x86_amd64_compiler_detection_index = tools_env["PATH"].upper().find(tools_env['VCTOOLSINSTALLDIR'].upper() + "BIN\\HOSTX86\\X64;")
  385. if(vc_x86_amd64_compiler_detection_index > -1
  386. and (vc_chosen_compiler_index == -1
  387. or vc_chosen_compiler_index > vc_x86_amd64_compiler_detection_index)):
  388. vc_chosen_compiler_index = vc_x86_amd64_compiler_detection_index
  389. vc_chosen_compiler_str = "x86_amd64"
  390. return vc_chosen_compiler_str
  391. def find_visual_c_batch_file(env):
  392. from SCons.Tool.MSCommon.vc import get_default_version, get_host_target, find_batch_file
  393. version = get_default_version(env)
  394. (host_platform, target_platform, _) = get_host_target(env)
  395. return find_batch_file(env, version, host_platform, target_platform)[0]
  396. def generate_cpp_hint_file(filename):
  397. if os.path.isfile(filename):
  398. # Don't overwrite an existing hint file since the user may have customized it.
  399. pass
  400. else:
  401. try:
  402. with open(filename, "w") as fd:
  403. fd.write("#define GDCLASS(m_class, m_inherits)\n")
  404. except IOError:
  405. print("Could not write cpp.hint file.")
  406. def generate_vs_project(env, num_jobs):
  407. batch_file = find_visual_c_batch_file(env)
  408. if batch_file:
  409. def build_commandline(commands):
  410. common_build_prefix = ['cmd /V /C set "plat=$(PlatformTarget)"',
  411. '(if "$(PlatformTarget)"=="x64" (set "plat=x86_amd64"))',
  412. 'set "tools=yes"',
  413. '(if "$(Configuration)"=="release" (set "tools=no"))',
  414. 'call "' + batch_file + '" !plat!']
  415. result = " ^& ".join(common_build_prefix + [commands])
  416. return result
  417. env.AddToVSProject(env.core_sources)
  418. env.AddToVSProject(env.main_sources)
  419. env.AddToVSProject(env.modules_sources)
  420. env.AddToVSProject(env.scene_sources)
  421. env.AddToVSProject(env.servers_sources)
  422. env.AddToVSProject(env.editor_sources)
  423. # windows allows us to have spaces in paths, so we need
  424. # to double quote off the directory. However, the path ends
  425. # in a backslash, so we need to remove this, lest it escape the
  426. # last double quote off, confusing MSBuild
  427. env['MSVSBUILDCOM'] = build_commandline('scons --directory="$(ProjectDir.TrimEnd(\'\\\'))" platform=windows progress=no target=$(Configuration) tools=!tools! -j' + str(num_jobs))
  428. env['MSVSREBUILDCOM'] = build_commandline('scons --directory="$(ProjectDir.TrimEnd(\'\\\'))" platform=windows progress=no target=$(Configuration) tools=!tools! vsproj=yes -j' + str(num_jobs))
  429. env['MSVSCLEANCOM'] = build_commandline('scons --directory="$(ProjectDir.TrimEnd(\'\\\'))" --clean platform=windows progress=no target=$(Configuration) tools=!tools! -j' + str(num_jobs))
  430. # This version information (Win32, x64, Debug, Release, Release_Debug seems to be
  431. # required for Visual Studio to understand that it needs to generate an NMAKE
  432. # project. Do not modify without knowing what you are doing.
  433. debug_variants = ['debug|Win32'] + ['debug|x64']
  434. release_variants = ['release|Win32'] + ['release|x64']
  435. release_debug_variants = ['release_debug|Win32'] + ['release_debug|x64']
  436. variants = debug_variants + release_variants + release_debug_variants
  437. debug_targets = ['bin\\godot.windows.tools.32.exe'] + ['bin\\godot.windows.tools.64.exe']
  438. release_targets = ['bin\\godot.windows.opt.32.exe'] + ['bin\\godot.windows.opt.64.exe']
  439. release_debug_targets = ['bin\\godot.windows.opt.tools.32.exe'] + ['bin\\godot.windows.opt.tools.64.exe']
  440. targets = debug_targets + release_targets + release_debug_targets
  441. if not env.get('MSVS'):
  442. env['MSVS']['PROJECTSUFFIX'] = '.vcxproj'
  443. env['MSVS']['SOLUTIONSUFFIX'] = '.sln'
  444. env.MSVSProject(
  445. target=['#godot' + env['MSVSPROJECTSUFFIX']],
  446. incs=env.vs_incs,
  447. srcs=env.vs_srcs,
  448. runfile=targets,
  449. buildtarget=targets,
  450. auto_build_solution=1,
  451. variant=variants)
  452. else:
  453. print("Could not locate Visual Studio batch file for setting up the build environment. Not generating VS project.")
  454. def precious_program(env, program, sources, **args):
  455. program = env.ProgramOriginal(program, sources, **args)
  456. env.Precious(program)
  457. return program
  458. def add_shared_library(env, name, sources, **args):
  459. library = env.SharedLibrary(name, sources, **args)
  460. env.NoCache(library)
  461. return library
  462. def add_library(env, name, sources, **args):
  463. library = env.Library(name, sources, **args)
  464. env.NoCache(library)
  465. return library
  466. def add_program(env, name, sources, **args):
  467. program = env.Program(name, sources, **args)
  468. env.NoCache(program)
  469. return program
  470. def CommandNoCache(env, target, sources, command, **args):
  471. result = env.Command(target, sources, command, **args)
  472. env.NoCache(result)
  473. return result
  474. def detect_darwin_sdk_path(platform, env):
  475. sdk_name = ''
  476. if platform == 'osx':
  477. sdk_name = 'macosx'
  478. var_name = 'MACOS_SDK_PATH'
  479. elif platform == 'iphone':
  480. sdk_name = 'iphoneos'
  481. var_name = 'IPHONESDK'
  482. elif platform == 'iphonesimulator':
  483. sdk_name = 'iphonesimulator'
  484. var_name = 'IPHONESDK'
  485. else:
  486. raise Exception("Invalid platform argument passed to detect_darwin_sdk_path")
  487. if not env[var_name]:
  488. try:
  489. sdk_path = decode_utf8(subprocess.check_output(['xcrun', '--sdk', sdk_name, '--show-sdk-path']).strip())
  490. if sdk_path:
  491. env[var_name] = sdk_path
  492. except (subprocess.CalledProcessError, OSError):
  493. print("Failed to find SDK path while running xcrun --sdk {} --show-sdk-path.".format(sdk_name))
  494. raise
  495. def get_compiler_version(env):
  496. version = decode_utf8(subprocess.check_output([env['CXX'], '--version']).strip())
  497. match = re.search('[0-9][0-9.]*', version)
  498. if match is not None:
  499. return match.group().split('.')
  500. else:
  501. return None
  502. def using_gcc(env):
  503. return 'gcc' in os.path.basename(env["CC"])
  504. def using_clang(env):
  505. return 'clang' in os.path.basename(env["CC"])