SConstruct 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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', '-ZI'])
  56. env.Append(LINKFLAGS = ['-DEBUG'])
  57. else:
  58. env.Append(CCFLAGS = ['-O2', '-EHsc', '-DNDEBUG', '-MD'])
  59. if env['target'] in ('debug', 'd'):
  60. cpp_library += '.debug'
  61. else:
  62. cpp_library += '.release'
  63. cpp_library += '.' + str(bits)
  64. # make sure our binding library is properly includes
  65. env.Append(CPPPATH=['.', godot_headers_path, cpp_bindings_path + 'include/', cpp_bindings_path + 'include/core/', cpp_bindings_path + 'include/gen/'])
  66. env.Append(LIBPATH=[cpp_bindings_path + 'bin/'])
  67. env.Append(LIBS=[cpp_library])
  68. # tweak this if you want to use different folders, or more folders, to store your source code in.
  69. env.Append(CPPPATH=['src/'])
  70. sources = Glob('src/*.cpp')
  71. library = env.SharedLibrary(target=env['target_path'] + env['target_name'] , source=sources)
  72. Default(library)
  73. # Generates help for the -h scons option.
  74. Help(opts.GenerateHelpText(env))