detect.py 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. import os
  2. import sys
  3. import subprocess
  4. from methods import detect_darwin_sdk_path
  5. def is_active():
  6. return True
  7. def get_name():
  8. return "OSX"
  9. def can_build():
  10. if (sys.platform == "darwin" or ("OSXCROSS_ROOT" in os.environ)):
  11. return True
  12. return False
  13. def get_opts():
  14. from SCons.Variables import BoolVariable, EnumVariable
  15. return [
  16. ('osxcross_sdk', 'OSXCross SDK version', 'darwin14'),
  17. ('MACOS_SDK_PATH', 'Path to the macOS SDK', ''),
  18. BoolVariable('use_static_mvk', 'Link MoltenVK statically as Level-0 driver (better portability) or use Vulkan ICD loader (enables validation layers)', False),
  19. EnumVariable('debug_symbols', 'Add debugging symbols to release builds', 'yes', ('yes', 'no', 'full')),
  20. BoolVariable('separate_debug_symbols', 'Create a separate file containing debugging symbols', False),
  21. BoolVariable('use_ubsan', 'Use LLVM/GCC compiler undefined behavior sanitizer (UBSAN)', False),
  22. BoolVariable('use_asan', 'Use LLVM/GCC compiler address sanitizer (ASAN))', False),
  23. BoolVariable('use_tsan', 'Use LLVM/GCC compiler thread sanitizer (TSAN))', False),
  24. ]
  25. def get_flags():
  26. return [
  27. ]
  28. def configure(env):
  29. ## Build type
  30. if (env["target"] == "release"):
  31. if (env["optimize"] == "speed"): #optimize for speed (default)
  32. env.Prepend(CCFLAGS=['-O3', '-fomit-frame-pointer', '-ftree-vectorize', '-msse2'])
  33. else: #optimize for size
  34. env.Prepend(CCFLAGS=['-Os','-ftree-vectorize', '-msse2'])
  35. if (env["debug_symbols"] == "yes"):
  36. env.Prepend(CCFLAGS=['-g1'])
  37. if (env["debug_symbols"] == "full"):
  38. env.Prepend(CCFLAGS=['-g2'])
  39. elif (env["target"] == "release_debug"):
  40. if (env["optimize"] == "speed"): #optimize for speed (default)
  41. env.Prepend(CCFLAGS=['-O2'])
  42. else: #optimize for size
  43. env.Prepend(CCFLAGS=['-Os'])
  44. env.Prepend(CPPDEFINES=['DEBUG_ENABLED'])
  45. if (env["debug_symbols"] == "yes"):
  46. env.Prepend(CCFLAGS=['-g1'])
  47. if (env["debug_symbols"] == "full"):
  48. env.Prepend(CCFLAGS=['-g2'])
  49. elif (env["target"] == "debug"):
  50. env.Prepend(CCFLAGS=['-g3'])
  51. env.Prepend(CPPDEFINES=['DEBUG_ENABLED', 'DEBUG_MEMORY_ENABLED'])
  52. ## Architecture
  53. # Mac OS X no longer runs on 32-bit since 10.7 which is unsupported since 2014
  54. # As such, we only support 64-bit
  55. env["bits"] = "64"
  56. ## Compiler configuration
  57. # Save this in environment for use by other modules
  58. if "OSXCROSS_ROOT" in os.environ:
  59. env["osxcross"] = True
  60. if not "osxcross" in env: # regular native build
  61. env.Append(CCFLAGS=['-arch', 'x86_64'])
  62. env.Append(LINKFLAGS=['-arch', 'x86_64'])
  63. if (env["macports_clang"] != 'no'):
  64. mpprefix = os.environ.get("MACPORTS_PREFIX", "/opt/local")
  65. mpclangver = env["macports_clang"]
  66. env["CC"] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/clang"
  67. env["LINK"] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/clang++"
  68. env["CXX"] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/clang++"
  69. env['AR'] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/llvm-ar"
  70. env['RANLIB'] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/llvm-ranlib"
  71. env['AS'] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/llvm-as"
  72. env.Append(CPPDEFINES=['__MACPORTS__']) #hack to fix libvpx MM256_BROADCASTSI128_SI256 define
  73. else:
  74. env['CC'] = 'clang'
  75. env['CXX'] = 'clang++'
  76. detect_darwin_sdk_path('osx', env)
  77. env.Append(CCFLAGS=['-isysroot', '$MACOS_SDK_PATH'])
  78. env.Append(LINKFLAGS=['-isysroot', '$MACOS_SDK_PATH'])
  79. else: # osxcross build
  80. root = os.environ.get("OSXCROSS_ROOT", 0)
  81. basecmd = root + "/target/bin/x86_64-apple-" + env["osxcross_sdk"] + "-"
  82. ccache_path = os.environ.get("CCACHE")
  83. if ccache_path is None:
  84. env['CC'] = basecmd + "cc"
  85. env['CXX'] = basecmd + "c++"
  86. else:
  87. # there aren't any ccache wrappers available for OS X cross-compile,
  88. # to enable caching we need to prepend the path to the ccache binary
  89. env['CC'] = ccache_path + ' ' + basecmd + "cc"
  90. env['CXX'] = ccache_path + ' ' + basecmd + "c++"
  91. env['AR'] = basecmd + "ar"
  92. env['RANLIB'] = basecmd + "ranlib"
  93. env['AS'] = basecmd + "as"
  94. env.Append(CPPDEFINES=['__MACPORTS__']) #hack to fix libvpx MM256_BROADCASTSI128_SI256 define
  95. if (env["CXX"] == "clang++"):
  96. env.Append(CPPDEFINES=['TYPED_METHOD_BIND'])
  97. env["CC"] = "clang"
  98. env["LINK"] = "clang++"
  99. if env['use_ubsan'] or env['use_asan'] or env['use_tsan']:
  100. env.extra_suffix += "s"
  101. if env['use_ubsan']:
  102. env.Append(CCFLAGS=['-fsanitize=undefined'])
  103. env.Append(LINKFLAGS=['-fsanitize=undefined'])
  104. if env['use_asan']:
  105. env.Append(CCFLAGS=['-fsanitize=address'])
  106. env.Append(LINKFLAGS=['-fsanitize=address'])
  107. if env['use_tsan']:
  108. env.Append(CCFLAGS=['-fsanitize=thread'])
  109. env.Append(LINKFLAGS=['-fsanitize=thread'])
  110. ## Dependencies
  111. if env['builtin_libtheora']:
  112. env["x86_libtheora_opt_gcc"] = True
  113. ## Flags
  114. env.Prepend(CPPPATH=['#platform/osx'])
  115. env.Append(CPPDEFINES=['OSX_ENABLED', 'UNIX_ENABLED', 'APPLE_STYLE_KEYS', 'COREAUDIO_ENABLED', 'COREMIDI_ENABLED'])
  116. env.Append(LINKFLAGS=['-framework', 'Cocoa', '-framework', 'Carbon', '-framework', 'AudioUnit', '-framework', 'CoreAudio', '-framework', 'CoreMIDI', '-framework', 'IOKit', '-framework', 'ForceFeedback', '-framework', 'CoreVideo', '-framework', 'AVFoundation', '-framework', 'CoreMedia'])
  117. env.Append(LIBS=['pthread', 'z'])
  118. env.Append(CPPDEFINES=['VULKAN_ENABLED'])
  119. env.Append(LINKFLAGS=['-framework', 'Metal', '-framework', 'QuartzCore', '-framework', 'IOSurface'])
  120. if (env['use_static_mvk']):
  121. env.Append(LINKFLAGS=['-framework', 'MoltenVK'])
  122. env['builtin_vulkan'] = False
  123. elif not env['builtin_vulkan']:
  124. env.Append(LIBS=['vulkan'])
  125. #env.Append(CPPDEFINES=['GLES_ENABLED', 'OPENGL_ENABLED'])
  126. env.Append(CCFLAGS=['-mmacosx-version-min=10.12'])
  127. env.Append(LINKFLAGS=['-mmacosx-version-min=10.12'])