toolchain.lua 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. --
  2. -- Copyright (c) 2012-2017 Daniele Bartolini and individual contributors.
  3. -- License: https://github.com/dbartolini/crown/blob/master/LICENSE
  4. --
  5. function toolchain(build_dir, lib_dir)
  6. newoption
  7. {
  8. trigger = "compiler",
  9. value = "COMPILER",
  10. description = "Choose compiler",
  11. allowed =
  12. {
  13. { "android-arm", "Android - ARM" },
  14. { "linux-gcc", "Linux (GCC compiler)" },
  15. { "mingw-gcc", "MinGW (GCC compiler)" },
  16. }
  17. }
  18. if (_ACTION == nil) then return end
  19. if _ACTION == "clean" then
  20. os.rmdir(BUILD_DIR)
  21. end
  22. if _ACTION == "gmake" then
  23. if nil == _OPTIONS["compiler"] then
  24. print("Choose a compiler!")
  25. os.exit(1)
  26. end
  27. if "android-arm" == _OPTIONS["compiler"] then
  28. if not os.getenv("ANDROID_NDK_ROOT") then
  29. print("Set ANDROID_NDK_ROOT environment variable.")
  30. end
  31. if not os.getenv("ANDROID_NDK_ARM") then
  32. print("Set ANDROID_NDK_ARM environment variables.")
  33. end
  34. premake.gcc.cc = "$(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-gcc"
  35. premake.gcc.cxx = "$(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-g++"
  36. premake.gcc.ar = "$(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-ar"
  37. location(build_dir .. "projects/" .. "android")
  38. elseif "linux-gcc" == _OPTIONS["compiler"] then
  39. if not os.is("linux") then
  40. print("Action not valid in current OS.")
  41. end
  42. location(build_dir .. "projects/" .. "linux")
  43. elseif "mingw-gcc" == _OPTIONS["compiler"] then
  44. if not os.getenv("MINGW") then
  45. print("Set MINGW environment variable.")
  46. os.exit(1)
  47. end
  48. premake.gcc.cc = "$(MINGW)/bin/x86_64-w64-mingw32-gcc"
  49. premake.gcc.cxx = "$(MINGW)/bin/x86_64-w64-mingw32-g++"
  50. premake.gcc.ar = "$(MINGW)/bin/ar"
  51. location(build_dir .. "projects/" .. "mingw")
  52. end
  53. elseif _ACTION == "vs2017" then
  54. if not os.is("windows") then
  55. print("Action not valid in current OS.")
  56. end
  57. location(build_dir .. "projects/" .. _ACTION)
  58. end
  59. flags {
  60. "StaticRuntime",
  61. "NoPCH",
  62. "NoRTTI",
  63. "NoExceptions",
  64. "NoEditAndContinue",
  65. "Symbols",
  66. }
  67. defines {
  68. "__STDC_CONSTANT_MACROS",
  69. "__STDC_FORMAT_MACROS",
  70. "__STDC_LIMIT_MACROS",
  71. }
  72. configuration { "debug" }
  73. targetsuffix "-debug"
  74. configuration { "development" }
  75. targetsuffix "-development"
  76. configuration { "release" }
  77. targetsuffix "-release"
  78. configuration { "development or release" }
  79. flags {
  80. "OptimizeSpeed"
  81. }
  82. configuration { "debug or development", "linux-*" }
  83. linkoptions {
  84. "-rdynamic"
  85. }
  86. configuration { "linux-gcc or android-arm" }
  87. buildoptions {
  88. "-Werror=return-type",
  89. }
  90. configuration { "x32", "linux-*" }
  91. targetdir (build_dir .. "linux32" .. "/bin")
  92. objdir (build_dir .. "linux32" .. "/obj")
  93. libdirs {
  94. lib_dir .. "../build/linux32/bin",
  95. }
  96. configuration { "x64", "linux-*" }
  97. targetdir (build_dir .. "linux64" .. "/bin")
  98. objdir (build_dir .. "linux64" .. "/obj")
  99. libdirs {
  100. lib_dir .. "../build/linux64/bin",
  101. }
  102. configuration { "linux-gcc*" }
  103. buildoptions {
  104. "-Wall",
  105. "-Wextra",
  106. "-Wundef",
  107. "-msse2",
  108. }
  109. buildoptions_cpp {
  110. "-std=c++0x",
  111. }
  112. links {
  113. "dl",
  114. }
  115. linkoptions {
  116. "-Wl,-rpath=\\$$ORIGIN",
  117. "-Wl,--no-as-needed",
  118. }
  119. configuration { "android-*" }
  120. targetprefix("lib")
  121. flags {
  122. "NoImportLib"
  123. }
  124. includedirs {
  125. "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.8/include",
  126. "$(ANDROID_NDK_ROOT)/sources/android/native_app_glue",
  127. }
  128. linkoptions {
  129. "-nostdlib",
  130. "-static-libgcc",
  131. }
  132. links {
  133. "c",
  134. "dl",
  135. "m",
  136. "gnustl_static",
  137. "android",
  138. "log",
  139. }
  140. buildoptions {
  141. "-fPIC",
  142. "-no-canonical-prefixes",
  143. "-Wa,--noexecstack",
  144. "-fstack-protector",
  145. "-ffunction-sections",
  146. "-Wno-psabi", -- note: the mangling of 'va_list' has changed in GCC 4.4.0
  147. "-Wunused-value",
  148. }
  149. buildoptions_cpp {
  150. "-std=c++0x",
  151. }
  152. linkoptions {
  153. "-no-canonical-prefixes",
  154. "-Wl,--no-undefined",
  155. "-Wl,-z,noexecstack",
  156. "-Wl,-z,relro",
  157. "-Wl,-z,now",
  158. }
  159. configuration { "android-arm" }
  160. targetdir (build_dir .. "android-arm" .. "/bin")
  161. objdir (build_dir .. "android-arm" .. "/obj")
  162. libdirs {
  163. lib_dir .. "../build/android-arm/bin",
  164. "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a",
  165. }
  166. includedirs {
  167. "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/include",
  168. }
  169. buildoptions {
  170. "--sysroot=$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm",
  171. "-mthumb",
  172. "-march=armv7-a",
  173. "-mfloat-abi=softfp",
  174. "-mfpu=neon",
  175. "-Wunused-value",
  176. }
  177. linkoptions {
  178. "--sysroot=$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm",
  179. "$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm/usr/lib/crtbegin_so.o",
  180. "$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm/usr/lib/crtend_so.o",
  181. "-march=armv7-a",
  182. "-Wl,--fix-cortex-a8",
  183. }
  184. configuration { "mingw-*" }
  185. defines { "WIN32" }
  186. includedirs { path.join(CROWN_DIR, "3rdparty/bx/include/compat/mingw") }
  187. buildoptions {
  188. "-fdata-sections",
  189. "-ffunction-sections",
  190. "-msse2",
  191. "-Wunused-value",
  192. "-Wundef",
  193. }
  194. buildoptions_cpp {
  195. "-std=c++0x",
  196. }
  197. linkoptions {
  198. "-Wl,--gc-sections",
  199. "-static",
  200. "-static-libgcc",
  201. "-static-libstdc++",
  202. }
  203. configuration { "x32", "mingw-gcc" }
  204. targetdir (path.join(build_dir, "mingw32/bin"))
  205. objdir (path.join(build_dir, "mingw32/obj"))
  206. libdirs {
  207. lib_dir .. "../build/mingw32/bin",
  208. }
  209. buildoptions {
  210. "-m32",
  211. "-mstackrealign",
  212. }
  213. configuration { "x64", "mingw-gcc" }
  214. targetdir (path.join(build_dir, "mingw64/bin"))
  215. objdir (path.join(build_dir, "mingw64/obj"))
  216. libdirs {
  217. lib_dir .. "../build/mingw64/bin",
  218. }
  219. buildoptions { "-m64" }
  220. configuration { "vs*" }
  221. includedirs { CROWN_DIR .. "3rdparty/bx/include/compat/msvc" }
  222. defines {
  223. "WIN32",
  224. "_WIN32",
  225. "_HAS_EXCEPTIONS=0",
  226. "_HAS_ITERATOR_DEBUGGING=0",
  227. "_SCL_SECURE=0",
  228. "_SECURE_SCL=0",
  229. "_SCL_SECURE_NO_WARNINGS",
  230. "_CRT_SECURE_NO_WARNINGS",
  231. "_CRT_SECURE_NO_DEPRECATE",
  232. "NOMINMAX",
  233. }
  234. buildoptions {
  235. "/Oy-", -- Suppresses creation of frame pointers on the call stack.
  236. "/Ob2", -- The Inline Function Expansion
  237. }
  238. linkoptions {
  239. "/ignore:4199", -- LNK4199: /DELAYLOAD:*.dll ignored; no imports found from *.dll
  240. "/ignore:4221", -- LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library
  241. "/ignore:4099", -- LNK4099: The linker was unable to find your .pdb file.
  242. }
  243. configuration { "x32", "vs*" }
  244. targetdir (build_dir .. "win32" .. "/bin")
  245. objdir (build_dir .. "win32" .. "/obj")
  246. configuration { "x64", "vs*" }
  247. defines {
  248. "_WIN64",
  249. }
  250. targetdir (build_dir .. "win64" .. "/bin")
  251. objdir (build_dir .. "win64" .. "/obj")
  252. configuration {} -- reset configuration
  253. end
  254. function strip()
  255. configuration { "android-arm", "release"}
  256. postbuildcommands {
  257. "$(SILENT) echo Stripping symbols",
  258. "$(SILENT) $(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-strip -s \"$(TARGET)\""
  259. }
  260. configuration { "linux-*", "release" }
  261. postbuildcommands {
  262. "$(SILENT) echo Stripping symbols",
  263. "$(SILENT) strip -s \"$(TARGET)\""
  264. }
  265. configuration { "mingw*", "Release" }
  266. postbuildcommands {
  267. "$(SILENT) echo Stripping symbols.",
  268. "$(SILENT) $(MINGW)/bin/strip -s \"$(TARGET)\""
  269. }
  270. configuration {} -- reset configuration
  271. end