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