toolchain.lua 8.7 KB

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