detect.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import os
  2. import sys
  3. def is_active():
  4. return True
  5. def get_name():
  6. return "OSX"
  7. def can_build():
  8. if (sys.platform == "darwin" or ("OSXCROSS_ROOT" in os.environ)):
  9. return True
  10. return False
  11. def get_opts():
  12. from SCons.Variables import EnumVariable
  13. return [
  14. ('osxcross_sdk', 'OSXCross SDK version', 'darwin14'),
  15. EnumVariable('debug_symbols', 'Add debug symbols to release version', 'yes', ('yes', 'no', 'full')),
  16. ]
  17. def get_flags():
  18. return [
  19. ]
  20. def configure(env):
  21. ## Build type
  22. if (env["target"] == "release"):
  23. env.Prepend(CCFLAGS=['-O3', '-ffast-math', '-fomit-frame-pointer', '-ftree-vectorize', '-msse2'])
  24. if (env["debug_symbols"] == "yes"):
  25. env.Prepend(CCFLAGS=['-g1'])
  26. if (env["debug_symbols"] == "full"):
  27. env.Prepend(CCFLAGS=['-g2'])
  28. elif (env["target"] == "release_debug"):
  29. env.Prepend(CCFLAGS=['-O2', '-DDEBUG_ENABLED'])
  30. if (env["debug_symbols"] == "yes"):
  31. env.Prepend(CCFLAGS=['-g1'])
  32. if (env["debug_symbols"] == "full"):
  33. env.Prepend(CCFLAGS=['-g2'])
  34. elif (env["target"] == "debug"):
  35. env.Prepend(CCFLAGS=['-g3', '-DDEBUG_ENABLED', '-DDEBUG_MEMORY_ENABLED'])
  36. ## Architecture
  37. is64 = sys.maxsize > 2**32
  38. if (env["bits"] == "default"):
  39. env["bits"] = "64" if is64 else "32"
  40. ## Compiler configuration
  41. if "OSXCROSS_ROOT" not in os.environ: # regular native build
  42. if (env["bits"] == "fat"):
  43. env.Append(CCFLAGS=['-arch', 'i386', '-arch', 'x86_64'])
  44. env.Append(LINKFLAGS=['-arch', 'i386', '-arch', 'x86_64'])
  45. elif (env["bits"] == "32"):
  46. env.Append(CCFLAGS=['-arch', 'i386'])
  47. env.Append(LINKFLAGS=['-arch', 'i386'])
  48. else: # 64-bit, default
  49. env.Append(CCFLAGS=['-arch', 'x86_64'])
  50. env.Append(LINKFLAGS=['-arch', 'x86_64'])
  51. if (env["macports_clang"] != 'no'):
  52. mpprefix = os.environ.get("MACPORTS_PREFIX", "/opt/local")
  53. mpclangver = env["macports_clang"]
  54. env["CC"] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/clang"
  55. env["LD"] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/clang++"
  56. env["CXX"] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/clang++"
  57. env['AR'] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/llvm-ar"
  58. env['RANLIB'] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/llvm-ranlib"
  59. env['AS'] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/llvm-as"
  60. env.Append(CCFLAGS=['-D__MACPORTS__']) #hack to fix libvpx MM256_BROADCASTSI128_SI256 define
  61. if (env["openmp"]):
  62. env.Append(CPPFLAGS=['-fopenmp'])
  63. env.Append(LINKFLAGS=['-fopenmp'])
  64. else: # osxcross build
  65. root = os.environ.get("OSXCROSS_ROOT", 0)
  66. if env["bits"] == "fat":
  67. basecmd = root + "/target/bin/x86_64-apple-" + env["osxcross_sdk"] + "-"
  68. env.Append(CCFLAGS=['-arch', 'i386', '-arch', 'x86_64'])
  69. env.Append(LINKFLAGS=['-arch', 'i386', '-arch', 'x86_64'])
  70. elif env["bits"] == "32":
  71. basecmd = root + "/target/bin/i386-apple-" + env["osxcross_sdk"] + "-"
  72. else: # 64-bit, default
  73. basecmd = root + "/target/bin/x86_64-apple-" + env["osxcross_sdk"] + "-"
  74. ccache_path = os.environ.get("CCACHE")
  75. if ccache_path == None:
  76. env['CC'] = basecmd + "cc"
  77. env['CXX'] = basecmd + "c++"
  78. else:
  79. # there aren't any ccache wrappers available for OS X cross-compile,
  80. # to enable caching we need to prepend the path to the ccache binary
  81. env['CC'] = ccache_path + ' ' + basecmd + "cc"
  82. env['CXX'] = ccache_path + ' ' + basecmd + "c++"
  83. env['AR'] = basecmd + "ar"
  84. env['RANLIB'] = basecmd + "ranlib"
  85. env['AS'] = basecmd + "as"
  86. if (env["CXX"] == "clang++"):
  87. env.Append(CPPFLAGS=['-DTYPED_METHOD_BIND'])
  88. env["CC"] = "clang"
  89. env["LD"] = "clang++"
  90. ## Dependencies
  91. if env['builtin_libtheora']:
  92. env["x86_libtheora_opt_gcc"] = True
  93. ## Flags
  94. env.Append(CPPPATH=['#platform/osx'])
  95. env.Append(CPPFLAGS=['-DOSX_ENABLED', '-DUNIX_ENABLED', '-DGLES_ENABLED', '-DAPPLE_STYLE_KEYS', '-DCOREAUDIO_ENABLED'])
  96. env.Append(LINKFLAGS=['-framework', 'Cocoa', '-framework', 'Carbon', '-framework', 'OpenGL', '-framework', 'AGL', '-framework', 'AudioUnit', '-framework', 'CoreAudio', '-lz', '-framework', 'IOKit', '-framework', 'ForceFeedback'])
  97. env.Append(LIBS=['pthread'])
  98. env.Append(CPPFLAGS=['-mmacosx-version-min=10.9'])
  99. env.Append(LINKFLAGS=['-mmacosx-version-min=10.9'])