toolchain.lua 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. --
  2. -- Copyright (c) 2012-2016 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. }
  16. }
  17. if (_ACTION == nil) then return end
  18. if _ACTION == "clean" then
  19. os.rmdir(BUILD_DIR)
  20. end
  21. if _ACTION == "gmake" then
  22. if nil == _OPTIONS["compiler"] then
  23. print("Choose a compiler!")
  24. os.exit(1)
  25. end
  26. if "linux-gcc" == _OPTIONS["compiler"] then
  27. if not os.is("linux") then
  28. print("Action not valid in current OS.")
  29. end
  30. location(build_dir .. "projects/" .. "linux")
  31. elseif "android-arm" == _OPTIONS["compiler"] then
  32. if not os.getenv("ANDROID_NDK_ROOT") then
  33. print("Set ANDROID_NDK_ROOT environment variable.")
  34. end
  35. if not os.getenv("ANDROID_NDK_ARM") then
  36. print("Set ANDROID_NDK_ARM environment variables.")
  37. end
  38. premake.gcc.cc = "$(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-gcc"
  39. premake.gcc.cxx = "$(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-g++"
  40. premake.gcc.ar = "$(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-ar"
  41. location(build_dir .. "projects/" .. "android")
  42. end
  43. elseif _ACTION == "vs2013" then
  44. if not os.is("windows") then
  45. print("Action not valid in current OS.")
  46. end
  47. location(build_dir .. "projects/" .. _ACTION)
  48. end
  49. flags {
  50. "StaticRuntime",
  51. "NoPCH",
  52. "NoRTTI",
  53. "NoExceptions",
  54. "NoEditAndContinue",
  55. "Symbols",
  56. }
  57. defines {
  58. "__STDC_CONSTANT_MACROS",
  59. "__STDC_FORMAT_MACROS",
  60. "__STDC_LIMIT_MACROS",
  61. }
  62. configuration { "development or release" }
  63. flags {
  64. "OptimizeSpeed"
  65. }
  66. configuration { "debug", "x32" }
  67. targetsuffix "-debug-32"
  68. configuration { "debug", "x64" }
  69. targetsuffix "-debug-64"
  70. configuration { "development", "x32" }
  71. targetsuffix "-development-32"
  72. configuration { "development", "x64" }
  73. targetsuffix "-development-64"
  74. configuration { "release", "x32" }
  75. targetsuffix "-release-32"
  76. configuration { "release", "x64" }
  77. targetsuffix "-release-64"
  78. configuration { "debug", "native" }
  79. targetsuffix "-debug"
  80. configuration { "development", "native" }
  81. targetsuffix "-development"
  82. configuration { "release", "native" }
  83. targetsuffix "-release"
  84. configuration { "debug or development", "linux-*" }
  85. linkoptions {
  86. "-rdynamic"
  87. }
  88. configuration { "linux-gcc or android-arm" }
  89. buildoptions {
  90. "-Werror=return-type",
  91. }
  92. configuration { "x32", "linux-*" }
  93. targetdir (build_dir .. "linux32" .. "/bin")
  94. objdir (build_dir .. "linux32" .. "/obj")
  95. libdirs {
  96. lib_dir .. "../.build/linux32/bin",
  97. }
  98. configuration { "x64", "linux-*" }
  99. targetdir (build_dir .. "linux64" .. "/bin")
  100. objdir (build_dir .. "linux64" .. "/obj")
  101. libdirs {
  102. lib_dir .. "../.build/linux64/bin",
  103. }
  104. configuration { "linux-*" }
  105. buildoptions {
  106. "-Wall",
  107. "-Wextra",
  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. 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. "gcc",
  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 { "vs*" }
  183. includedirs { CROWN_DIR .. "src/core/compat/msvc" }
  184. defines {
  185. "WIN32",
  186. "_WIN32",
  187. "_HAS_EXCEPTIONS=0",
  188. "_HAS_ITERATOR_DEBUGGING=0",
  189. "_SCL_SECURE=0",
  190. "_SECURE_SCL=0",
  191. "_SCL_SECURE_NO_WARNINGS",
  192. "_CRT_SECURE_NO_WARNINGS",
  193. "_CRT_SECURE_NO_DEPRECATE",
  194. "NOMINMAX",
  195. }
  196. buildoptions {
  197. "/Oy-", -- Suppresses creation of frame pointers on the call stack.
  198. "/Ob2", -- The Inline Function Expansion
  199. }
  200. linkoptions {
  201. "/ignore:4199", -- LNK4199: /DELAYLOAD:*.dll ignored; no imports found from *.dll
  202. "/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
  203. "/ignore:4099", -- LNK4099: The linker was unable to find your .pdb file.
  204. }
  205. configuration { "x32", "vs*" }
  206. targetdir (build_dir .. "win32" .. "/bin")
  207. objdir (build_dir .. "win32" .. "/obj")
  208. configuration { "x64", "vs*" }
  209. defines {
  210. "_WIN64",
  211. }
  212. targetdir (build_dir .. "win64" .. "/bin")
  213. objdir (build_dir .. "win64" .. "/obj")
  214. configuration {} -- reset configuration
  215. end
  216. function strip()
  217. configuration { "android-arm", "release"}
  218. postbuildcommands {
  219. "$(SILENT) echo Stripping symbols",
  220. "$(SILENT) $(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-strip -s \"$(TARGET)\""
  221. }
  222. configuration { "linux-*", "release" }
  223. postbuildcommands {
  224. "$(SILENT) echo Stripping symbols",
  225. "$(SILENT) strip -s \"$(TARGET)\""
  226. }
  227. configuration {} -- reset configuration
  228. end