toolchain.lua 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. --
  2. -- Copyright (c) 2012-2018 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++14",
  111. }
  112. links {
  113. "dl",
  114. }
  115. linkoptions {
  116. "-Wl,-rpath=\\$$ORIGIN",
  117. "-Wl,--no-as-needed",
  118. "-no-pie",
  119. }
  120. configuration { "android-*" }
  121. targetprefix("lib")
  122. flags {
  123. "NoImportLib"
  124. }
  125. includedirs {
  126. "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.8/include",
  127. "$(ANDROID_NDK_ROOT)/sources/android/native_app_glue",
  128. }
  129. linkoptions {
  130. "-nostdlib",
  131. "-static-libgcc",
  132. }
  133. links {
  134. "c",
  135. "dl",
  136. "m",
  137. "gnustl_static",
  138. "android",
  139. "log",
  140. }
  141. buildoptions {
  142. "-fPIC",
  143. "-no-canonical-prefixes",
  144. "-Wa,--noexecstack",
  145. "-fstack-protector",
  146. "-ffunction-sections",
  147. "-Wno-psabi", -- note: the mangling of 'va_list' has changed in GCC 4.4.0
  148. "-Wunused-value",
  149. }
  150. buildoptions_cpp {
  151. "-std=c++14",
  152. }
  153. linkoptions {
  154. "-no-canonical-prefixes",
  155. "-Wl,--no-undefined",
  156. "-Wl,-z,noexecstack",
  157. "-Wl,-z,relro",
  158. "-Wl,-z,now",
  159. }
  160. configuration { "android-arm" }
  161. targetdir (build_dir .. "android-arm" .. "/bin")
  162. objdir (build_dir .. "android-arm" .. "/obj")
  163. libdirs {
  164. lib_dir .. "../build/android-arm/bin",
  165. "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a",
  166. }
  167. includedirs {
  168. "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/include",
  169. }
  170. buildoptions {
  171. "--sysroot=$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm",
  172. "-mthumb",
  173. "-march=armv7-a",
  174. "-mfloat-abi=softfp",
  175. "-mfpu=neon",
  176. "-Wunused-value",
  177. }
  178. linkoptions {
  179. "--sysroot=$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm",
  180. "$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm/usr/lib/crtbegin_so.o",
  181. "$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm/usr/lib/crtend_so.o",
  182. "-march=armv7-a",
  183. "-Wl,--fix-cortex-a8",
  184. }
  185. configuration { "mingw-*" }
  186. defines { "WIN32" }
  187. includedirs { path.join(CROWN_DIR, "3rdparty/bx/include/compat/mingw") }
  188. buildoptions {
  189. "-fdata-sections",
  190. "-ffunction-sections",
  191. "-msse2",
  192. "-Wunused-value",
  193. "-Wundef",
  194. }
  195. buildoptions_cpp {
  196. "-std=c++14",
  197. }
  198. linkoptions {
  199. "-Wl,--gc-sections",
  200. "-static",
  201. "-static-libgcc",
  202. "-static-libstdc++",
  203. }
  204. configuration { "x32", "mingw-gcc" }
  205. targetdir (path.join(build_dir, "mingw32/bin"))
  206. objdir (path.join(build_dir, "mingw32/obj"))
  207. libdirs {
  208. lib_dir .. "../build/mingw32/bin",
  209. }
  210. buildoptions {
  211. "-m32",
  212. "-mstackrealign",
  213. }
  214. configuration { "x64", "mingw-gcc" }
  215. targetdir (path.join(build_dir, "mingw64/bin"))
  216. objdir (path.join(build_dir, "mingw64/obj"))
  217. libdirs {
  218. lib_dir .. "../build/mingw64/bin",
  219. }
  220. buildoptions { "-m64" }
  221. configuration { "vs*" }
  222. includedirs { CROWN_DIR .. "3rdparty/bx/include/compat/msvc" }
  223. defines {
  224. "WIN32",
  225. "_WIN32",
  226. "_HAS_EXCEPTIONS=0",
  227. "_HAS_ITERATOR_DEBUGGING=0",
  228. "_SCL_SECURE=0",
  229. "_SECURE_SCL=0",
  230. "_SCL_SECURE_NO_WARNINGS",
  231. "_CRT_SECURE_NO_WARNINGS",
  232. "_CRT_SECURE_NO_DEPRECATE",
  233. "NOMINMAX",
  234. }
  235. buildoptions {
  236. "/Oy-", -- Suppresses creation of frame pointers on the call stack.
  237. "/Ob2", -- The Inline Function Expansion
  238. }
  239. linkoptions {
  240. "/ignore:4199", -- LNK4199: /DELAYLOAD:*.dll ignored; no imports found from *.dll
  241. "/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
  242. "/ignore:4099", -- LNK4099: The linker was unable to find your .pdb file.
  243. }
  244. configuration { "x32", "vs*" }
  245. targetdir (build_dir .. "win32" .. "/bin")
  246. objdir (build_dir .. "win32" .. "/obj")
  247. configuration { "x64", "vs*" }
  248. defines {
  249. "_WIN64",
  250. }
  251. targetdir (build_dir .. "win64" .. "/bin")
  252. objdir (build_dir .. "win64" .. "/obj")
  253. configuration {} -- reset configuration
  254. end
  255. function strip()
  256. configuration { "android-arm", "release"}
  257. postbuildcommands {
  258. "$(SILENT) echo Stripping symbols",
  259. "$(SILENT) $(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-strip -s \"$(TARGET)\""
  260. }
  261. configuration { "linux-*", "release" }
  262. postbuildcommands {
  263. "$(SILENT) echo Stripping symbols",
  264. "$(SILENT) strip -s \"$(TARGET)\""
  265. }
  266. configuration { "mingw*", "Release" }
  267. postbuildcommands {
  268. "$(SILENT) echo Stripping symbols.",
  269. "$(SILENT) $(MINGW)/bin/strip -s \"$(TARGET)\""
  270. }
  271. configuration {} -- reset configuration
  272. end