detect.py 4.8 KB

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