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