toolchain.lua 7.0 KB

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