SConstruct 3.7 KB

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