windows.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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["use_clang_cl"]:
  23. env["CC"] = "clang-cl"
  24. env["CXX"] = "clang-cl"
  25. elif sys.platform == "win32" or sys.platform == "msys":
  26. env["use_mingw"] = True
  27. mingw.generate(env)
  28. # Don't want lib prefixes
  29. env["IMPLIBPREFIX"] = ""
  30. env["SHLIBPREFIX"] = ""
  31. # Want dll suffix
  32. env["SHLIBSUFFIX"] = ".dll"
  33. # Long line hack. Use custom spawn, quick AR append (to avoid files with the same names to override each other).
  34. my_spawn.configure(env)
  35. else:
  36. env["use_mingw"] = True
  37. # Cross-compilation using MinGW
  38. prefix = "i686" if env["arch"] == "x86_32" else env["arch"]
  39. env["CXX"] = prefix + "-w64-mingw32-g++"
  40. env["CC"] = prefix + "-w64-mingw32-gcc"
  41. env["AR"] = prefix + "-w64-mingw32-ar"
  42. env["RANLIB"] = prefix + "-w64-mingw32-ranlib"
  43. env["LINK"] = prefix + "-w64-mingw32-g++"
  44. # Want dll suffix
  45. env["SHLIBSUFFIX"] = ".dll"
  46. # These options are for a release build even using target=debug
  47. env.Append(CCFLAGS=["-O3", "-Wwrite-strings"])
  48. env.Append(
  49. LINKFLAGS=[
  50. "--static",
  51. "-Wl,--no-undefined",
  52. "-static-libgcc",
  53. "-static-libstdc++",
  54. ]
  55. )