toolchain.lua 7.1 KB

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