SConstruct 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. # For the reference:
  31. # - CCFLAGS are compilation flags shared between C and C++
  32. # - CFLAGS are for C-specific compilation flags
  33. # - CXXFLAGS are for C++-specific compilation flags
  34. # - CPPFLAGS are for pre-processor flags
  35. # - CPPDEFINES are for pre-processor defines
  36. # - LINKFLAGS are for linking flags
  37. # Check our platform specifics
  38. if env['platform'] == "osx":
  39. env['target_path'] += 'osx/'
  40. cpp_library += '.osx'
  41. if env['target'] in ('debug', 'd'):
  42. env.Append(CCFLAGS=['-g', '-O2', '-arch', 'x86_64'])
  43. env.Append(LINKFLAGS=['-arch', 'x86_64'])
  44. else:
  45. env.Append(CCFLAGS=['-g', '-O3', '-arch', 'x86_64'])
  46. env.Append(LINKFLAGS=['-arch', 'x86_64'])
  47. elif env['platform'] in ('x11', 'linux'):
  48. env['target_path'] += 'x11/'
  49. cpp_library += '.linux'
  50. if env['target'] in ('debug', 'd'):
  51. env.Append(CCFLAGS=['-fPIC', '-g3', '-Og'])
  52. env.Append(CXXFLAGS=['-std=c++17'])
  53. else:
  54. env.Append(CCFLAGS=['-fPIC', '-g', '-O3'])
  55. env.Append(CXXFLAGS=['-std=c++17'])
  56. elif env['platform'] == "windows":
  57. env['target_path'] += 'win64/'
  58. cpp_library += '.windows'
  59. # This makes sure to keep the session environment variables on windows,
  60. # that way you can run scons in a vs 2017 prompt and it will find all the required tools
  61. env.Append(ENV=os.environ)
  62. env.Append(CPPDEFINES=['WIN32', '_WIN32', '_WINDOWS', '_CRT_SECURE_NO_WARNINGS'])
  63. env.Append(CCFLAGS=['-W3', '-GR'])
  64. if env['target'] in ('debug', 'd'):
  65. env.Append(CPPDEFINES=['_DEBUG'])
  66. env.Append(CCFLAGS=['-EHsc', '-MDd', '-ZI'])
  67. env.Append(LINKFLAGS=['-DEBUG'])
  68. else:
  69. env.Append(CPPDEFINES=['NDEBUG'])
  70. env.Append(CCFLAGS=['-O2', '-EHsc', '-MD'])
  71. if env['target'] in ('debug', 'd'):
  72. cpp_library += '.debug'
  73. else:
  74. cpp_library += '.release'
  75. cpp_library += '.' + str(bits)
  76. # make sure our binding library is properly includes
  77. env.Append(CPPPATH=['.', godot_headers_path, cpp_bindings_path + 'include/', cpp_bindings_path + 'include/core/', cpp_bindings_path + 'include/gen/'])
  78. env.Append(LIBPATH=[cpp_bindings_path + 'bin/'])
  79. env.Append(LIBS=[cpp_library])
  80. # tweak this if you want to use different folders, or more folders, to store your source code in.
  81. env.Append(CPPPATH=['src/'])
  82. sources = Glob('src/*.cpp')
  83. library = env.SharedLibrary(target=env['target_path'] + env['target_name'] , source=sources)
  84. Default(library)
  85. # Generates help for the -h scons option.
  86. Help(opts.GenerateHelpText(env))