toolchain.lua 8.3 KB

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