SConstruct 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!python
  2. import os, subprocess
  3. opts = Variables([], ARGUMENTS)
  4. # Gets the standard flags CC, CCX, etc.
  5. env = DefaultEnvironment()
  6. # Define our options
  7. opts.Add(EnumVariable('target', "Compilation target", 'debug', ['d', 'debug', 'r', 'release']))
  8. opts.Add(EnumVariable('platform', "Compilation platform", '', ['', 'windows', 'x11', 'linux', 'osx']))
  9. opts.Add(EnumVariable('p', "Compilation target, alias for 'platform'", '', ['', 'windows', 'x11', 'linux', 'osx']))
  10. opts.Add(BoolVariable('use_llvm', "Use the LLVM / Clang compiler", 'no'))
  11. opts.Add(PathVariable('target_path', 'The path where the lib is installed.', 'demo/bin/'))
  12. opts.Add(PathVariable('target_name', 'The library name.', 'libgdexample', PathVariable.PathAccept))
  13. # Local dependency paths, adapt them to your setup
  14. godot_headers_path = "godot-cpp/godot_headers/"
  15. cpp_bindings_path = "godot-cpp/"
  16. cpp_library = "libgodot-cpp"
  17. # only support 64 at this time..
  18. bits = 64
  19. # Updates the environment with the option variables.
  20. opts.Update(env)
  21. # Process some arguments
  22. if env['use_llvm']:
  23. env['CC'] = 'clang'
  24. env['CXX'] = 'clang++'
  25. if env['p'] != '':
  26. env['platform'] = env['p']
  27. if env['platform'] == '':
  28. print("No valid target platform selected.")
  29. quit();
  30. # Check our platform specifics
  31. if env['platform'] == "osx":
  32. env['target_path'] += 'osx/'
  33. cpp_library += '.osx'
  34. if env['target'] in ('debug', 'd'):
  35. env.Append(CCFLAGS = ['-g','-O2', '-arch', 'x86_64'])
  36. env.Append(LINKFLAGS = ['-arch', 'x86_64'])
  37. else:
  38. env.Append(CCFLAGS = ['-g','-O3', '-arch', 'x86_64'])
  39. env.Append(LINKFLAGS = ['-arch', 'x86_64'])
  40. elif env['platform'] in ('x11', 'linux'):
  41. env['target_path'] += 'x11/'
  42. cpp_library += '.linux'
  43. if env['target'] in ('debug', 'd'):
  44. env.Append(CCFLAGS = ['-fPIC', '-g3','-Og', '-std=c++17'])
  45. else:
  46. env.Append(CCFLAGS = ['-fPIC', '-g','-O3', '-std=c++17'])
  47. elif env['platform'] == "windows":
  48. env['target_path'] += 'win64/'
  49. cpp_library += '.windows'
  50. # This makes sure to keep the session environment variables on windows,
  51. # that way you can run scons in a vs 2017 prompt and it will find all the required tools
  52. env.Append(ENV = os.environ)
  53. env.Append(CCFLAGS = ['-DWIN32', '-D_WIN32', '-D_WINDOWS', '-W3', '-GR', '-D_CRT_SECURE_NO_WARNINGS'])
  54. if env['target'] in ('debug', 'd'):
  55. env.Append(CCFLAGS = ['-EHsc', '-D_DEBUG', '-MDd'])
  56. else:
  57. env.Append(CCFLAGS = ['-O2', '-EHsc', '-DNDEBUG', '-MD'])
  58. if env['target'] in ('debug', 'd'):
  59. cpp_library += '.debug'
  60. else:
  61. cpp_library += '.release'
  62. cpp_library += '.' + str(bits)
  63. # make sure our binding library is properly includes
  64. env.Append(CPPPATH=['.', godot_headers_path, cpp_bindings_path + 'include/', cpp_bindings_path + 'include/core/', cpp_bindings_path + 'include/gen/'])
  65. env.Append(LIBPATH=[cpp_bindings_path + 'bin/'])
  66. env.Append(LIBS=[cpp_library])
  67. # tweak this if you want to use different folders, or more folders, to store your source code in.
  68. env.Append(CPPPATH=['src/'])
  69. sources = Glob('src/*.cpp')
  70. library = env.SharedLibrary(target=env['target_path'] + env['target_name'] , source=sources)
  71. Default(library)
  72. # Generates help for the -h scons option.
  73. Help(opts.GenerateHelpText(env))