xmake.lua 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. on_load("windows", function (package)
  11. if not package:config("shared") then
  12. package:add("defines", "FREEIMAGE_LIB")
  13. end
  14. end)
  15. on_install("windows|x64", "windows|x86", "macosx", "linux", function (package)
  16. if package:is_plat("windows") and package:is_arch("x86") then
  17. local vs = import("core.tool.toolchain").load("msvc"):config("vs")
  18. if tonumber(vs) < 2019 then
  19. raise("Your compiler is too old to use this library.")
  20. end
  21. end
  22. local sources, includes
  23. local content = io.readfile("Makefile.srcs")
  24. sources = content:match("SRCS = (.-)\n"):split(" ")
  25. includes = content:match("INCLUDE = (.-)\n"):gsub("%-I", ""):split(" ")
  26. io.writefile("xmake.lua", format([[
  27. add_rules("mode.debug", "mode.release")
  28. includes("check_cincludes.lua")
  29. target("freeimage")
  30. set_kind("$(kind)")
  31. set_languages("c++11")
  32. add_files({"%s"})
  33. add_headerfiles("Source/FreeImage.h", "Source/FreeImageIO.h")
  34. set_symbols("hidden")
  35. add_includedirs({"%s"})
  36. check_cincludes("Z_HAVE_UNISTD_H", "unistd.h")
  37. add_defines("OPJ_STATIC", "NO_LCMS", "LIBRAW_NODLL", "DISABLE_PERF_MEASUREMENT")
  38. if is_plat("windows") then
  39. add_files("FreeImage.rc")
  40. add_defines("WIN32", "_CRT_SECURE_NO_DEPRECATE")
  41. add_defines(is_kind("static") and "FREEIMAGE_LIB" or "FREEIMAGE_EXPORTS")
  42. else
  43. add_defines("__ANSI__")
  44. end
  45. ]], table.concat(sources, "\",\""), table.concat(includes, "\", \"")))
  46. import("package.tools.xmake").install(package)
  47. end)
  48. on_test(function (package)
  49. assert(package:has_cfuncs("FreeImage_Initialise", {includes = "FreeImage.h"}))
  50. end)