SConstruct 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #!/usr/bin/env python
  2. import os
  3. import sys
  4. # Try to detect the host platform automatically.
  5. # This is used if no `platform` argument is passed
  6. if sys.platform.startswith("linux"):
  7. host_platform = "linux"
  8. elif sys.platform == "darwin":
  9. host_platform = "osx"
  10. elif sys.platform == "win32" or sys.platform == "msys":
  11. host_platform = "windows"
  12. else:
  13. raise ValueError("Could not detect platform automatically, please specify with platform=<platform>")
  14. env = Environment(ENV=os.environ)
  15. opts = Variables([], ARGUMENTS)
  16. # Define our options
  17. opts.Add(EnumVariable("target", "Compilation target", "debug", ["d", "debug", "r", "release"]))
  18. opts.Add(EnumVariable("platform", "Compilation platform", host_platform, ["", "windows", "x11", "linux", "osx"]))
  19. opts.Add(
  20. EnumVariable("p", "Compilation target, alias for 'platform'", host_platform, ["", "windows", "x11", "linux", "osx"])
  21. )
  22. opts.Add(EnumVariable("bits", "Target platform bits", "64", ("32", "64")))
  23. opts.Add(BoolVariable("use_llvm", "Use the LLVM / Clang compiler", "no"))
  24. opts.Add(PathVariable("target_path", "The path where the lib is installed.", "bin/", PathVariable.PathAccept))
  25. opts.Add(PathVariable("target_name", "The library name.", "libgdexample", PathVariable.PathAccept))
  26. # Local dependency paths, adapt them to your setup
  27. godot_headers_path = "../godot-headers/"
  28. cpp_bindings_path = "../"
  29. cpp_library = "libgodot-cpp"
  30. # only support 64 at this time..
  31. bits = 64
  32. # Updates the environment with the option variables.
  33. opts.Update(env)
  34. # Generates help for the -h scons option.
  35. Help(opts.GenerateHelpText(env))
  36. # This makes sure to keep the session environment variables on Windows.
  37. # This way, you can run SCons in a Visual Studio 2017 prompt and it will find
  38. # all the required tools
  39. if host_platform == "windows" and env["platform"] != "android":
  40. if env["bits"] == "64":
  41. env = Environment(TARGET_ARCH="amd64")
  42. elif env["bits"] == "32":
  43. env = Environment(TARGET_ARCH="x86")
  44. opts.Update(env)
  45. # Process some arguments
  46. if env["use_llvm"]:
  47. env["CC"] = "clang"
  48. env["CXX"] = "clang++"
  49. if env["p"] != "":
  50. env["platform"] = env["p"]
  51. if env["platform"] == "":
  52. print("No valid target platform selected.")
  53. quit()
  54. # For the reference:
  55. # - CCFLAGS are compilation flags shared between C and C++
  56. # - CFLAGS are for C-specific compilation flags
  57. # - CXXFLAGS are for C++-specific compilation flags
  58. # - CPPFLAGS are for pre-processor flags
  59. # - CPPDEFINES are for pre-processor defines
  60. # - LINKFLAGS are for linking flags
  61. # Check our platform specifics
  62. if env["platform"] == "osx":
  63. env["target_path"] += "osx/"
  64. cpp_library += ".osx"
  65. env.Append(CCFLAGS=["-arch", "x86_64"])
  66. env.Append(CXXFLAGS=["-std=c++17"])
  67. env.Append(LINKFLAGS=["-arch", "x86_64"])
  68. if env["target"] in ("debug", "d"):
  69. env.Append(CCFLAGS=["-g", "-O2"])
  70. else:
  71. env.Append(CCFLAGS=["-g", "-O3"])
  72. elif env["platform"] in ("x11", "linux"):
  73. env["target_path"] += "x11/"
  74. cpp_library += ".linux"
  75. env.Append(CCFLAGS=["-fPIC"])
  76. env.Append(CXXFLAGS=["-std=c++17"])
  77. if env["target"] in ("debug", "d"):
  78. env.Append(CCFLAGS=["-g3", "-Og"])
  79. else:
  80. env.Append(CCFLAGS=["-g", "-O3"])
  81. elif env["platform"] == "windows":
  82. env["target_path"] += "win64/"
  83. cpp_library += ".windows"
  84. # This makes sure to keep the session environment variables on windows,
  85. # that way you can run scons in a vs 2017 prompt and it will find all the required tools
  86. env.Append(ENV=os.environ)
  87. env.Append(CPPDEFINES=["WIN32", "_WIN32", "_WINDOWS", "_CRT_SECURE_NO_WARNINGS"])
  88. env.Append(CCFLAGS=["-W3", "-GR"])
  89. env.Append(CXXFLAGS=["-std:c++17"])
  90. if env["target"] in ("debug", "d"):
  91. env.Append(CPPDEFINES=["_DEBUG"])
  92. env.Append(CCFLAGS=["-EHsc", "-MDd", "-ZI"])
  93. env.Append(LINKFLAGS=["-DEBUG"])
  94. else:
  95. env.Append(CPPDEFINES=["NDEBUG"])
  96. env.Append(CCFLAGS=["-O2", "-EHsc", "-MD"])
  97. if env["target"] in ("debug", "d"):
  98. cpp_library += ".debug"
  99. else:
  100. cpp_library += ".release"
  101. cpp_library += "." + str(bits)
  102. # make sure our binding library is properly includes
  103. env.Append(
  104. CPPPATH=[
  105. ".",
  106. godot_headers_path,
  107. cpp_bindings_path + "include/",
  108. cpp_bindings_path + "include/core/",
  109. cpp_bindings_path + "include/gen/",
  110. ]
  111. )
  112. env.Append(LIBPATH=[cpp_bindings_path + "bin/"])
  113. env.Append(LIBS=[cpp_library])
  114. # tweak this if you want to use different folders, or more folders, to store your source code in.
  115. env.Append(CPPPATH=["src/"])
  116. sources = Glob("src/*.cpp")
  117. library = env.SharedLibrary(target=env["target_path"] + env["target_name"], source=sources)
  118. Default(library)