detect.py 6.6 KB

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