1
0

premake5.lua 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  1. ---
  2. -- Premake 5.x build configuration script
  3. -- Use this script to configure the project with Premake5.
  4. ---
  5. --
  6. -- Remember my location; I will need it to locate sub-scripts later.
  7. --
  8. local corePath = _SCRIPT_DIR
  9. --
  10. -- Disable deprecation warnings for myself, so that older development
  11. -- versions of Premake can be used to bootstrap new builds.
  12. --
  13. premake.api.deprecations "off"
  14. --
  15. -- Register supporting actions and options.
  16. --
  17. newaction {
  18. trigger = "embed",
  19. description = "Embed scripts in scripts.c; required before release builds",
  20. execute = function ()
  21. include (path.join(corePath, "scripts/embed.lua"))
  22. end
  23. }
  24. newaction {
  25. trigger = "package",
  26. description = "Creates source and binary packages",
  27. execute = function ()
  28. include (path.join(corePath, "scripts/package.lua"))
  29. end
  30. }
  31. newaction {
  32. trigger = "docs-check",
  33. description = "Validates documentation files for Premake APIs",
  34. execute = function ()
  35. include (path.join(corePath, "scripts/docscheck.lua"))
  36. end
  37. }
  38. newaction {
  39. trigger = "test",
  40. description = "Run the automated test suite",
  41. execute = function ()
  42. test = require "self-test"
  43. premake.action.call("self-test")
  44. end
  45. }
  46. newoption {
  47. trigger = "test-all",
  48. description = "Run all unit tests, including slower network and I/O"
  49. }
  50. newoption {
  51. trigger = "test-only",
  52. description = "When testing, run only the specified suite or test"
  53. }
  54. newoption {
  55. trigger = "to",
  56. value = "path",
  57. description = "Set the output location for the generated files"
  58. }
  59. newoption {
  60. trigger = "no-curl",
  61. description = "Disable Curl 3rd party lib"
  62. }
  63. newoption {
  64. trigger = "no-zlib",
  65. description = "Disable Zlib/Zip 3rd party lib"
  66. }
  67. newoption {
  68. trigger = "no-luasocket",
  69. description = "Disable Luasocket 3rd party lib"
  70. }
  71. newoption {
  72. trigger = "bytecode",
  73. description = "Embed scripts as bytecode instead of stripped souce code"
  74. }
  75. newoption {
  76. trigger = "arch",
  77. value = "arch",
  78. description = "Set the architecture of the binary to be built.",
  79. allowed = {
  80. { "ARM", "ARM (On macOS, same as ARM64.)" },
  81. { "ARM64", "ARM64" },
  82. { "x86", "x86 (On macOS, same as x86_64.)" },
  83. { "x86_64", "x86_64" },
  84. { "Universal", "Universal Binary (macOS only)" },
  85. --
  86. { "Win32", "Same as x86" },
  87. { "x64", "Same as x86_64" },
  88. },
  89. default = "x86",
  90. }
  91. --
  92. -- Define the project. Put the release configuration first so it will be the
  93. -- default when folks build using the makefile. That way they don't have to
  94. -- worry about the /scripts argument and all that.
  95. --
  96. -- TODO: Switch to these new APIs once they've had a chance to land everywhere
  97. --
  98. -- defaultConfiguration "Release"
  99. -- symbols "On"
  100. --
  101. solution "Premake5"
  102. configurations { "Release", "Debug" }
  103. location ( _OPTIONS["to"] )
  104. flags { "StaticRuntime", "MultiProcessorCompile" }
  105. warnings "Extra"
  106. if not _OPTIONS["no-zlib"] then
  107. defines { "PREMAKE_COMPRESSION" }
  108. end
  109. if not _OPTIONS["no-curl"] then
  110. defines { "CURL_STATICLIB", "PREMAKE_CURL"}
  111. end
  112. filter { "system:macosx", "options:arch=ARM or arch=ARM64" }
  113. buildoptions { "-arch arm64" }
  114. linkoptions { "-arch arm64" }
  115. filter { "system:macosx", "options:arch=x86 or arch=x86_64 or arch=Win32 or arch=x64" }
  116. buildoptions { "-arch x86_64" }
  117. linkoptions { "-arch x86_64" }
  118. filter { "system:macosx", "options:arch=Universal" }
  119. buildoptions { "-arch arm64", "-arch x86_64" }
  120. linkoptions { "-arch arm64", "-arch x86_64" }
  121. filter { "system:windows", "options:arch=ARM" }
  122. platforms { "ARM" }
  123. filter { "system:windows", "options:arch=ARM64" }
  124. platforms { "ARM64" }
  125. filter { "system:windows", "options:arch=x86 or arch=Win32" }
  126. platforms { "Win32" }
  127. filter { "system:windows", "options:arch=x86_64 or arch=x64" }
  128. platforms { "x64" }
  129. filter "configurations:Debug"
  130. defines "_DEBUG"
  131. flags { "Symbols" }
  132. filter "configurations:Release"
  133. defines "NDEBUG"
  134. optimize "Full"
  135. flags { "NoBufferSecurityCheck", "NoRuntimeChecks" }
  136. filter "action:vs*"
  137. defines { "_CRT_SECURE_NO_DEPRECATE", "_CRT_SECURE_NO_WARNINGS", "_CRT_NONSTDC_NO_WARNINGS" }
  138. filter { "system:windows", "configurations:Release" }
  139. flags { "NoIncrementalLink" }
  140. -- MinGW AR does not handle LTO out of the box and need a plugin to be setup
  141. filter { "system:windows", "configurations:Release", "toolset:not mingw" }
  142. flags { "LinkTimeOptimization" }
  143. project "Premake5"
  144. targetname "premake5"
  145. language "C"
  146. kind "ConsoleApp"
  147. includedirs { "contrib/lua/src", "contrib/luashim" }
  148. links { "lua-lib" }
  149. -- optional 3rd party libraries
  150. if not _OPTIONS["no-zlib"] then
  151. includedirs { "contrib/zlib", "contrib/libzip" }
  152. links { "zip-lib", "zlib-lib" }
  153. end
  154. if not _OPTIONS["no-curl"] then
  155. includedirs { "contrib/curl/include" }
  156. links { "curl-lib" }
  157. end
  158. files
  159. {
  160. "*.txt", "**.lua",
  161. "src/**.h", "src/**.c",
  162. "modules/**"
  163. }
  164. excludes
  165. {
  166. "contrib/**.*",
  167. "binmodules/**.*"
  168. }
  169. filter "configurations:Debug"
  170. targetdir "bin/debug"
  171. debugargs { "--scripts=%{prj.location}/%{path.getrelative(prj.location, prj.basedir)}", "test" }
  172. debugdir "."
  173. filter "configurations:Release"
  174. targetdir "bin/release"
  175. filter "system:windows"
  176. links { "ole32", "ws2_32", "advapi32", "version" }
  177. files { "src/**.rc" }
  178. filter "toolset:mingw"
  179. links { "crypt32" }
  180. filter "system:linux or bsd or hurd"
  181. defines { "LUA_USE_POSIX", "LUA_USE_DLOPEN" }
  182. links { "m" }
  183. linkoptions { "-rdynamic" }
  184. filter "system:linux or hurd"
  185. links { "dl", "rt" }
  186. filter { "system:not windows", "system:not macosx" }
  187. if not _OPTIONS["no-curl"] then
  188. links { "mbedtls-lib" }
  189. end
  190. filter "system:macosx"
  191. defines { "LUA_USE_MACOSX" }
  192. links { "CoreServices.framework", "Foundation.framework", "Security.framework", "readline" }
  193. filter { "system:macosx", "action:gmake" }
  194. toolset "clang"
  195. filter { "system:solaris" }
  196. links { "m", "socket", "nsl" }
  197. filter "system:aix"
  198. defines { "LUA_USE_POSIX", "LUA_USE_DLOPEN" }
  199. links { "m" }
  200. filter "system:haiku"
  201. defines { "LUA_USE_POSIX", "LUA_USE_DLOPEN", "_BSD_SOURCE" }
  202. links { "network", "bsd" }
  203. -- optional 3rd party libraries
  204. group "contrib"
  205. include "contrib/lua"
  206. include "contrib/luashim"
  207. if not _OPTIONS["no-zlib"] then
  208. include "contrib/zlib"
  209. include "contrib/libzip"
  210. end
  211. if not _OPTIONS["no-curl"] then
  212. include "contrib/mbedtls"
  213. include "contrib/curl"
  214. end
  215. group "Binary Modules"
  216. include "binmodules/example"
  217. if not _OPTIONS["no-luasocket"] then
  218. include "binmodules/luasocket"
  219. end
  220. --
  221. -- A more thorough cleanup.
  222. --
  223. if _ACTION == "clean" then
  224. os.rmdir("bin")
  225. os.rmdir("build")
  226. end