xmake.lua 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. package("magnum")
  2. set_homepage("https://magnum.graphics/")
  3. set_description("Lightweight and modular C++11/C++14 graphics middleware for games and data visualization.")
  4. set_license("MIT")
  5. add_urls("https://github.com/mosra/magnum/archive/refs/tags/$(version).zip",
  6. "https://github.com/mosra/magnum.git")
  7. add_versions("v2020.06", "78c52bc403cec27b98d8d87186622ca57f8d70ffd64342fe4094c720b7d3b0e3")
  8. add_patches("2020.06", "patches/2020.06/msvc.patch", "0739a29807c6aeb4681eaadb4c624c39f5d1ba746de3df7ab83801f41d1ad5bd")
  9. add_configs("audio", {description = "Build Audio library.", default = false, type = "boolean"})
  10. add_configs("meshtools", {description = "Build MeshTools library.", default = true, type = "boolean"})
  11. add_configs("opengl", {description = "Build GL library.", default = true, type = "boolean"})
  12. add_configs("vulkan", {description = "Build Vk library.", default = false, type = "boolean"})
  13. add_configs("deprecated", {description = "Include deprecated APIs in the build.", default = true, type = "boolean"})
  14. add_configs("plugin_static", {description = "Build plugins as static libraries.", default = false, type = "boolean"})
  15. local applicationlibs = {"android", "emscripten", "glfw", "glx", "sdl2", "xegl", "windowlesscgl", "windowlessegl", "windowlessglx", "windowlessios", "windowlesswgl", "windowlesswindowsegl"}
  16. for _, applicationlib in ipairs(applicationlibs) do
  17. add_configs(applicationlib, {description = "Build the " .. applicationlib .. " application library.", default = false, type = "boolean"})
  18. end
  19. local contexts = {"cgl", "egl", "glx", "wgl"}
  20. for _, context in ipairs(contexts) do
  21. add_configs(context .. "context", {description = "Build the " .. context .. " context handling library.", default = false, type = "boolean"})
  22. end
  23. local testers = {"opengltester", "vulkantester"}
  24. for _, tester in ipairs(testers) do
  25. add_configs(tester, {description = "Build the " .. tester .. " class.", default = false, type = "boolean"})
  26. end
  27. local plugins = {"anyaudioimporter", "anyimageconverter", "anyimageimporter", "anysceneconverter", "anysceneimporter", "anyshaderconverter", "magnumfont", "magnumfontconverter", "objimporter", "tgaimporter", "tgaimageconverter", "wavaudioimporter"}
  28. for _, plugin in ipairs(plugins) do
  29. add_configs(plugin, {description = "Build the " .. plugin .. " plugin.", default = false, type = "boolean"})
  30. end
  31. local utilities = {"gl_info", "vk_info", "al_info", "distancefieldconverter", "fontconverter", "imageconverter", "sceneconverter", "shaderconverter"}
  32. for _, utility in ipairs(utilities) do
  33. add_configs(utility, {description = "Build the " .. utility .. " executable.", default = false, type = "boolean"})
  34. end
  35. add_deps("cmake", "corrade")
  36. on_load("windows", "linux", "macosx", function (package)
  37. if package:config("audio") then
  38. package:add("deps", "openal-soft", {configs = {shared = true}})
  39. end
  40. if package:config("opengl") then
  41. package:add("deps", "opengl")
  42. end
  43. if package:config("vulkan") then
  44. package:add("deps", "vulkansdk")
  45. end
  46. if package:config("glfw") then
  47. package:add("deps", "glfw")
  48. end
  49. if package:config("sdl2") then
  50. package:add("deps", "libsdl", {configs = {sdlmain = false}})
  51. end
  52. if package:config("glx") then
  53. package:add("deps", "libx11")
  54. end
  55. local links = {"MagnumAnyAudioImporter", "MagnumAnyImageConverter", "MagnumAnyImageImporter", "MagnumAnySceneConverter", "MagnumAnySceneImporter", "MagnumMagnumFont", "MagnumMagnumFontConverter", "MagnumObjImporter", "MagnumTgaImageConverter", "MagnumTgaImporter", "MagnumWavAudioImporter"}
  56. table.join2(links, {"MagnumCglContext", "MagnumEglContext", "MagnumGlxContext", "MagnumWglContext", "MagnumOpenGLTester", "MagnumVulkanTester"})
  57. table.join2(links, {"MagnumAndroidApplication", "MagnumEmscriptenApplication", "MagnumGlfwApplication", "MagnumGlxApplication", "MagnumSdl2Application", "MagnumXEglApplication", "MagnumWindowlessCglApplication", "MagnumWindowlessEglApplication", "MagnumWindowlessGlxApplication", "MagnumWindowlessIosApplication", "MagnumWindowlessWglApplication", "MagnumWindowlessWindowsEglApplication"})
  58. table.join2(links, {"MagnumAudio", "MagnumDebugTools", "MagnumGL", "MagnumMeshTools", "MagnumPrimitives", "MagnumSceneGraph", "MagnumShaders", "MagnumText", "MagnumTextureTools", "MagnumTrade", "MagnumVk", "Magnum"})
  59. local postfix = package:debug() and "-d" or ""
  60. for _, link in ipairs(links) do
  61. package:add("links", link .. postfix)
  62. end
  63. end)
  64. on_install("windows", "linux", "macosx", function (package)
  65. io.replace("modules/FindSDL2.cmake", "SDL2-2.0 SDL2", "SDL2-2.0 SDL2 SDL2-static", {plain = true})
  66. io.replace("modules/FindSDL2.cmake", "${_SDL2_LIBRARY_PATH_SUFFIX}", "lib ${_SDL2_LIBRARY_PATH_SUFFIX}", {plain = true})
  67. local configs = {"-DBUILD_TESTS=OFF", "-DLIB_SUFFIX="}
  68. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  69. table.insert(configs, "-DBUILD_STATIC=" .. (package:config("shared") and "OFF" or "ON"))
  70. table.insert(configs, "-DWITH_AUDIO=" .. (package:config("audio") and "ON" or "OFF"))
  71. table.insert(configs, "-DWITH_MESHTOOLS=" .. (package:config("meshtools") and "ON" or "OFF"))
  72. table.insert(configs, "-DWITH_GL=" .. (package:config("opengl") and "ON" or "OFF"))
  73. table.insert(configs, "-DWITH_VK=" .. (package:config("vulkan") and "ON" or "OFF"))
  74. table.insert(configs, "-DBUILD_DEPRECATED=" .. (package:config("deprecated") and "ON" or "OFF"))
  75. table.insert(configs, "-DBUILD_PLUGIN_STATIC=" .. (package:config("plugin_static") and "ON" or "OFF"))
  76. for _, applicationlib in ipairs(applicationlibs) do
  77. table.insert(configs, "-DWITH_" .. applicationlib:upper() .. "APPLICATION=" .. (package:config(applicationlib) and "ON" or "OFF"))
  78. end
  79. for _, context in ipairs(contexts) do
  80. table.insert(configs, "-DWITH_" .. context:upper() .. "CONTEXT=" .. (package:config(context) and "ON" or "OFF"))
  81. end
  82. for _, tester in ipairs(testers) do
  83. table.insert(configs, "-DWITH_" .. tester:upper() .. "=" .. (package:config(tester) and "ON" or "OFF"))
  84. end
  85. for _, plugin in ipairs(plugins) do
  86. table.insert(configs, "-DWITH_" .. plugin:upper() .. "=" .. (package:config(plugin) and "ON" or "OFF"))
  87. end
  88. for _, utility in ipairs(utilities) do
  89. table.insert(configs, "-DWITH_" .. utility:upper() .. "=" .. (package:config(utility) and "ON" or "OFF"))
  90. end
  91. import("package.tools.cmake").install(package, configs, {buildir = os.tmpfile() .. ".dir"})
  92. end)
  93. on_test(function (package)
  94. assert(package:check_cxxsnippets({test = [[
  95. #include <Magnum/GL/Buffer.h>
  96. #include <Magnum/Math/Color.h>
  97. using namespace Magnum;
  98. struct TriangleVertex {
  99. Vector2 position;
  100. Color3 color;
  101. };
  102. void test() {
  103. using namespace Math::Literals;
  104. const TriangleVertex data[]{
  105. {{-0.5f, -0.5f}, 0xff0000_rgbf},
  106. {{ 0.5f, -0.5f}, 0x00ff00_rgbf},
  107. {{ 0.0f, 0.5f}, 0x0000ff_rgbf}
  108. };
  109. GL::Buffer buffer;
  110. buffer.setData(data);
  111. }
  112. ]]}, {configs = {languages = "c++14"}}))
  113. end)