toolchain.lua 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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. }
  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 { "debug" }
  63. targetsuffix "-debug"
  64. configuration { "development" }
  65. targetsuffix "-development"
  66. configuration { "release" }
  67. targetsuffix "-release"
  68. configuration { "development or release" }
  69. flags {
  70. "OptimizeSpeed"
  71. }
  72. configuration { "debug or development", "linux-*" }
  73. linkoptions {
  74. "-rdynamic"
  75. }
  76. configuration { "linux-gcc or android-arm" }
  77. buildoptions {
  78. "-Werror=return-type",
  79. }
  80. configuration { "x32", "linux-*" }
  81. targetdir (build_dir .. "linux32" .. "/bin")
  82. objdir (build_dir .. "linux32" .. "/obj")
  83. libdirs {
  84. lib_dir .. "../.build/linux32/bin",
  85. }
  86. configuration { "x64", "linux-*" }
  87. targetdir (build_dir .. "linux64" .. "/bin")
  88. objdir (build_dir .. "linux64" .. "/obj")
  89. libdirs {
  90. lib_dir .. "../.build/linux64/bin",
  91. }
  92. configuration { "linux-*" }
  93. buildoptions {
  94. "-Wall",
  95. "-Wextra",
  96. "-Wundef",
  97. "-msse2",
  98. }
  99. buildoptions_cpp {
  100. "-std=c++0x",
  101. }
  102. linkoptions {
  103. "-Wl,-rpath=\\$$ORIGIN",
  104. "-Wl,--no-as-needed",
  105. }
  106. configuration { "android-*" }
  107. targetprefix("lib")
  108. flags {
  109. "NoImportLib"
  110. }
  111. includedirs {
  112. "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.8/include",
  113. "$(ANDROID_NDK_ROOT)/sources/android/native_app_glue",
  114. }
  115. linkoptions {
  116. "-nostdlib",
  117. "-static-libgcc",
  118. }
  119. links {
  120. "c",
  121. "dl",
  122. "m",
  123. "gnustl_static",
  124. "android",
  125. "log",
  126. }
  127. buildoptions {
  128. "-fPIC",
  129. "-no-canonical-prefixes",
  130. "-Wa,--noexecstack",
  131. "-fstack-protector",
  132. "-ffunction-sections",
  133. "-Wno-psabi", -- note: the mangling of 'va_list' has changed in GCC 4.4.0
  134. "-Wunused-value",
  135. }
  136. buildoptions_cpp {
  137. "-std=c++0x",
  138. }
  139. linkoptions {
  140. "-no-canonical-prefixes",
  141. "-Wl,--no-undefined",
  142. "-Wl,-z,noexecstack",
  143. "-Wl,-z,relro",
  144. "-Wl,-z,now",
  145. }
  146. configuration { "android-arm" }
  147. targetdir (build_dir .. "android-arm" .. "/bin")
  148. objdir (build_dir .. "android-arm" .. "/obj")
  149. libdirs {
  150. lib_dir .. "../.build/android-arm/bin",
  151. "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a",
  152. }
  153. includedirs {
  154. "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/include",
  155. }
  156. buildoptions {
  157. "--sysroot=$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm",
  158. "-mthumb",
  159. "-march=armv7-a",
  160. "-mfloat-abi=softfp",
  161. "-mfpu=neon",
  162. "-Wunused-value",
  163. }
  164. linkoptions {
  165. "--sysroot=$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm",
  166. "$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm/usr/lib/crtbegin_so.o",
  167. "$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm/usr/lib/crtend_so.o",
  168. "-march=armv7-a",
  169. "-Wl,--fix-cortex-a8",
  170. }
  171. configuration { "vs*" }
  172. includedirs { CROWN_DIR .. "src/core/compat/msvc" }
  173. defines {
  174. "WIN32",
  175. "_WIN32",
  176. "_HAS_EXCEPTIONS=0",
  177. "_HAS_ITERATOR_DEBUGGING=0",
  178. "_SCL_SECURE=0",
  179. "_SECURE_SCL=0",
  180. "_SCL_SECURE_NO_WARNINGS",
  181. "_CRT_SECURE_NO_WARNINGS",
  182. "_CRT_SECURE_NO_DEPRECATE",
  183. "NOMINMAX",
  184. }
  185. buildoptions {
  186. "/Oy-", -- Suppresses creation of frame pointers on the call stack.
  187. "/Ob2", -- The Inline Function Expansion
  188. }
  189. linkoptions {
  190. "/ignore:4199", -- LNK4199: /DELAYLOAD:*.dll ignored; no imports found from *.dll
  191. "/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
  192. "/ignore:4099", -- LNK4099: The linker was unable to find your .pdb file.
  193. }
  194. configuration { "x32", "vs*" }
  195. targetdir (build_dir .. "win32" .. "/bin")
  196. objdir (build_dir .. "win32" .. "/obj")
  197. configuration { "x64", "vs*" }
  198. defines {
  199. "_WIN64",
  200. }
  201. targetdir (build_dir .. "win64" .. "/bin")
  202. objdir (build_dir .. "win64" .. "/obj")
  203. configuration {} -- reset configuration
  204. end
  205. function strip()
  206. configuration { "android-arm", "release"}
  207. postbuildcommands {
  208. "$(SILENT) echo Stripping symbols",
  209. "$(SILENT) $(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-strip -s \"$(TARGET)\""
  210. }
  211. configuration { "linux-*", "release" }
  212. postbuildcommands {
  213. "$(SILENT) echo Stripping symbols",
  214. "$(SILENT) strip -s \"$(TARGET)\""
  215. }
  216. configuration {} -- reset configuration
  217. end