toolchain.lua 6.1 KB

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