SConstruct 5.0 KB

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