toolchain.lua 8.8 KB

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