windows.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import sys
  2. import common_compiler_flags
  3. import my_spawn
  4. from SCons.Tool import mingw, msvc
  5. from SCons.Variables import BoolVariable
  6. def options(opts):
  7. opts.Add(BoolVariable("use_mingw", "Use the MinGW compiler instead of MSVC - only effective on Windows", False))
  8. opts.Add(BoolVariable("use_clang_cl", "Use the clang driver instead of MSVC - only effective on Windows", False))
  9. opts.Add(BoolVariable("use_static_cpp", "Link MinGW/MSVC C++ runtime libraries statically", True))
  10. def exists(env):
  11. return True
  12. def generate(env):
  13. if not env["use_mingw"] and msvc.exists(env):
  14. if env["arch"] == "x86_64":
  15. env["TARGET_ARCH"] = "amd64"
  16. elif env["arch"] == "x86_32":
  17. env["TARGET_ARCH"] = "x86"
  18. env["is_msvc"] = True
  19. # MSVC, linker, and archiver.
  20. msvc.generate(env)
  21. env.Tool("mslib")
  22. env.Tool("mslink")
  23. env.Append(CPPDEFINES=["TYPED_METHOD_BIND", "NOMINMAX"])
  24. env.Append(CCFLAGS=["/utf-8"])
  25. env.Append(LINKFLAGS=["/WX"])
  26. if env["use_clang_cl"]:
  27. env["CC"] = "clang-cl"
  28. env["CXX"] = "clang-cl"
  29. if env["use_static_cpp"]:
  30. env.Append(CCFLAGS=["/MT"])
  31. else:
  32. env.Append(CCFLAGS=["/MD"])
  33. elif sys.platform == "win32" or sys.platform == "msys":
  34. env["use_mingw"] = True
  35. mingw.generate(env)
  36. # Don't want lib prefixes
  37. env["IMPLIBPREFIX"] = ""
  38. env["SHLIBPREFIX"] = ""
  39. # Want dll suffix
  40. env["SHLIBSUFFIX"] = ".dll"
  41. env.Append(CCFLAGS=["-Wwrite-strings"])
  42. env.Append(LINKFLAGS=["-Wl,--no-undefined"])
  43. if env["use_static_cpp"]:
  44. env.Append(
  45. LINKFLAGS=[
  46. "-static",
  47. "-static-libgcc",
  48. "-static-libstdc++",
  49. ]
  50. )
  51. # Long line hack. Use custom spawn, quick AR append (to avoid files with the same names to override each other).
  52. my_spawn.configure(env)
  53. else:
  54. env["use_mingw"] = True
  55. # Cross-compilation using MinGW
  56. prefix = "i686" if env["arch"] == "x86_32" else env["arch"]
  57. env["CXX"] = prefix + "-w64-mingw32-g++"
  58. env["CC"] = prefix + "-w64-mingw32-gcc"
  59. env["AR"] = prefix + "-w64-mingw32-ar"
  60. env["RANLIB"] = prefix + "-w64-mingw32-ranlib"
  61. env["LINK"] = prefix + "-w64-mingw32-g++"
  62. # Want dll suffix
  63. env["SHLIBSUFFIX"] = ".dll"
  64. env.Append(CCFLAGS=["-Wwrite-strings"])
  65. env.Append(LINKFLAGS=["-Wl,--no-undefined"])
  66. if env["use_static_cpp"]:
  67. env.Append(
  68. LINKFLAGS=[
  69. "-static",
  70. "-static-libgcc",
  71. "-static-libstdc++",
  72. ]
  73. )
  74. env.Append(CPPDEFINES=["WINDOWS_ENABLED"])
  75. common_compiler_flags.generate(env)