toolchain.lua 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  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. "$(PHYSX_SDK_LINUX)/Bin/linux32",
  102. }
  103. buildoptions {
  104. "-m32",
  105. "-malign-double", -- Required by PhysX
  106. }
  107. configuration { "x64", "linux-*" }
  108. targetdir (build_dir .. "linux64" .. "/bin")
  109. objdir (build_dir .. "linux64" .. "/obj")
  110. libdirs {
  111. lib_dir .. "../.build/linux64/bin",
  112. "$(PHYSX_SDK_LINUX)/Lib/linux64",
  113. "$(PHYSX_SDK_LINUX)/Bin/linux64",
  114. }
  115. buildoptions {
  116. "-m64",
  117. }
  118. configuration { "linux-*" }
  119. buildoptions {
  120. "-Wall",
  121. "-Wextra",
  122. "-msse2",
  123. -- "-Werror",
  124. -- "-pedantic",
  125. "-Wno-unknown-pragmas",
  126. "-Wno-unused-local-typedefs",
  127. }
  128. buildoptions_cpp {
  129. "-std=c++03",
  130. }
  131. linkoptions {
  132. "-Wl,-rpath=\\$$ORIGIN",
  133. "-Wl,--no-as-needed",
  134. }
  135. configuration { "android-*" }
  136. flags {
  137. "NoImportLib"
  138. }
  139. includedirs {
  140. "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.8/include",
  141. "$(ANDROID_NDK_ROOT)/sources/android/native_app_glue",
  142. }
  143. linkoptions {
  144. "-nostdlib",
  145. "-static-libgcc",
  146. }
  147. links {
  148. "c",
  149. "dl",
  150. "m",
  151. "android",
  152. "log",
  153. "gnustl_static",
  154. "gcc",
  155. }
  156. buildoptions {
  157. "-fPIC",
  158. "-no-canonical-prefixes",
  159. "-Wa,--noexecstack",
  160. "-fstack-protector",
  161. "-ffunction-sections",
  162. "-Wno-psabi", -- note: the mangling of 'va_list' has changed in GCC 4.4.0
  163. "-Wunused-value",
  164. -- "-Wundef", -- note: avoids PhysX warnings
  165. }
  166. buildoptions_cpp {
  167. "-std=c++03",
  168. }
  169. linkoptions {
  170. "-no-canonical-prefixes",
  171. "-Wl,--no-undefined",
  172. "-Wl,-z,noexecstack",
  173. "-Wl,-z,relro",
  174. "-Wl,-z,now",
  175. }
  176. configuration { "android-arm" }
  177. targetdir (build_dir .. "android-arm" .. "/bin")
  178. objdir (build_dir .. "android-arm" .. "/obj")
  179. libdirs {
  180. lib_dir .. "../.build/android-arm/bin",
  181. "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a",
  182. "$(PHYSX_SDK_ANDROID)/Lib/android9_neon",
  183. }
  184. includedirs {
  185. "$(ANDROID_NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/include",
  186. }
  187. buildoptions {
  188. "--sysroot=$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm",
  189. "-mthumb",
  190. "-march=armv7-a",
  191. "-mfloat-abi=softfp",
  192. "-mfpu=neon",
  193. "-Wunused-value",
  194. -- "-Wundef", -- note: avoids PhysX warnings
  195. }
  196. linkoptions {
  197. "--sysroot=$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm",
  198. "$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm/usr/lib/crtbegin_so.o",
  199. "$(ANDROID_NDK_ROOT)/platforms/android-14/arch-arm/usr/lib/crtend_so.o",
  200. "-march=armv7-a",
  201. "-Wl,--fix-cortex-a8",
  202. }
  203. configuration { "vs*" }
  204. includedirs { CROWN_DIR .. "src/core/compat/msvc" }
  205. defines {
  206. "WIN32",
  207. "_WIN32",
  208. "_HAS_EXCEPTIONS=0",
  209. "_HAS_ITERATOR_DEBUGGING=0",
  210. "_SCL_SECURE=0",
  211. "_SECURE_SCL=0",
  212. "_SCL_SECURE_NO_WARNINGS",
  213. "_CRT_SECURE_NO_WARNINGS",
  214. "_CRT_SECURE_NO_DEPRECATE",
  215. "NOMINMAX",
  216. }
  217. buildoptions {
  218. "/Oy-", -- Suppresses creation of frame pointers on the call stack.
  219. "/Ob2", -- The Inline Function Expansion
  220. }
  221. linkoptions {
  222. "/ignore:4199", -- LNK4199: /DELAYLOAD:*.dll ignored; no imports found from *.dll
  223. "/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
  224. "/ignore:4099", -- LNK4099: The linker was unable to find your .pdb file.
  225. }
  226. configuration { "x32", "vs*" }
  227. targetdir (build_dir .. "win32" .. "/bin")
  228. objdir (build_dir .. "win32" .. "/obj")
  229. libdirs {
  230. "$(PHYSX_SDK_WINDOWS)/Lib/win32",
  231. "$(DXSDK_DIR)/Lib/x86",
  232. }
  233. configuration { "x64", "vs*" }
  234. targetdir (build_dir .. "win64" .. "/bin")
  235. objdir (build_dir .. "win64" .. "/obj")
  236. libdirs {
  237. "$(PHYSX_SDK_WINDOWS)/Lib/win64",
  238. "$(DXSDK_DIR)/Lib/x64",
  239. }
  240. configuration {} -- reset configuration
  241. end
  242. function strip()
  243. configuration { "android-arm", "release"}
  244. postbuildcommands {
  245. "$(SILENT) echo Stripping symbols",
  246. "$(SILENT) $(ANDROID_NDK_ARM)/bin/arm-linux-androideabi-strip -s \"$(TARGET)\""
  247. }
  248. configuration { "linux-*", "release" }
  249. postbuildcommands {
  250. "$(SILENT) echo Stripping symbols",
  251. "$(SILENT) strip -s \"$(TARGET)\""
  252. }
  253. configuration {} -- reset configuration
  254. end