SConstruct 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406
  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('libtheora','Theora library for theora module (system/builtin)','builtin')
  100. opts.Add('opus','Opus and opusfile library for Opus format support: (system/builtin)','builtin')
  101. opts.Add('minizip','Build Minizip Archive Support: (yes/no)','yes')
  102. opts.Add('squish','Squish library for BC Texture Compression in editor (system/builtin)','builtin')
  103. opts.Add('freetype','Freetype support in editor','builtin')
  104. opts.Add('xml','XML Save/Load support (yes/no)','yes')
  105. opts.Add('libpng','libpng library for image loader support (system/builtin)','builtin')
  106. opts.Add('libwebp','libwebp library for webp module (system/builtin)','builtin')
  107. opts.Add('openssl','OpenSSL library for openssl module (system/builtin)','builtin')
  108. opts.Add('libmpcdec','libmpcdec library for mpc module (system/builtin)','builtin')
  109. opts.Add('enet','ENet library (system/builtin)','builtin')
  110. opts.Add('glew','GLEW library for the gl_context (system/builtin)','builtin')
  111. opts.Add("CXX", "C++ Compiler")
  112. opts.Add("CC", "C Compiler")
  113. opts.Add("CCFLAGS", "Custom flags for the C++ compiler");
  114. opts.Add("CFLAGS", "Custom flags for the C compiler");
  115. opts.Add("LINKFLAGS", "Custom flags for the linker");
  116. opts.Add('unix_global_settings_path', 'unix-specific path to system-wide settings. Currently only used by templates.','')
  117. opts.Add('disable_3d', 'Disable 3D nodes for smaller executable (yes/no)', "no")
  118. opts.Add('disable_advanced_gui', 'Disable advance 3D gui nodes and behaviors (yes/no)', "no")
  119. opts.Add('colored', 'Enable colored output for the compilation (yes/no)', 'no')
  120. opts.Add('deprecated','Enable deprecated features (yes/no)','yes')
  121. opts.Add('extra_suffix', 'Custom extra suffix added to the base filename of all generated binary files.', '')
  122. opts.Add('vsproj', 'Generate Visual Studio Project. (yes/no)', 'no')
  123. # add platform specific options
  124. for k in platform_opts.keys():
  125. opt_list = platform_opts[k]
  126. for o in opt_list:
  127. opts.Add(o[0],o[1],o[2])
  128. for x in module_list:
  129. opts.Add('module_'+x+'_enabled', "Enable module '"+x+"' (yes/no)", "yes")
  130. opts.Update(env_base) # update environment
  131. Help(opts.GenerateHelpText(env_base)) # generate help
  132. # add default include paths
  133. env_base.Append(CPPPATH=['#core','#core/math','#tools','#drivers','#'])
  134. # configure ENV for platform
  135. env_base.platform_exporters=platform_exporters
  136. """
  137. sys.path.append("./platform/"+env_base["platform"])
  138. import detect
  139. detect.configure(env_base)
  140. sys.path.remove("./platform/"+env_base["platform"])
  141. sys.modules.pop('detect')
  142. """
  143. if (env_base['target']=='debug'):
  144. env_base.Append(CPPFLAGS=['-DDEBUG_MEMORY_ALLOC']);
  145. env_base.Append(CPPFLAGS=['-DSCI_NAMESPACE'])
  146. if (env_base['deprecated']!='no'):
  147. env_base.Append(CPPFLAGS=['-DENABLE_DEPRECATED']);
  148. env_base.platforms = {}
  149. selected_platform =""
  150. if env_base['platform'] != "":
  151. selected_platform=env_base['platform']
  152. elif env_base['p'] != "":
  153. selected_platform=env_base['p']
  154. env_base["platform"]=selected_platform
  155. if selected_platform in platform_list:
  156. sys.path.append("./platform/"+selected_platform)
  157. import detect
  158. if "create" in dir(detect):
  159. env = detect.create(env_base)
  160. else:
  161. env = env_base.Clone()
  162. if env['vsproj']=="yes":
  163. env.vs_incs = []
  164. env.vs_srcs = []
  165. def AddToVSProject( sources ):
  166. for x in sources:
  167. if type(x) == type(""):
  168. fname = env.File(x).path
  169. else:
  170. fname = env.File(x)[0].path
  171. pieces = fname.split(".")
  172. if len(pieces)>0:
  173. basename = pieces[0]
  174. basename = basename.replace('\\\\','/')
  175. env.vs_srcs = env.vs_srcs + [basename + ".cpp"]
  176. env.vs_incs = env.vs_incs + [basename + ".h"]
  177. #print basename
  178. env.AddToVSProject = AddToVSProject
  179. env.extra_suffix=""
  180. if env["extra_suffix"] != '' :
  181. env.extra_suffix += '.'+env["extra_suffix"]
  182. CCFLAGS = env.get('CCFLAGS', '')
  183. env['CCFLAGS'] = ''
  184. env.Append(CCFLAGS=string.split(str(CCFLAGS)))
  185. CFLAGS = env.get('CFLAGS', '')
  186. env['CFLAGS'] = ''
  187. env.Append(CFLAGS=string.split(str(CFLAGS)))
  188. LINKFLAGS = env.get('LINKFLAGS', '')
  189. env['LINKFLAGS'] = ''
  190. env.Append(LINKFLAGS=string.split(str(LINKFLAGS)))
  191. flag_list = platform_flags[selected_platform]
  192. for f in flag_list:
  193. if not (f[0] in ARGUMENTS): # allow command line to override platform flags
  194. env[f[0]] = f[1]
  195. #must happen after the flags, so when flags are used by configure, stuff happens (ie, ssl on x11)
  196. detect.configure(env)
  197. if (env["freetype"]!="no"):
  198. env.Append(CCFLAGS=['-DFREETYPE_ENABLED'])
  199. if (env["freetype"]=="builtin"):
  200. env.Append(CPPPATH=['#drivers/freetype'])
  201. env.Append(CPPPATH=['#drivers/freetype/freetype/include'])
  202. #env['platform_libsuffix'] = env['LIBSUFFIX']
  203. suffix="."+selected_platform
  204. if (env["target"]=="release"):
  205. if (env["tools"]=="yes"):
  206. print("Tools can only be built with targets 'debug' and 'release_debug'.")
  207. sys.exit(255)
  208. suffix+=".opt"
  209. elif (env["target"]=="release_debug"):
  210. if (env["tools"]=="yes"):
  211. suffix+=".opt.tools"
  212. else:
  213. suffix+=".opt.debug"
  214. else:
  215. if (env["tools"]=="yes"):
  216. suffix+=".tools"
  217. else:
  218. suffix+=".debug"
  219. if env["arch"] != "":
  220. suffix += "."+env["arch"]
  221. elif (env["bits"]=="32"):
  222. suffix+=".32"
  223. elif (env["bits"]=="64"):
  224. suffix+=".64"
  225. elif (env["bits"]=="fat"):
  226. suffix+=".fat"
  227. suffix+=env.extra_suffix
  228. env["PROGSUFFIX"]=suffix+env["PROGSUFFIX"]
  229. env["OBJSUFFIX"]=suffix+env["OBJSUFFIX"]
  230. env["LIBSUFFIX"]=suffix+env["LIBSUFFIX"]
  231. env["SHLIBSUFFIX"]=suffix+env["SHLIBSUFFIX"]
  232. sys.path.remove("./platform/"+selected_platform)
  233. sys.modules.pop('detect')
  234. env.module_list=[]
  235. for x in module_list:
  236. if env['module_'+x+'_enabled'] != "yes":
  237. continue
  238. tmppath="./modules/"+x
  239. sys.path.append(tmppath)
  240. env.current_module=x
  241. import config
  242. if (config.can_build(selected_platform)):
  243. config.configure(env)
  244. env.module_list.append(x)
  245. sys.path.remove(tmppath)
  246. sys.modules.pop('config')
  247. if (env.use_ptrcall):
  248. env.Append(CPPFLAGS=['-DPTRCALL_ENABLED']);
  249. # to test 64 bits compiltion
  250. # env.Append(CPPFLAGS=['-m64'])
  251. if (env['tools']=='yes'):
  252. env.Append(CPPFLAGS=['-DTOOLS_ENABLED'])
  253. if (env['disable_3d']=='yes'):
  254. env.Append(CPPFLAGS=['-D_3D_DISABLED'])
  255. if (env['gdscript']=='yes'):
  256. env.Append(CPPFLAGS=['-DGDSCRIPT_ENABLED'])
  257. if (env['disable_advanced_gui']=='yes'):
  258. env.Append(CPPFLAGS=['-DADVANCED_GUI_DISABLED'])
  259. if (env['minizip'] == 'yes'):
  260. env.Append(CPPFLAGS=['-DMINIZIP_ENABLED'])
  261. if (env['xml']=='yes'):
  262. env.Append(CPPFLAGS=['-DXML_ENABLED'])
  263. if (env['colored']=='yes'):
  264. methods.colored(sys,env)
  265. Export('env')
  266. #build subdirs, the build order is dependent on link order.
  267. SConscript("core/SCsub")
  268. SConscript("servers/SCsub")
  269. SConscript("scene/SCsub")
  270. SConscript("tools/SCsub")
  271. SConscript("drivers/SCsub")
  272. SConscript("bin/SCsub")
  273. SConscript("modules/SCsub")
  274. SConscript("main/SCsub")
  275. SConscript("platform/"+selected_platform+"/SCsub"); # build selected platform
  276. # Microsoft Visual Studio Project Generation
  277. if (env['vsproj'])=="yes":
  278. AddToVSProject(env.core_sources)
  279. AddToVSProject(env.main_sources)
  280. AddToVSProject(env.modules_sources)
  281. AddToVSProject(env.scene_sources)
  282. AddToVSProject(env.servers_sources)
  283. AddToVSProject(env.tool_sources)
  284. # this env flag won't work, it needs to be set in env_base=Environment(MSVC_VERSION='9.0')
  285. # Even then, SCons still seems to ignore it and builds with the latest MSVC...
  286. # That said, it's not needed to be set so far but I'm leaving it here so that this comment
  287. # has a purpose.
  288. #env['MSVS_VERSION']='9.0'
  289. # Calls a CMD with /C(lose) and /V(delayed environment variable expansion) options.
  290. # And runs vcvarsall bat for the propper arhitecture and scons for propper configuration
  291. 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'
  292. 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'
  293. 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'
  294. # This version information (Win32, x64, Debug, Release, Release_Debug seems to be
  295. # required for Visual Studio to understand that it needs to generate an NMAKE
  296. # project. Do not modify without knowing what you are doing.
  297. debug_variants = ['debug|Win32']+['debug|x64']
  298. release_variants = ['release|Win32']+['release|x64']
  299. release_debug_variants = ['release_debug|Win32']+['release_debug|x64']
  300. variants = debug_variants + release_variants + release_debug_variants
  301. debug_targets = ['Debug']+['Debug']
  302. release_targets = ['Release']+['Release']
  303. release_debug_targets = ['ReleaseDebug']+['ReleaseDebug']
  304. targets = debug_targets + release_targets + release_debug_targets
  305. msvproj = env.MSVSProject(target = ['#godot' + env['MSVSPROJECTSUFFIX'] ],
  306. incs = env.vs_incs,
  307. srcs = env.vs_srcs,
  308. runfile = targets,
  309. buildtarget = targets,
  310. auto_build_solution=1,
  311. variant = variants)
  312. else:
  313. print("No valid target platform selected.")
  314. print("The following were detected:")
  315. for x in platform_list:
  316. print("\t"+x)
  317. print("\nPlease run scons again with argument: platform=<string>")