toolchain.lua 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. --
  2. -- Copyright (c) 2012-2015 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 print("Action not valid in current OS.") end
  29. if not os.getenv("PHYSX_SDK_LINUX") then
  30. print("Set PHYSX_SDK_LINUX environment variable.")
  31. end
  32. location(build_dir .. "projects/" .. "linux")
  33. end
  34. if "android-arm" == _OPTIONS["compiler"] then
  35. if not os.getenv("ANDROID_NDK_ROOT") then
  36. print("Set ANDROID_NDK_ROOT environment variable.")
  37. end
  38. if not os.getenv("ANDROID_NDK_ARM") then
  39. print("Set ANDROID_NDK_ARM environment variables.")
  40. end
  41. if not os.getenv("PHYSX_SDK_ANDROID") then
  42. print("Set PHYSX_SDK_ANDROID environment variable.")
  43. end
  44. premake.gcc.cc = "$(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-gcc"
  45. premake.gcc.cxx = "$(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-g++"
  46. premake.gcc.ar = "$(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-ar"
  47. location(build_dir .. "projects/" .. "android")
  48. end
  49. end
  50. if _ACTION == "vs2013" then
  51. if not os.is("windows") then print("Action not valid in current OS.") end
  52. if not os.getenv("PHYSX_SDK_WINDOWS") then
  53. print("Set PHYSX_SDK_WINDOWS environment variable.")
  54. end
  55. if not os.getenv("DXSDK_DIR") then
  56. print("Set DXSDK_DIR environment variable.")
  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_FORMAT_MACROS",
  70. "__STDC_CONSTANT_MACROS",
  71. "__STDC_LIMIT_MACROS",
  72. }
  73. configuration { "development or release" }
  74. flags {
  75. "OptimizeSpeed"
  76. }
  77. configuration { "debug", "x32" }
  78. targetsuffix "-debug-32"
  79. configuration { "debug", "x64" }
  80. targetsuffix "-debug-64"
  81. configuration { "development", "x32" }
  82. targetsuffix "-development-32"
  83. configuration { "development", "x64" }
  84. targetsuffix "-development-64"
  85. configuration { "release", "x32" }
  86. targetsuffix "-release-32"
  87. configuration { "release", "x64" }
  88. targetsuffix "-release-64"
  89. configuration { "debug", "native" }
  90. targetsuffix "-debug"
  91. configuration { "development", "native" }
  92. targetsuffix "-development"
  93. configuration { "release", "native" }
  94. targetsuffix "-release"
  95. configuration { "x32", "linux-*" }
  96. targetdir (build_dir .. "linux32" .. "/bin")
  97. objdir (build_dir .. "linux32" .. "/obj")
  98. libdirs {
  99. lib_dir .. "../.build/linux32/bin",
  100. "$(PHYSX_SDK_LINUX)/Lib/linux32"
  101. }
  102. buildoptions {
  103. "-m32",
  104. "-malign-double", -- Required by PhysX
  105. }
  106. configuration { "x64", "linux-*" }
  107. targetdir (build_dir .. "linux64" .. "/bin")
  108. objdir (build_dir .. "linux64" .. "/obj")
  109. libdirs {
  110. lib_dir .. "../.build/linux64/bin",
  111. "$(PHYSX_SDK_LINUX)/Lib/linux64"
  112. }
  113. buildoptions {
  114. "-m64",
  115. }
  116. configuration { "linux-*" }
  117. buildoptions {
  118. "-Wall",
  119. "-Wextra",
  120. "-msse2",
  121. -- "-Werror",
  122. -- "-pedantic",
  123. "-Wno-unknown-pragmas",
  124. "-Wno-unused-local-typedefs",
  125. }
  126. buildoptions_cpp {
  127. "-std=c++03",
  128. }
  129. linkoptions {
  130. "-Wl,-rpath=\\$$ORIGIN",
  131. "-Wl,--no-as-needed",
  132. }
  133. configuration { "android-*" }
  134. flags {
  135. "NoImportLib"
  136. }
  137. includedirs {
  138. "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.8/include",
  139. "$(ANDROID_NDK_ROOT)/sources/android/native_app_glue",
  140. }
  141. linkoptions {
  142. "-nostdlib",
  143. "-static-libgcc",
  144. }
  145. links {
  146. "c",
  147. "dl",
  148. "m",
  149. "android",
  150. "log",
  151. "gnustl_static",
  152. "gcc",
  153. }
  154. buildoptions {
  155. "-fPIC",
  156. "-no-canonical-prefixes",
  157. "-Wa,--noexecstack",
  158. "-fstack-protector",
  159. "-ffunction-sections",
  160. "-Wno-psabi", -- note: the mangling of 'va_list' has changed in GCC 4.4.0
  161. "-Wunused-value",
  162. -- "-Wundef", -- note: avoids PhysX warnings
  163. }
  164. buildoptions_cpp {
  165. "-std=c++03",
  166. }
  167. linkoptions {
  168. "-no-canonical-prefixes",
  169. "-Wl,--no-undefined",
  170. "-Wl,-z,noexecstack",
  171. "-Wl,-z,relro",
  172. "-Wl,-z,now",
  173. }
  174. configuration { "android-arm" }
  175. targetdir (build_dir .. "android-arm" .. "/bin")
  176. objdir (build_dir .. "android-arm" .. "/obj")
  177. libdirs {
  178. lib_dir .. "../.build/android-arm/bin",
  179. "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a",
  180. "$(PHYSX_SDK_ANDROID)/Lib/android9_neon",
  181. }
  182. includedirs {
  183. "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/include",
  184. }
  185. buildoptions {
  186. "--sysroot=$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm",
  187. "-mthumb",
  188. "-march=armv7-a",
  189. "-mfloat-abi=softfp",
  190. "-mfpu=neon",
  191. "-Wunused-value",
  192. -- "-Wundef", -- note: avoids PhysX warnings
  193. }
  194. linkoptions {
  195. "--sysroot=$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm",
  196. "$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm/usr/lib/crtbegin_so.o",
  197. "$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm/usr/lib/crtend_so.o",
  198. "-march=armv7-a",
  199. "-Wl,--fix-cortex-a8",
  200. }
  201. configuration { "vs*" }
  202. includedirs { CROWN_DIR .. "engine/core/compat/msvc" }
  203. defines {
  204. "WIN32",
  205. "_WIN32",
  206. "_HAS_EXCEPTIONS=0",
  207. "_HAS_ITERATOR_DEBUGGING=0",
  208. "_SCL_SECURE=0",
  209. "_SECURE_SCL=0",
  210. "_SCL_SECURE_NO_WARNINGS",
  211. "_CRT_SECURE_NO_WARNINGS",
  212. "_CRT_SECURE_NO_DEPRECATE",
  213. "NOMINMAX",
  214. }
  215. buildoptions {
  216. "/Oy-", -- Suppresses creation of frame pointers on the call stack.
  217. "/Ob2", -- The Inline Function Expansion
  218. }
  219. linkoptions {
  220. "/ignore:4199", -- LNK4199: /DELAYLOAD:*.dll ignored; no imports found from *.dll
  221. "/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
  222. "/ignore:4099", -- LNK4099: The linker was unable to find your .pdb file.
  223. }
  224. configuration { "x32", "vs*" }
  225. targetdir (build_dir .. "win32" .. "/bin")
  226. objdir (build_dir .. "win32" .. "/obj")
  227. libdirs {
  228. "$(PHYSX_SDK_WINDOWS)/Lib/win32",
  229. "$(DXSDK_DIR)/Lib/x86",
  230. }
  231. configuration { "x64", "vs*" }
  232. targetdir (build_dir .. "win64" .. "/bin")
  233. objdir (build_dir .. "win64" .. "/obj")
  234. libdirs {
  235. "$(PHYSX_SDK_WINDOWS)/Lib/win64",
  236. "$(DXSDK_DIR)/Lib/x64",
  237. }
  238. configuration {} -- reset configuration
  239. end
  240. function strip()
  241. configuration { "android-arm", "release"}
  242. postbuildcommands {
  243. "$(SILENT) echo Stripping symbols",
  244. "$(SILENT) $(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-strip -s \"$(TARGET)\""
  245. }
  246. configuration { "linux-*", "release" }
  247. postbuildcommands {
  248. "$(SILENT) echo Stripping symbols",
  249. "$(SILENT) strip -s \"$(TARGET)\""
  250. }
  251. configuration {} -- reset configuration
  252. end