SConstruct 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  1. EnsureSConsVersion(0,14);
  2. import string
  3. import os
  4. import os.path
  5. import glob
  6. import sys
  7. import methods
  8. methods.update_version()
  9. # scan possible build platforms
  10. platform_list = [] # list of platforms
  11. platform_opts = {} # options for each platform
  12. platform_flags = {} # flags for each platform
  13. active_platforms=[]
  14. active_platform_ids=[]
  15. platform_exporters=[]
  16. global_defaults=[]
  17. for x in glob.glob("platform/*"):
  18. if (not os.path.isdir(x) or not os.path.exists(x+"/detect.py")):
  19. continue
  20. tmppath="./"+x
  21. sys.path.append(tmppath)
  22. import detect
  23. if (os.path.exists(x+"/export/export.cpp")):
  24. platform_exporters.append(x[9:])
  25. if (os.path.exists(x+"/globals/global_defaults.cpp")):
  26. global_defaults.append(x[9:])
  27. if (detect.is_active()):
  28. active_platforms.append( detect.get_name() )
  29. active_platform_ids.append(x);
  30. if (detect.can_build()):
  31. x=x.replace("platform/","") # rest of world
  32. x=x.replace("platform\\","") # win32
  33. platform_list+=[x]
  34. platform_opts[x]=detect.get_opts()
  35. platform_flags[x]=detect.get_flags()
  36. sys.path.remove(tmppath)
  37. sys.modules.pop('detect')
  38. module_list=methods.detect_modules()
  39. #print "Detected Platforms: "+str(platform_list)
  40. methods.save_active_platforms(active_platforms,active_platform_ids)
  41. custom_tools=['default']
  42. platform_arg = ARGUMENTS.get("platform", ARGUMENTS.get("p", False))
  43. if (os.name=="posix"):
  44. pass
  45. elif (os.name=="nt"):
  46. if (not methods.msvc_is_detected() or platform_arg=="android"):
  47. custom_tools=['mingw']
  48. env_base=Environment(tools=custom_tools);
  49. env_base.AppendENVPath('PATH', os.getenv('PATH'))
  50. env_base.AppendENVPath('PKG_CONFIG_PATH', os.getenv('PKG_CONFIG_PATH'))
  51. env_base.global_defaults=global_defaults
  52. env_base.android_maven_repos=[]
  53. env_base.android_dependencies=[]
  54. env_base.android_java_dirs=[]
  55. env_base.android_res_dirs=[]
  56. env_base.android_aidl_dirs=[]
  57. env_base.android_jni_dirs=[]
  58. env_base.android_default_config=[]
  59. env_base.android_manifest_chunk=""
  60. env_base.android_permission_chunk=""
  61. env_base.android_appattributes_chunk=""
  62. env_base.disabled_modules=[]
  63. env_base.use_ptrcall=False
  64. env_base.split_drivers=False
  65. env_base.__class__.android_add_maven_repository=methods.android_add_maven_repository
  66. env_base.__class__.android_add_dependency=methods.android_add_dependency
  67. env_base.__class__.android_add_java_dir=methods.android_add_java_dir
  68. env_base.__class__.android_add_res_dir=methods.android_add_res_dir
  69. env_base.__class__.android_add_aidl_dir=methods.android_add_aidl_dir
  70. env_base.__class__.android_add_jni_dir=methods.android_add_jni_dir
  71. env_base.__class__.android_add_default_config=methods.android_add_default_config
  72. env_base.__class__.android_add_to_manifest = methods.android_add_to_manifest
  73. env_base.__class__.android_add_to_permissions = methods.android_add_to_permissions
  74. env_base.__class__.android_add_to_attributes = methods.android_add_to_attributes
  75. env_base.__class__.disable_module = methods.disable_module
  76. env_base.__class__.add_source_files = methods.add_source_files
  77. env_base.__class__.use_windows_spawn_fix = methods.use_windows_spawn_fix
  78. env_base["x86_opt_gcc"]=False
  79. env_base["x86_opt_vc"]=False
  80. env_base["armv7_opt_gcc"]=False
  81. customs = ['custom.py']
  82. profile = ARGUMENTS.get("profile", False)
  83. if profile:
  84. import os.path
  85. if os.path.isfile(profile):
  86. customs.append(profile)
  87. elif os.path.isfile(profile+".py"):
  88. customs.append(profile+".py")
  89. opts=Variables(customs, ARGUMENTS)
  90. opts.Add('target', 'Compile Target (debug/release_debug/release).', "debug")
  91. opts.Add('arch', 'Platform dependent architecture (arm/arm64/x86/x64/mips/etc)', "")
  92. opts.Add('bits', 'Compile Target Bits (default/32/64/fat).', "default")
  93. opts.Add('platform','Platform: '+str(platform_list)+'.',"")
  94. opts.Add('p','Platform (same as platform=).',"")
  95. opts.Add('tools','Build Tools (Including Editor): (yes/no)','yes')
  96. opts.Add('gdscript','Build GDSCript support: (yes/no)','yes')
  97. opts.Add('libogg','Ogg library for ogg container support (system/builtin)','builtin')
  98. opts.Add('libvorbis','Ogg Vorbis library for vorbis support (system/builtin)','builtin')
  99. opts.Add('opus','Opus and opusfile library for Opus format support: (system/builtin)','builtin')
  100. opts.Add('minizip','Build Minizip Archive Support: (yes/no)','yes')
  101. opts.Add('squish','Squish BC Texture Compression in editor (yes/no)','yes')
  102. opts.Add('theora','Theora Video (yes/no)','yes')
  103. opts.Add('theoralib','Theora Video (yes/no)','no')
  104. opts.Add('freetype','Freetype support in editor','builtin')
  105. opts.Add('xml','XML Save/Load support (yes/no)','yes')
  106. opts.Add('libpng','libpng library for image loader support (system/builtin)','builtin')
  107. opts.Add('libwebp','libwebp library for webp module (system/builtin)','builtin')
  108. opts.Add('builtin_zlib','Use built-in zlib (yes/no)','yes')
  109. opts.Add('openssl','Use OpenSSL (yes/no/builtin)','no')
  110. opts.Add('musepack','Musepack Audio (yes/no)','yes')
  111. opts.Add('enet','ENet library (system/builtin)','builtin')
  112. opts.Add("CXX", "C++ Compiler")
  113. opts.Add("CC", "C Compiler")
  114. opts.Add("CCFLAGS", "Custom flags for the C++ compiler");
  115. opts.Add("CFLAGS", "Custom flags for the C compiler");
  116. opts.Add("LINKFLAGS", "Custom flags for the linker");
  117. opts.Add('unix_global_settings_path', 'unix-specific path to system-wide settings. Currently only used by templates.','')
  118. opts.Add('disable_3d', 'Disable 3D nodes for smaller executable (yes/no)', "no")
  119. opts.Add('disable_advanced_gui', 'Disable advance 3D gui nodes and behaviors (yes/no)', "no")
  120. opts.Add('colored', 'Enable colored output for the compilation (yes/no)', 'no')
  121. opts.Add('deprecated','Enable deprecated features (yes/no)','yes')
  122. opts.Add('extra_suffix', 'Custom extra suffix added to the base filename of all generated binary files.', '')
  123. opts.Add('vsproj', 'Generate Visual Studio Project. (yes/no)', 'no')
  124. # add platform specific options
  125. for k in platform_opts.keys():
  126. opt_list = platform_opts[k]
  127. for o in opt_list:
  128. opts.Add(o[0],o[1],o[2])
  129. for x in module_list:
  130. opts.Add('module_'+x+'_enabled', "Enable module '"+x+"' (yes/no)", "yes")
  131. opts.Update(env_base) # update environment
  132. Help(opts.GenerateHelpText(env_base)) # generate help
  133. # add default include paths
  134. env_base.Append(CPPPATH=['#core','#core/math','#tools','#drivers','#'])
  135. # configure ENV for platform
  136. env_base.platform_exporters=platform_exporters
  137. """
  138. sys.path.append("./platform/"+env_base["platform"])
  139. import detect
  140. detect.configure(env_base)
  141. sys.path.remove("./platform/"+env_base["platform"])
  142. sys.modules.pop('detect')
  143. """
  144. if (env_base['target']=='debug'):
  145. env_base.Append(CPPFLAGS=['-DDEBUG_MEMORY_ALLOC']);
  146. env_base.Append(CPPFLAGS=['-DSCI_NAMESPACE'])
  147. if (env_base['deprecated']!='no'):
  148. env_base.Append(CPPFLAGS=['-DENABLE_DEPRECATED']);
  149. env_base.platforms = {}
  150. selected_platform =""
  151. if env_base['platform'] != "":
  152. selected_platform=env_base['platform']
  153. elif env_base['p'] != "":
  154. selected_platform=env_base['p']
  155. env_base["platform"]=selected_platform
  156. if selected_platform in platform_list:
  157. sys.path.append("./platform/"+selected_platform)
  158. import detect
  159. if "create" in dir(detect):
  160. env = detect.create(env_base)
  161. else:
  162. env = env_base.Clone()
  163. if env['vsproj']=="yes":
  164. env.vs_incs = []
  165. env.vs_srcs = []
  166. def AddToVSProject( sources ):
  167. for x in sources:
  168. if type(x) == type(""):
  169. fname = env.File(x).path
  170. else:
  171. fname = env.File(x)[0].path
  172. pieces = fname.split(".")
  173. if len(pieces)>0:
  174. basename = pieces[0]
  175. basename = basename.replace('\\\\','/')
  176. env.vs_srcs = env.vs_srcs + [basename + ".cpp"]
  177. env.vs_incs = env.vs_incs + [basename + ".h"]
  178. #print basename
  179. env.AddToVSProject = AddToVSProject
  180. env.extra_suffix=""
  181. if env["extra_suffix"] != '' :
  182. env.extra_suffix += '.'+env["extra_suffix"]
  183. CCFLAGS = env.get('CCFLAGS', '')
  184. env['CCFLAGS'] = ''
  185. env.Append(CCFLAGS=string.split(str(CCFLAGS)))
  186. CFLAGS = env.get('CFLAGS', '')
  187. env['CFLAGS'] = ''
  188. env.Append(CFLAGS=string.split(str(CFLAGS)))
  189. LINKFLAGS = env.get('LINKFLAGS', '')
  190. env['LINKFLAGS'] = ''
  191. env.Append(LINKFLAGS=string.split(str(LINKFLAGS)))
  192. flag_list = platform_flags[selected_platform]
  193. for f in flag_list:
  194. if not (f[0] in ARGUMENTS): # allow command line to override platform flags
  195. env[f[0]] = f[1]
  196. #must happen after the flags, so when flags are used by configure, stuff happens (ie, ssl on x11)
  197. detect.configure(env)
  198. if (env["freetype"]!="no"):
  199. env.Append(CCFLAGS=['-DFREETYPE_ENABLED'])
  200. if (env["freetype"]=="builtin"):
  201. env.Append(CPPPATH=['#drivers/freetype'])
  202. env.Append(CPPPATH=['#drivers/freetype/freetype/include'])
  203. #env['platform_libsuffix'] = env['LIBSUFFIX']
  204. suffix="."+selected_platform
  205. if (env["target"]=="release"):
  206. if (env["tools"]=="yes"):
  207. print("Tools can only be built with targets 'debug' and 'release_debug'.")
  208. sys.exit(255)
  209. suffix+=".opt"
  210. elif (env["target"]=="release_debug"):
  211. if (env["tools"]=="yes"):
  212. suffix+=".opt.tools"
  213. else:
  214. suffix+=".opt.debug"
  215. else:
  216. if (env["tools"]=="yes"):
  217. suffix+=".tools"
  218. else:
  219. suffix+=".debug"
  220. if env["arch"] != "":
  221. suffix += "."+env["arch"]
  222. elif (env["bits"]=="32"):
  223. suffix+=".32"
  224. elif (env["bits"]=="64"):
  225. suffix+=".64"
  226. elif (env["bits"]=="fat"):
  227. suffix+=".fat"
  228. suffix+=env.extra_suffix
  229. env["PROGSUFFIX"]=suffix+env["PROGSUFFIX"]
  230. env["OBJSUFFIX"]=suffix+env["OBJSUFFIX"]
  231. env["LIBSUFFIX"]=suffix+env["LIBSUFFIX"]
  232. env["SHLIBSUFFIX"]=suffix+env["SHLIBSUFFIX"]
  233. sys.path.remove("./platform/"+selected_platform)
  234. sys.modules.pop('detect')
  235. env.module_list=[]
  236. for x in module_list:
  237. if env['module_'+x+'_enabled'] != "yes":
  238. continue
  239. tmppath="./modules/"+x
  240. sys.path.append(tmppath)
  241. env.current_module=x
  242. import config
  243. if (config.can_build(selected_platform)):
  244. config.configure(env)
  245. env.module_list.append(x)
  246. sys.path.remove(tmppath)
  247. sys.modules.pop('config')
  248. if (env.use_ptrcall):
  249. env.Append(CPPFLAGS=['-DPTRCALL_ENABLED']);
  250. if (env['musepack']=='yes'):
  251. env.Append(CPPFLAGS=['-DMUSEPACK_ENABLED']);
  252. #if (env['openssl']!='no'):
  253. # env.Append(CPPFLAGS=['-DOPENSSL_ENABLED']);
  254. # if (env['openssl']=="builtin"):
  255. # env.Append(CPPPATH=['#drivers/builtin_openssl2'])
  256. if (env["builtin_zlib"]=='yes'):
  257. env.Append(CPPPATH=['#drivers/builtin_zlib/zlib'])
  258. # to test 64 bits compiltion
  259. # env.Append(CPPFLAGS=['-m64'])
  260. if (env_base['squish']=='yes'):
  261. env.Append(CPPFLAGS=['-DSQUISH_ENABLED']);
  262. if (env['theora']=='yes'):
  263. env['theoralib']='yes'
  264. env.Append(CPPFLAGS=['-DTHEORA_ENABLED']);
  265. if (env['theoralib']=='yes'):
  266. env.Append(CPPFLAGS=['-DTHEORALIB_ENABLED']);
  267. if (env['tools']=='yes'):
  268. env.Append(CPPFLAGS=['-DTOOLS_ENABLED'])
  269. if (env['disable_3d']=='yes'):
  270. env.Append(CPPFLAGS=['-D_3D_DISABLED'])
  271. if (env['gdscript']=='yes'):
  272. env.Append(CPPFLAGS=['-DGDSCRIPT_ENABLED'])
  273. if (env['disable_advanced_gui']=='yes'):
  274. env.Append(CPPFLAGS=['-DADVANCED_GUI_DISABLED'])
  275. if (env['minizip'] == 'yes'):
  276. env.Append(CPPFLAGS=['-DMINIZIP_ENABLED'])
  277. if (env['xml']=='yes'):
  278. env.Append(CPPFLAGS=['-DXML_ENABLED'])
  279. if (env['colored']=='yes'):
  280. methods.colored(sys,env)
  281. Export('env')
  282. #build subdirs, the build order is dependent on link order.
  283. SConscript("core/SCsub")
  284. SConscript("servers/SCsub")
  285. SConscript("scene/SCsub")
  286. SConscript("tools/SCsub")
  287. SConscript("drivers/SCsub")
  288. SConscript("bin/SCsub")
  289. SConscript("modules/SCsub")
  290. SConscript("main/SCsub")
  291. SConscript("platform/"+selected_platform+"/SCsub"); # build selected platform
  292. # Microsoft Visual Studio Project Generation
  293. if (env['vsproj'])=="yes":
  294. AddToVSProject(env.core_sources)
  295. AddToVSProject(env.main_sources)
  296. AddToVSProject(env.modules_sources)
  297. AddToVSProject(env.scene_sources)
  298. AddToVSProject(env.servers_sources)
  299. AddToVSProject(env.tool_sources)
  300. # this env flag won't work, it needs to be set in env_base=Environment(MSVC_VERSION='9.0')
  301. # Even then, SCons still seems to ignore it and builds with the latest MSVC...
  302. # That said, it's not needed to be set so far but I'm leaving it here so that this comment
  303. # has a purpose.
  304. #env['MSVS_VERSION']='9.0'
  305. # Calls a CMD with /C(lose) and /V(delayed environment variable expansion) options.
  306. # And runs vcvarsall bat for the propper arhitecture and scons for propper configuration
  307. env['MSVSBUILDCOM'] = 'cmd /V /C set "plat=$(PlatformTarget)" ^& (if "$(PlatformTarget)"=="x64" (set "plat=x86_amd64")) ^& set "tools=yes" ^& (if "$(Configuration)"=="release" (set "tools=no")) ^& call "$(VCInstallDir)vcvarsall.bat" !plat! ^& scons platform=windows target=$(Configuration) tools=!tools! -j2'
  308. env['MSVSREBUILDCOM'] = 'cmd /V /C set "plat=$(PlatformTarget)" ^& (if "$(PlatformTarget)"=="x64" (set "plat=x86_amd64")) ^& set "tools=yes" ^& (if "$(Configuration)"=="release" (set "tools=no")) & call "$(VCInstallDir)vcvarsall.bat" !plat! ^& scons platform=windows target=$(Configuration) tools=!tools! vsproj=yes -j2'
  309. env['MSVSCLEANCOM'] = 'cmd /V /C set "plat=$(PlatformTarget)" ^& (if "$(PlatformTarget)"=="x64" (set "plat=x86_amd64")) ^& set "tools=yes" ^& (if "$(Configuration)"=="release" (set "tools=no")) ^& call "$(VCInstallDir)vcvarsall.bat" !plat! ^& scons --clean platform=windows target=$(Configuration) tools=!tools! -j2'
  310. # This version information (Win32, x64, Debug, Release, Release_Debug seems to be
  311. # required for Visual Studio to understand that it needs to generate an NMAKE
  312. # project. Do not modify without knowing what you are doing.
  313. debug_variants = ['debug|Win32']+['debug|x64']
  314. release_variants = ['release|Win32']+['release|x64']
  315. release_debug_variants = ['release_debug|Win32']+['release_debug|x64']
  316. variants = debug_variants + release_variants + release_debug_variants
  317. debug_targets = ['Debug']+['Debug']
  318. release_targets = ['Release']+['Release']
  319. release_debug_targets = ['ReleaseDebug']+['ReleaseDebug']
  320. targets = debug_targets + release_targets + release_debug_targets
  321. msvproj = env.MSVSProject(target = ['#godot' + env['MSVSPROJECTSUFFIX'] ],
  322. incs = env.vs_incs,
  323. srcs = env.vs_srcs,
  324. runfile = targets,
  325. buildtarget = targets,
  326. auto_build_solution=1,
  327. variant = variants)
  328. else:
  329. print("No valid target platform selected.")
  330. print("The following were detected:")
  331. for x in platform_list:
  332. print("\t"+x)
  333. print("\nPlease run scons again with argument: platform=<string>")