SConstruct 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. #!/usr/bin/env python
  2. import os
  3. import sys
  4. # Try to detect the host platform automatically.
  5. # This is used if no `platform` argument is passed
  6. if sys.platform.startswith('linux'):
  7. host_platform = 'linux'
  8. elif sys.platform == 'darwin':
  9. host_platform = 'osx'
  10. elif sys.platform == 'win32' or sys.platform == 'msys':
  11. host_platform = 'windows'
  12. else:
  13. raise ValueError(
  14. 'Could not detect platform automatically, please specify with '
  15. 'platform=<platform>'
  16. )
  17. env = Environment(ENV = os.environ)
  18. opts = Variables([], ARGUMENTS)
  19. # Define our options
  20. opts.Add(EnumVariable('target', "Compilation target", 'debug', ['d', 'debug', 'r', 'release']))
  21. opts.Add(EnumVariable('platform', "Compilation platform", host_platform, ['', 'windows', 'x11', 'linux', 'osx']))
  22. opts.Add(EnumVariable('p', "Compilation target, alias for 'platform'", host_platform, ['', 'windows', 'x11', 'linux', 'osx']))
  23. opts.Add(EnumVariable('bits', 'Target platform bits', '64', ('32', '64')))
  24. opts.Add(BoolVariable('use_llvm', "Use the LLVM / Clang compiler", 'no'))
  25. opts.Add(PathVariable('target_path', 'The path where the lib is installed.', 'bin/', PathVariable.PathAccept))
  26. opts.Add(PathVariable('target_name', 'The library name.', 'libgdexample', PathVariable.PathAccept))
  27. # Local dependency paths, adapt them to your setup
  28. godot_headers_path = "../godot-headers/"
  29. cpp_bindings_path = "../"
  30. cpp_library = "libgodot-cpp"
  31. # only support 64 at this time..
  32. bits = 64
  33. # Updates the environment with the option variables.
  34. opts.Update(env)
  35. # Generates help for the -h scons option.
  36. Help(opts.GenerateHelpText(env))
  37. # This makes sure to keep the session environment variables on Windows.
  38. # This way, you can run SCons in a Visual Studio 2017 prompt and it will find
  39. # all the required tools
  40. if host_platform == 'windows' and env['platform'] != 'android':
  41. if env['bits'] == '64':
  42. env = Environment(TARGET_ARCH='amd64')
  43. elif env['bits'] == '32':
  44. env = Environment(TARGET_ARCH='x86')
  45. opts.Update(env)
  46. # Process some arguments
  47. if env['use_llvm']:
  48. env['CC'] = 'clang'
  49. env['CXX'] = 'clang++'
  50. if env['p'] != '':
  51. env['platform'] = env['p']
  52. if env['platform'] == '':
  53. print("No valid target platform selected.")
  54. quit();
  55. # For the reference:
  56. # - CCFLAGS are compilation flags shared between C and C++
  57. # - CFLAGS are for C-specific compilation flags
  58. # - CXXFLAGS are for C++-specific compilation flags
  59. # - CPPFLAGS are for pre-processor flags
  60. # - CPPDEFINES are for pre-processor defines
  61. # - LINKFLAGS are for linking flags
  62. # Check our platform specifics
  63. if env['platform'] == "osx":
  64. env['target_path'] += 'osx/'
  65. cpp_library += '.osx'
  66. env.Append(CCFLAGS=['-arch', 'x86_64'])
  67. env.Append(CXXFLAGS=['-std=c++17'])
  68. env.Append(LINKFLAGS=['-arch', 'x86_64'])
  69. if env['target'] in ('debug', 'd'):
  70. env.Append(CCFLAGS=['-g', '-O2'])
  71. else:
  72. env.Append(CCFLAGS=['-g', '-O3'])
  73. elif env['platform'] in ('x11', 'linux'):
  74. env['target_path'] += 'x11/'
  75. cpp_library += '.linux'
  76. env.Append(CCFLAGS=['-fPIC'])
  77. env.Append(CXXFLAGS=['-std=c++17'])
  78. if env['target'] in ('debug', 'd'):
  79. env.Append(CCFLAGS=['-g3', '-Og'])
  80. else:
  81. env.Append(CCFLAGS=['-g', '-O3'])
  82. elif env['platform'] == "windows":
  83. env['target_path'] += 'win64/'
  84. cpp_library += '.windows'
  85. # This makes sure to keep the session environment variables on windows,
  86. # that way you can run scons in a vs 2017 prompt and it will find all the required tools
  87. env.Append(ENV=os.environ)
  88. env.Append(CPPDEFINES=['WIN32', '_WIN32', '_WINDOWS', '_CRT_SECURE_NO_WARNINGS'])
  89. env.Append(CCFLAGS=['-W3', '-GR'])
  90. env.Append(CXXFLAGS=['-std:c++17'])
  91. if env['target'] in ('debug', 'd'):
  92. env.Append(CPPDEFINES=['_DEBUG'])
  93. env.Append(CCFLAGS=['-EHsc', '-MDd', '-ZI'])
  94. env.Append(LINKFLAGS=['-DEBUG'])
  95. else:
  96. env.Append(CPPDEFINES=['NDEBUG'])
  97. env.Append(CCFLAGS=['-O2', '-EHsc', '-MD'])
  98. if env['target'] in ('debug', 'd'):
  99. cpp_library += '.debug'
  100. else:
  101. cpp_library += '.release'
  102. cpp_library += '.' + str(bits)
  103. # make sure our binding library is properly includes
  104. env.Append(CPPPATH=['.', godot_headers_path, cpp_bindings_path + 'include/', cpp_bindings_path + 'include/core/', cpp_bindings_path + 'include/gen/'])
  105. env.Append(LIBPATH=[cpp_bindings_path + 'bin/'])
  106. env.Append(LIBS=[cpp_library])
  107. # tweak this if you want to use different folders, or more folders, to store your source code in.
  108. env.Append(CPPPATH=['src/'])
  109. sources = Glob('src/*.cpp')
  110. library = env.SharedLibrary(target=env['target_path'] + env['target_name'] , source=sources)
  111. Default(library)