windows.py 2.2 KB

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