detect.py 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. BoolVariable('use_ubsan', 'Use LLVM/GCC compiler undefined behavior sanitizer (UBSAN)', False),
  20. BoolVariable('use_asan', 'Use LLVM/GCC compiler address sanitizer (ASAN))', False),
  21. BoolVariable('use_tsan', 'Use LLVM/GCC compiler thread sanitizer (TSAN))', False),
  22. ]
  23. def get_flags():
  24. return [
  25. ]
  26. def configure(env):
  27. ## Build type
  28. if (env["target"] == "release"):
  29. if (env["optimize"] == "speed"): #optimize for speed (default)
  30. env.Prepend(CCFLAGS=['-O3', '-fomit-frame-pointer', '-ftree-vectorize', '-msse2'])
  31. else: #optimize for size
  32. env.Prepend(CCFLAGS=['-Os','-ftree-vectorize', '-msse2'])
  33. if (env["debug_symbols"] == "yes"):
  34. env.Prepend(CCFLAGS=['-g1'])
  35. if (env["debug_symbols"] == "full"):
  36. env.Prepend(CCFLAGS=['-g2'])
  37. elif (env["target"] == "release_debug"):
  38. if (env["optimize"] == "speed"): #optimize for speed (default)
  39. env.Prepend(CCFLAGS=['-O2'])
  40. else: #optimize for size
  41. env.Prepend(CCFLAGS=['-Os'])
  42. env.Prepend(CPPDEFINES=['DEBUG_ENABLED'])
  43. if (env["debug_symbols"] == "yes"):
  44. env.Prepend(CCFLAGS=['-g1'])
  45. if (env["debug_symbols"] == "full"):
  46. env.Prepend(CCFLAGS=['-g2'])
  47. elif (env["target"] == "debug"):
  48. env.Prepend(CCFLAGS=['-g3'])
  49. env.Prepend(CPPDEFINES=['DEBUG_ENABLED', 'DEBUG_MEMORY_ENABLED'])
  50. ## Architecture
  51. # Mac OS X no longer runs on 32-bit since 10.7 which is unsupported since 2014
  52. # As such, we only support 64-bit
  53. env["bits"] = "64"
  54. ## Compiler configuration
  55. # Save this in environment for use by other modules
  56. if "OSXCROSS_ROOT" in os.environ:
  57. env["osxcross"] = True
  58. if not "osxcross" in env: # regular native build
  59. env.Append(CCFLAGS=['-arch', 'x86_64'])
  60. env.Append(LINKFLAGS=['-arch', 'x86_64'])
  61. if (env["macports_clang"] != 'no'):
  62. mpprefix = os.environ.get("MACPORTS_PREFIX", "/opt/local")
  63. mpclangver = env["macports_clang"]
  64. env["CC"] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/clang"
  65. env["LINK"] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/clang++"
  66. env["CXX"] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/clang++"
  67. env['AR'] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/llvm-ar"
  68. env['RANLIB'] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/llvm-ranlib"
  69. env['AS'] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/llvm-as"
  70. env.Append(CPPDEFINES=['__MACPORTS__']) #hack to fix libvpx MM256_BROADCASTSI128_SI256 define
  71. else:
  72. env['CC'] = 'clang'
  73. env['CXX'] = 'clang++'
  74. detect_darwin_sdk_path('osx', env)
  75. env.Append(CCFLAGS=['-isysroot', '$MACOS_SDK_PATH'])
  76. env.Append(LINKFLAGS=['-isysroot', '$MACOS_SDK_PATH'])
  77. else: # osxcross build
  78. root = os.environ.get("OSXCROSS_ROOT", 0)
  79. basecmd = root + "/target/bin/x86_64-apple-" + env["osxcross_sdk"] + "-"
  80. ccache_path = os.environ.get("CCACHE")
  81. if ccache_path is None:
  82. env['CC'] = basecmd + "cc"
  83. env['CXX'] = basecmd + "c++"
  84. else:
  85. # there aren't any ccache wrappers available for OS X cross-compile,
  86. # to enable caching we need to prepend the path to the ccache binary
  87. env['CC'] = ccache_path + ' ' + basecmd + "cc"
  88. env['CXX'] = ccache_path + ' ' + basecmd + "c++"
  89. env['AR'] = basecmd + "ar"
  90. env['RANLIB'] = basecmd + "ranlib"
  91. env['AS'] = basecmd + "as"
  92. env.Append(CPPDEFINES=['__MACPORTS__']) #hack to fix libvpx MM256_BROADCASTSI128_SI256 define
  93. if (env["CXX"] == "clang++"):
  94. env.Append(CPPDEFINES=['TYPED_METHOD_BIND'])
  95. env["CC"] = "clang"
  96. env["LINK"] = "clang++"
  97. if env['use_ubsan'] or env['use_asan'] or env['use_tsan']:
  98. env.extra_suffix += "s"
  99. if env['use_ubsan']:
  100. env.Append(CCFLAGS=['-fsanitize=undefined'])
  101. env.Append(LINKFLAGS=['-fsanitize=undefined'])
  102. if env['use_asan']:
  103. env.Append(CCFLAGS=['-fsanitize=address'])
  104. env.Append(LINKFLAGS=['-fsanitize=address'])
  105. if env['use_tsan']:
  106. env.Append(CCFLAGS=['-fsanitize=thread'])
  107. env.Append(LINKFLAGS=['-fsanitize=thread'])
  108. ## Dependencies
  109. if env['builtin_libtheora']:
  110. env["x86_libtheora_opt_gcc"] = True
  111. ## Flags
  112. env.Prepend(CPPPATH=['#platform/osx'])
  113. env.Append(CPPDEFINES=['OSX_ENABLED', 'UNIX_ENABLED', 'GLES_ENABLED', 'APPLE_STYLE_KEYS', 'COREAUDIO_ENABLED', 'COREMIDI_ENABLED'])
  114. 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'])
  115. env.Append(LIBS=['pthread'])
  116. env.Append(CCFLAGS=['-mmacosx-version-min=10.9'])
  117. env.Append(LINKFLAGS=['-mmacosx-version-min=10.9'])