toolchain.lua 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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. local windowsPlatform = string.gsub(os.getenv("WindowsSDKVersion") or "8.1", "\\", "")
  58. local action = premake.action.current()
  59. action.vstudio.windowsTargetPlatformVersion = windowsPlatform
  60. action.vstudio.windowsTargetPlatformMinVersion = windowsPlatform
  61. location(build_dir .. "projects/" .. _ACTION)
  62. end
  63. flags {
  64. "StaticRuntime",
  65. "NoPCH",
  66. "NoRTTI",
  67. "NoExceptions",
  68. "NoEditAndContinue",
  69. "Symbols",
  70. }
  71. defines {
  72. "__STDC_CONSTANT_MACROS",
  73. "__STDC_FORMAT_MACROS",
  74. "__STDC_LIMIT_MACROS",
  75. }
  76. configuration { "debug" }
  77. targetsuffix "-debug"
  78. configuration { "development" }
  79. targetsuffix "-development"
  80. configuration { "release" }
  81. targetsuffix "-release"
  82. configuration { "development or release" }
  83. flags {
  84. "OptimizeSpeed"
  85. }
  86. configuration { "debug or development", "linux-*" }
  87. linkoptions {
  88. "-rdynamic"
  89. }
  90. configuration { "linux-gcc or android-arm" }
  91. buildoptions {
  92. "-Werror=return-type",
  93. }
  94. configuration { "x32", "linux-*" }
  95. targetdir (build_dir .. "linux32" .. "/bin")
  96. objdir (build_dir .. "linux32" .. "/obj")
  97. libdirs {
  98. lib_dir .. "../build/linux32/bin",
  99. }
  100. configuration { "x64", "linux-*" }
  101. targetdir (build_dir .. "linux64" .. "/bin")
  102. objdir (build_dir .. "linux64" .. "/obj")
  103. libdirs {
  104. lib_dir .. "../build/linux64/bin",
  105. }
  106. configuration { "linux-gcc*" }
  107. buildoptions {
  108. "-Wall",
  109. "-Wextra",
  110. "-Wundef",
  111. "-msse2",
  112. }
  113. buildoptions_cpp {
  114. "-std=c++14",
  115. }
  116. links {
  117. "dl",
  118. }
  119. linkoptions {
  120. "-Wl,-rpath=\\$$ORIGIN",
  121. "-Wl,--no-as-needed",
  122. "-no-pie",
  123. }
  124. configuration { "android-*" }
  125. targetprefix("lib")
  126. flags {
  127. "NoImportLib"
  128. }
  129. includedirs {
  130. "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.8/include",
  131. "$(ANDROID_NDK_ROOT)/sources/android/native_app_glue",
  132. }
  133. linkoptions {
  134. "-nostdlib",
  135. "-static-libgcc",
  136. }
  137. links {
  138. "c",
  139. "dl",
  140. "m",
  141. "gnustl_static",
  142. "android",
  143. "log",
  144. }
  145. buildoptions {
  146. "-fPIC",
  147. "-no-canonical-prefixes",
  148. "-Wa,--noexecstack",
  149. "-fstack-protector",
  150. "-ffunction-sections",
  151. "-Wno-psabi", -- note: the mangling of 'va_list' has changed in GCC 4.4.0
  152. "-Wunused-value",
  153. }
  154. buildoptions_cpp {
  155. "-std=c++14",
  156. }
  157. linkoptions {
  158. "-no-canonical-prefixes",
  159. "-Wl,--no-undefined",
  160. "-Wl,-z,noexecstack",
  161. "-Wl,-z,relro",
  162. "-Wl,-z,now",
  163. }
  164. configuration { "android-arm" }
  165. targetdir (build_dir .. "android-arm" .. "/bin")
  166. objdir (build_dir .. "android-arm" .. "/obj")
  167. libdirs {
  168. lib_dir .. "../build/android-arm/bin",
  169. "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a",
  170. }
  171. includedirs {
  172. "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/include",
  173. }
  174. buildoptions {
  175. "--sysroot=$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm",
  176. "-mthumb",
  177. "-march=armv7-a",
  178. "-mfloat-abi=softfp",
  179. "-mfpu=neon",
  180. "-Wunused-value",
  181. }
  182. linkoptions {
  183. "--sysroot=$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm",
  184. "$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm/usr/lib/crtbegin_so.o",
  185. "$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm/usr/lib/crtend_so.o",
  186. "-march=armv7-a",
  187. "-Wl,--fix-cortex-a8",
  188. }
  189. configuration { "mingw-*" }
  190. defines { "WIN32" }
  191. includedirs { path.join(CROWN_DIR, "3rdparty/bx/include/compat/mingw") }
  192. buildoptions {
  193. "-fdata-sections",
  194. "-ffunction-sections",
  195. "-msse2",
  196. "-Wunused-value",
  197. "-Wundef",
  198. }
  199. buildoptions_cpp {
  200. "-std=c++14",
  201. }
  202. linkoptions {
  203. "-Wl,--gc-sections",
  204. "-static",
  205. "-static-libgcc",
  206. "-static-libstdc++",
  207. }
  208. configuration { "x32", "mingw-gcc" }
  209. targetdir (path.join(build_dir, "mingw32/bin"))
  210. objdir (path.join(build_dir, "mingw32/obj"))
  211. libdirs {
  212. lib_dir .. "../build/mingw32/bin",
  213. }
  214. buildoptions {
  215. "-m32",
  216. "-mstackrealign",
  217. }
  218. configuration { "x64", "mingw-gcc" }
  219. targetdir (path.join(build_dir, "mingw64/bin"))
  220. objdir (path.join(build_dir, "mingw64/obj"))
  221. libdirs {
  222. lib_dir .. "../build/mingw64/bin",
  223. }
  224. buildoptions { "-m64" }
  225. configuration { "vs*" }
  226. includedirs { CROWN_DIR .. "3rdparty/bx/include/compat/msvc" }
  227. defines {
  228. "WIN32",
  229. "_WIN32",
  230. "_HAS_EXCEPTIONS=0",
  231. "_HAS_ITERATOR_DEBUGGING=0",
  232. "_SCL_SECURE=0",
  233. "_SECURE_SCL=0",
  234. "_SCL_SECURE_NO_WARNINGS",
  235. "_CRT_SECURE_NO_WARNINGS",
  236. "_CRT_SECURE_NO_DEPRECATE",
  237. "NOMINMAX",
  238. }
  239. buildoptions {
  240. "/Oy-", -- Suppresses creation of frame pointers on the call stack.
  241. "/Ob2", -- The Inline Function Expansion
  242. }
  243. linkoptions {
  244. "/ignore:4199", -- LNK4199: /DELAYLOAD:*.dll ignored; no imports found from *.dll
  245. "/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
  246. "/ignore:4099", -- LNK4099: The linker was unable to find your .pdb file.
  247. }
  248. configuration { "x32", "vs*" }
  249. targetdir (build_dir .. "win32" .. "/bin")
  250. objdir (build_dir .. "win32" .. "/obj")
  251. configuration { "x64", "vs*" }
  252. defines {
  253. "_WIN64",
  254. }
  255. targetdir (build_dir .. "win64" .. "/bin")
  256. objdir (build_dir .. "win64" .. "/obj")
  257. configuration {} -- reset configuration
  258. end
  259. function strip()
  260. configuration { "android-arm", "release"}
  261. postbuildcommands {
  262. "$(SILENT) echo Stripping symbols",
  263. "$(SILENT) $(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-strip -s \"$(TARGET)\""
  264. }
  265. configuration { "linux-*", "release" }
  266. postbuildcommands {
  267. "$(SILENT) echo Stripping symbols",
  268. "$(SILENT) strip -s \"$(TARGET)\""
  269. }
  270. configuration { "mingw*", "Release" }
  271. postbuildcommands {
  272. "$(SILENT) echo Stripping symbols.",
  273. "$(SILENT) $(MINGW)/bin/strip -s \"$(TARGET)\""
  274. }
  275. configuration {} -- reset configuration
  276. end