methods.py 24 KB

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