windows.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. opts.Add(BoolVariable("use_static_cpp", "Link MinGW/MSVC C++ runtime libraries statically", True))
  9. def exists(env):
  10. return True
  11. def generate(env):
  12. base = None
  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"])