detect.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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', '-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'])
  37. else: #optimize for size
  38. env.Prepend(CCFLAGS=['-Os'])
  39. env.Prepend(CPPDEFINES=['DEBUG_ENABLED'])
  40. if (env["debug_symbols"] == "yes"):
  41. env.Prepend(CCFLAGS=['-g1'])
  42. if (env["debug_symbols"] == "full"):
  43. env.Prepend(CCFLAGS=['-g2'])
  44. elif (env["target"] == "debug"):
  45. env.Prepend(CCFLAGS=['-g3'])
  46. env.Prepend(CPPDEFINES=['DEBUG_ENABLED', 'DEBUG_MEMORY_ENABLED'])
  47. ## Architecture
  48. # Mac OS X no longer runs on 32-bit since 10.7 which is unsupported since 2014
  49. # As such, we only support 64-bit
  50. env["bits"] = "64"
  51. ## Compiler configuration
  52. # Save this in environment for use by other modules
  53. if "OSXCROSS_ROOT" in os.environ:
  54. env["osxcross"] = True
  55. if not "osxcross" in env: # regular native build
  56. env.Append(CCFLAGS=['-arch', 'x86_64'])
  57. env.Append(LINKFLAGS=['-arch', 'x86_64'])
  58. if (env["macports_clang"] != 'no'):
  59. mpprefix = os.environ.get("MACPORTS_PREFIX", "/opt/local")
  60. mpclangver = env["macports_clang"]
  61. env["CC"] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/clang"
  62. env["LINK"] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/clang++"
  63. env["CXX"] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/clang++"
  64. env['AR'] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/llvm-ar"
  65. env['RANLIB'] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/llvm-ranlib"
  66. env['AS'] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/llvm-as"
  67. env.Append(CPPDEFINES=['__MACPORTS__']) #hack to fix libvpx MM256_BROADCASTSI128_SI256 define
  68. else:
  69. env['CC'] = 'clang'
  70. env['CXX'] = 'clang++'
  71. detect_darwin_sdk_path('osx', env)
  72. env.Append(CCFLAGS=['-isysroot', '$MACOS_SDK_PATH'])
  73. env.Append(LINKFLAGS=['-isysroot', '$MACOS_SDK_PATH'])
  74. else: # osxcross build
  75. root = os.environ.get("OSXCROSS_ROOT", 0)
  76. basecmd = root + "/target/bin/x86_64-apple-" + env["osxcross_sdk"] + "-"
  77. ccache_path = os.environ.get("CCACHE")
  78. if ccache_path is None:
  79. env['CC'] = basecmd + "cc"
  80. env['CXX'] = basecmd + "c++"
  81. else:
  82. # there aren't any ccache wrappers available for OS X cross-compile,
  83. # to enable caching we need to prepend the path to the ccache binary
  84. env['CC'] = ccache_path + ' ' + basecmd + "cc"
  85. env['CXX'] = ccache_path + ' ' + basecmd + "c++"
  86. env['AR'] = basecmd + "ar"
  87. env['RANLIB'] = basecmd + "ranlib"
  88. env['AS'] = basecmd + "as"
  89. env.Append(CPPDEFINES=['__MACPORTS__']) #hack to fix libvpx MM256_BROADCASTSI128_SI256 define
  90. if (env["CXX"] == "clang++"):
  91. env.Append(CPPDEFINES=['TYPED_METHOD_BIND'])
  92. env["CC"] = "clang"
  93. env["LINK"] = "clang++"
  94. ## Dependencies
  95. if env['builtin_libtheora']:
  96. env["x86_libtheora_opt_gcc"] = True
  97. ## Flags
  98. env.Prepend(CPPPATH=['#platform/osx'])
  99. env.Append(CPPDEFINES=['OSX_ENABLED', 'UNIX_ENABLED', 'GLES_ENABLED', 'APPLE_STYLE_KEYS', 'COREAUDIO_ENABLED', 'COREMIDI_ENABLED'])
  100. env.Append(LINKFLAGS=['-framework', 'Cocoa', '-framework', 'Carbon', '-framework', 'OpenGL', '-framework', 'AGL', '-framework', 'AudioUnit', '-framework', 'CoreAudio', '-framework', 'CoreMIDI', '-lz', '-framework', 'IOKit', '-framework', 'ForceFeedback', '-framework', 'AVFoundation', '-framework', 'CoreMedia', '-framework', 'CoreVideo'])
  101. env.Append(LIBS=['pthread'])
  102. env.Append(CCFLAGS=['-mmacosx-version-min=10.9'])
  103. env.Append(LINKFLAGS=['-mmacosx-version-min=10.9'])