windows.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import sys
  2. import my_spawn
  3. from SCons.Tool import msvc, mingw
  4. from SCons.Variables import *
  5. def options(opts):
  6. opts.Add(BoolVariable("use_mingw", "Use the MinGW compiler instead of MSVC - only effective on Windows", False))
  7. opts.Add(BoolVariable("use_clang_cl", "Use the clang driver instead of MSVC - only effective on Windows", False))
  8. def exists(env):
  9. return True
  10. def generate(env):
  11. base = None
  12. if not env["use_mingw"] and msvc.exists(env):
  13. if env["arch"] == "x86_64":
  14. env["TARGET_ARCH"] = "amd64"
  15. elif env["arch"] == "x86_32":
  16. env["TARGET_ARCH"] = "x86"
  17. env["is_msvc"] = True
  18. msvc.generate(env)
  19. env.Append(CPPDEFINES=["TYPED_METHOD_BIND", "NOMINMAX"])
  20. env.Append(CCFLAGS=["/EHsc"])
  21. env.Append(LINKFLAGS=["/WX"])
  22. if env["debug_symbols"] or env["target"] == "debug":
  23. env.Append(CCFLAGS=["/MDd"])
  24. else:
  25. env.Append(CCFLAGS=["/MD"])
  26. if env["use_clang_cl"]:
  27. env["CC"] = "clang-cl"
  28. env["CXX"] = "clang-cl"
  29. elif sys.platform == "win32" or sys.platform == "msys":
  30. env["use_mingw"] = True
  31. mingw.generate(env)
  32. # Don't want lib prefixes
  33. env["IMPLIBPREFIX"] = ""
  34. env["SHLIBPREFIX"] = ""
  35. # Want dll suffix
  36. env["SHLIBSUFFIX"] = ".dll"
  37. # Long line hack. Use custom spawn, quick AR append (to avoid files with the same names to override each other).
  38. my_spawn.configure(env)
  39. else:
  40. env["use_mingw"] = True
  41. # Cross-compilation using MinGW
  42. prefix = "i686" if env["arch"] == "x86_32" else env["arch"]
  43. env["CXX"] = prefix + "-w64-mingw32-g++"
  44. env["CC"] = prefix + "-w64-mingw32-gcc"
  45. env["AR"] = prefix + "-w64-mingw32-ar"
  46. env["RANLIB"] = prefix + "-w64-mingw32-ranlib"
  47. env["LINK"] = prefix + "-w64-mingw32-g++"
  48. # Want dll suffix
  49. env["SHLIBSUFFIX"] = ".dll"
  50. # These options are for a release build even using target=debug
  51. env.Append(CCFLAGS=["-O3", "-Wwrite-strings"])
  52. env.Append(
  53. LINKFLAGS=[
  54. "--static",
  55. "-Wl,--no-undefined",
  56. "-static-libgcc",
  57. "-static-libstdc++",
  58. ]
  59. )