detect.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 BoolVariable, EnumVariable
  13. return [
  14. ('osxcross_sdk', 'OSXCross SDK version', 'darwin14'),
  15. EnumVariable('debug_symbols', 'Add debugging symbols to release builds', 'yes', ('yes', 'no', 'full')),
  16. BoolVariable('separate_debug_symbols', 'Create a separate file containing debugging symbols', False),
  17. ]
  18. def get_flags():
  19. return [
  20. ]
  21. def configure(env):
  22. ## Build type
  23. if (env["target"] == "release"):
  24. env.Prepend(CCFLAGS=['-O3', '-ffast-math', '-fomit-frame-pointer', '-ftree-vectorize', '-msse2'])
  25. if (env["debug_symbols"] == "yes"):
  26. env.Prepend(CCFLAGS=['-g1'])
  27. if (env["debug_symbols"] == "full"):
  28. env.Prepend(CCFLAGS=['-g2'])
  29. elif (env["target"] == "release_debug"):
  30. env.Prepend(CCFLAGS=['-O2', '-DDEBUG_ENABLED'])
  31. if (env["debug_symbols"] == "yes"):
  32. env.Prepend(CCFLAGS=['-g1'])
  33. if (env["debug_symbols"] == "full"):
  34. env.Prepend(CCFLAGS=['-g2'])
  35. elif (env["target"] == "debug"):
  36. env.Prepend(CCFLAGS=['-g3', '-DDEBUG_ENABLED', '-DDEBUG_MEMORY_ENABLED'])
  37. ## Architecture
  38. # Mac OS X no longer runs on 32-bit since 10.7 which is unsupported since 2014
  39. # As such, we only support 64-bit
  40. env["bits"] = "64"
  41. ## Compiler configuration
  42. if "OSXCROSS_ROOT" not in os.environ: # regular native build
  43. env.Append(CCFLAGS=['-arch', 'x86_64'])
  44. env.Append(LINKFLAGS=['-arch', 'x86_64'])
  45. if (env["macports_clang"] != 'no'):
  46. mpprefix = os.environ.get("MACPORTS_PREFIX", "/opt/local")
  47. mpclangver = env["macports_clang"]
  48. env["CC"] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/clang"
  49. env["LINK"] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/clang++"
  50. env["CXX"] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/clang++"
  51. env['AR'] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/llvm-ar"
  52. env['RANLIB'] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/llvm-ranlib"
  53. env['AS'] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/llvm-as"
  54. env.Append(CCFLAGS=['-D__MACPORTS__']) #hack to fix libvpx MM256_BROADCASTSI128_SI256 define
  55. else: # osxcross build
  56. root = os.environ.get("OSXCROSS_ROOT", 0)
  57. basecmd = root + "/target/bin/x86_64-apple-" + env["osxcross_sdk"] + "-"
  58. ccache_path = os.environ.get("CCACHE")
  59. if ccache_path == None:
  60. env['CC'] = basecmd + "cc"
  61. env['CXX'] = basecmd + "c++"
  62. else:
  63. # there aren't any ccache wrappers available for OS X cross-compile,
  64. # to enable caching we need to prepend the path to the ccache binary
  65. env['CC'] = ccache_path + ' ' + basecmd + "cc"
  66. env['CXX'] = ccache_path + ' ' + basecmd + "c++"
  67. env['AR'] = basecmd + "ar"
  68. env['RANLIB'] = basecmd + "ranlib"
  69. env['AS'] = basecmd + "as"
  70. env.Append(CCFLAGS=['-D__MACPORTS__']) #hack to fix libvpx MM256_BROADCASTSI128_SI256 define
  71. if (env["CXX"] == "clang++"):
  72. env.Append(CPPFLAGS=['-DTYPED_METHOD_BIND'])
  73. env["CC"] = "clang"
  74. env["LINK"] = "clang++"
  75. ## Dependencies
  76. if env['builtin_libtheora']:
  77. env["x86_libtheora_opt_gcc"] = True
  78. ## Flags
  79. env.Append(CPPPATH=['#platform/osx'])
  80. env.Append(CPPFLAGS=['-DOSX_ENABLED', '-DUNIX_ENABLED', '-DGLES_ENABLED', '-DAPPLE_STYLE_KEYS', '-DCOREAUDIO_ENABLED'])
  81. env.Append(LINKFLAGS=['-framework', 'Cocoa', '-framework', 'Carbon', '-framework', 'OpenGL', '-framework', 'AGL', '-framework', 'AudioUnit', '-framework', 'CoreAudio', '-lz', '-framework', 'IOKit', '-framework', 'ForceFeedback'])
  82. env.Append(LIBS=['pthread'])
  83. env.Append(CPPFLAGS=['-mmacosx-version-min=10.9'])
  84. env.Append(LINKFLAGS=['-mmacosx-version-min=10.9'])