xmake.lua 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package("freeimage")
  2. set_homepage("https://sourceforge.net/projects/freeimage/")
  3. set_description("FreeImage is a library project for developers who would like to support popular graphics image formats (PNG, JPEG, TIFF, BMP and others).")
  4. add_urls("https://sourceforge.net/projects/freeimage/files/Source%20Distribution/$(version).zip", {version = function (version)
  5. return version .. "/FreeImage" .. version:gsub("%.", "")
  6. end})
  7. add_versions("3.18.0", "f41379682f9ada94ea7b34fe86bf9ee00935a3147be41b6569c9605a53e438fd")
  8. add_patches("3.18.0", path.join(os.scriptdir(), "patches", "3.18.0", "libjxr.patch"), "fddbb9fa736da383f54352dc0ab848d083d9279b66cc6ac53910236144ad75ab")
  9. add_patches("3.18.0", path.join(os.scriptdir(), "patches", "3.18.0", "openexr.patch"), "051940ec58fd5ae85b65c67b83fd46eda807c9039f0f5207769ac871350af830")
  10. add_patches("3.18.0", path.join(os.scriptdir(), "patches", "3.18.0", "pluginbmp.patch"), "2029f95478c8ce77f83671fe8e1889c11caa04eef2584abf0cd0a9f6a7047db0")
  11. add_configs("rgb", {description = "Use RGB instead of BGR.", default = false})
  12. if is_plat("macosx") then
  13. add_deps("libpng")
  14. end
  15. on_load("windows", function (package)
  16. if not package:config("shared") then
  17. package:add("defines", "FREEIMAGE_LIB")
  18. end
  19. end)
  20. on_install("windows|x64", "windows|x86", "macosx", "linux", function (package)
  21. if package:is_plat("windows") and package:is_arch("x86") then
  22. local vs = import("core.tool.toolchain").load("msvc"):config("vs")
  23. if tonumber(vs) < 2019 then
  24. raise("Your compiler is too old to use this library.")
  25. end
  26. end
  27. local sources, includes
  28. local content = io.readfile("Makefile.srcs")
  29. sources = content:match("SRCS = (.-)\n"):split(" ")
  30. includes = content:match("INCLUDE = (.-)\n"):gsub("%-I", ""):split(" ")
  31. local rgb_type = package:config("rgb") and "FREEIMAGE_COLORORDER=1" or "FREEIMAGE_COLORORDER=0"
  32. io.writefile("xmake.lua", format([[
  33. add_rules("mode.debug", "mode.release")
  34. includes("check_cincludes.lua")
  35. if is_plat("macosx") then
  36. add_requires("libpng")
  37. end
  38. target("freeimage")
  39. set_kind("$(kind)")
  40. set_languages("c++11")
  41. if is_plat("macosx") then
  42. add_packages("libpng")
  43. end
  44. add_files({"%s"})
  45. add_headerfiles("Source/FreeImage.h", "Source/FreeImageIO.h")
  46. set_symbols("hidden")
  47. add_includedirs({"%s"})
  48. check_cincludes("Z_HAVE_UNISTD_H", "unistd.h")
  49. add_defines("OPJ_STATIC", "NO_LCMS", "LIBRAW_NODLL", "DISABLE_PERF_MEASUREMENT", "]] .. rgb_type .. [[")
  50. if is_plat("windows") then
  51. add_files("FreeImage.rc")
  52. add_defines("WIN32", "_CRT_SECURE_NO_DEPRECATE")
  53. add_defines(is_kind("static") and "FREEIMAGE_LIB" or "FREEIMAGE_EXPORTS")
  54. else
  55. add_defines("__ANSI__")
  56. end
  57. ]], table.concat(sources, "\",\""), table.concat(includes, "\", \"")))
  58. import("package.tools.xmake").install(package)
  59. end)
  60. on_test(function (package)
  61. assert(package:has_cfuncs("FreeImage_Initialise", {includes = "FreeImage.h"}))
  62. end)