windows.py 2.9 KB

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