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"
  64. or _ACTION == "vs2019"
  65. then
  66. if not os.is("windows") then
  67. print("Action not valid in current OS.")
  68. end
  69. local windowsPlatform = string.gsub(os.getenv("WindowsSDKVersion") or "8.1", "\\", "")
  70. local action = premake.action.current()
  71. action.vstudio.windowsTargetPlatformVersion = windowsPlatform
  72. action.vstudio.windowsTargetPlatformMinVersion = windowsPlatform
  73. location(build_dir .. "projects/" .. _ACTION)
  74. end
  75. flags {
  76. "StaticRuntime",
  77. "NoPCH",
  78. "NoRTTI",
  79. "NoExceptions",
  80. "NoEditAndContinue",
  81. "NoFramePointer",
  82. "Symbols",
  83. }
  84. defines {
  85. "__STDC_CONSTANT_MACROS",
  86. "__STDC_FORMAT_MACROS",
  87. "__STDC_LIMIT_MACROS",
  88. }
  89. configuration { "debug" }
  90. targetsuffix "-debug"
  91. configuration { "development" }
  92. targetsuffix "-development"
  93. configuration { "release" }
  94. targetsuffix "-release"
  95. configuration { "development or release" }
  96. flags {
  97. "OptimizeSpeed"
  98. }
  99. configuration { "debug or development", "linux-*" }
  100. linkoptions {
  101. "-rdynamic"
  102. }
  103. configuration { "linux-gcc or android-arm" }
  104. buildoptions {
  105. "-Werror=return-type",
  106. }
  107. configuration { "x32", "linux-gcc" }
  108. targetdir (build_dir .. "linux32" .. "/bin")
  109. objdir (build_dir .. "linux32" .. "/obj")
  110. libdirs {
  111. lib_dir .. "../build/linux32/bin",
  112. }
  113. configuration { "x64", "linux-gcc" }
  114. targetdir (build_dir .. "linux64" .. "/bin")
  115. objdir (build_dir .. "linux64" .. "/obj")
  116. libdirs {
  117. lib_dir .. "../build/linux64/bin",
  118. }
  119. configuration { "x64", "linux-clang" }
  120. targetdir (build_dir .. "linux64_clang" .. "/bin")
  121. objdir (build_dir .. "linux64_clang" .. "/obj")
  122. libdirs {
  123. lib_dir .. "../build/linux64_clang/bin",
  124. }
  125. configuration { "x32", "vs*" }
  126. targetdir (build_dir .. "win32" .. "/bin")
  127. objdir (build_dir .. "win32" .. "/obj")
  128. libdirs {
  129. lib_dir .. "../build/win32/bin",
  130. }
  131. configuration { "x64", "vs*" }
  132. targetdir (build_dir .. "win64" .. "/bin")
  133. objdir (build_dir .. "win64" .. "/obj")
  134. libdirs {
  135. lib_dir .. "../build/win64/bin",
  136. }
  137. configuration { "linux-gcc* or linux-clang" }
  138. buildoptions {
  139. "-Wall",
  140. "-Wextra",
  141. "-Wundef",
  142. "-msse2",
  143. }
  144. buildoptions_cpp {
  145. "-std=c++14",
  146. }
  147. links {
  148. "dl",
  149. }
  150. linkoptions {
  151. "-Wl,-rpath=\\$$ORIGIN",
  152. "-Wl,--no-as-needed",
  153. "-no-pie",
  154. }
  155. configuration { "android-*" }
  156. targetprefix("lib")
  157. flags {
  158. "NoImportLib"
  159. }
  160. includedirs {
  161. "$(ANDROID_NDK_ROOT)/sources/android/native_app_glue",
  162. }
  163. linkoptions {
  164. "-nostdlib",
  165. }
  166. links {
  167. "c",
  168. "dl",
  169. "m",
  170. "android",
  171. "log",
  172. "c++_shared",
  173. "gcc",
  174. }
  175. buildoptions {
  176. "-fPIC",
  177. "-no-canonical-prefixes",
  178. "-Wa,--noexecstack",
  179. "-fstack-protector-strong",
  180. "-ffunction-sections",
  181. "-Wunused-value",
  182. "-Wundef",
  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/llvm-libc++/libs/armeabi-v7a",
  197. }
  198. includedirs {
  199. "$(ANDROID_NDK_ROOT)/sysroot/usr/include/arm-linux-androideabi", -- <asm/...>
  200. }
  201. buildoptions {
  202. "--target=armv7-none-linux-androideabi$(ANDROID_NDK_ABI)",
  203. "--gcc-toolchain=$(ANDROID_NDK_ROOT)/toolchains/llvm/prebuilt/linux-x86_64",
  204. "--sysroot=$(ANDROID_NDK_ROOT)/toolchains/llvm/prebuilt/linux-x86_64/sysroot",
  205. "-mthumb",
  206. "-march=armv7-a",
  207. "-mfloat-abi=softfp",
  208. "-mfpu=neon",
  209. "-Wunused-value",
  210. "-Wundef",
  211. }
  212. linkoptions {
  213. "--target=armv7-none-linux-androideabi$(ANDROID_NDK_ABI)",
  214. "--gcc-toolchain=$(ANDROID_NDK_ROOT)/toolchains/llvm/prebuilt/linux-x86_64",
  215. "--sysroot=$(ANDROID_NDK_ROOT)/toolchains/llvm/prebuilt/linux-x86_64/sysroot",
  216. "$(ANDROID_NDK_ROOT)/platforms/android-$(ANDROID_NDK_ABI)/arch-arm/usr/lib/crtbegin_so.o",
  217. "$(ANDROID_NDK_ROOT)/platforms/android-$(ANDROID_NDK_ABI)/arch-arm/usr/lib/crtend_so.o",
  218. "-march=armv7-a",
  219. "-Wl,--fix-cortex-a8",
  220. }
  221. configuration { "mingw-*" }
  222. defines { "WIN32" }
  223. includedirs { path.join(CROWN_DIR, "3rdparty/bx/include/compat/mingw") }
  224. buildoptions {
  225. "-fdata-sections",
  226. "-ffunction-sections",
  227. "-msse2",
  228. "-Wunused-value",
  229. "-Wundef",
  230. }
  231. buildoptions_cpp {
  232. "-std=c++14",
  233. }
  234. linkoptions {
  235. "-Wl,--gc-sections",
  236. "-static",
  237. "-static-libgcc",
  238. "-static-libstdc++",
  239. }
  240. configuration { "x32", "mingw-gcc" }
  241. targetdir (path.join(build_dir, "mingw32/bin"))
  242. objdir (path.join(build_dir, "mingw32/obj"))
  243. libdirs {
  244. lib_dir .. "../build/mingw32/bin",
  245. }
  246. buildoptions {
  247. "-m32",
  248. "-mstackrealign",
  249. }
  250. configuration { "x64", "mingw-gcc" }
  251. targetdir (path.join(build_dir, "mingw64/bin"))
  252. objdir (path.join(build_dir, "mingw64/obj"))
  253. libdirs {
  254. lib_dir .. "../build/mingw64/bin",
  255. }
  256. buildoptions { "-m64" }
  257. configuration { "vs*" }
  258. includedirs { CROWN_DIR .. "3rdparty/bx/include/compat/msvc" }
  259. defines {
  260. "WIN32",
  261. "_WIN32",
  262. "_HAS_EXCEPTIONS=0",
  263. "_HAS_ITERATOR_DEBUGGING=0",
  264. "_SCL_SECURE=0",
  265. "_SECURE_SCL=0",
  266. "_SCL_SECURE_NO_WARNINGS",
  267. "_CRT_SECURE_NO_WARNINGS",
  268. "_CRT_SECURE_NO_DEPRECATE",
  269. "NOMINMAX",
  270. }
  271. buildoptions {
  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