detect.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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(CPPFLAGS=['-DDEBUG_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(CPPFLAGS=['-DDEBUG_ENABLED', '-DDEBUG_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(CPPFLAGS=['-D__MACPORTS__']) #hack to fix libvpx MM256_BROADCASTSI128_SI256 define
  68. detect_darwin_sdk_path('osx', env)
  69. env.Append(CCFLAGS=['-isysroot', '$MACOS_SDK_PATH'])
  70. env.Append(LINKFLAGS=['-isysroot', '$MACOS_SDK_PATH'])
  71. else: # osxcross build
  72. root = os.environ.get("OSXCROSS_ROOT", 0)
  73. basecmd = root + "/target/bin/x86_64-apple-" + env["osxcross_sdk"] + "-"
  74. ccache_path = os.environ.get("CCACHE")
  75. if ccache_path is 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. env.Append(CPPFLAGS=['-D__MACPORTS__']) #hack to fix libvpx MM256_BROADCASTSI128_SI256 define
  87. if (env["CXX"] == "clang++"):
  88. env.Append(CPPFLAGS=['-DTYPED_METHOD_BIND'])
  89. env["CC"] = "clang"
  90. env["LINK"] = "clang++"
  91. ## Dependencies
  92. if env['builtin_libtheora']:
  93. env["x86_libtheora_opt_gcc"] = True
  94. ## Flags
  95. env.Append(CPPPATH=['#platform/osx'])
  96. env.Append(CPPFLAGS=['-DOSX_ENABLED', '-DUNIX_ENABLED', '-DGLES_ENABLED', '-DAPPLE_STYLE_KEYS', '-DCOREAUDIO_ENABLED', '-DCOREMIDI_ENABLED'])
  97. env.Append(LINKFLAGS=['-framework', 'Cocoa', '-framework', 'Carbon', '-framework', 'OpenGL', '-framework', 'AGL', '-framework', 'AudioUnit', '-framework', 'CoreAudio', '-framework', 'CoreMIDI', '-lz', '-framework', 'IOKit', '-framework', 'ForceFeedback', '-framework', 'CoreVideo'])
  98. env.Append(LIBS=['pthread'])
  99. env.Append(CCFLAGS=['-mmacosx-version-min=10.9'])
  100. env.Append(LINKFLAGS=['-mmacosx-version-min=10.9'])