xmake.lua 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package("nifti")
  2. set_homepage("https://github.com/NIFTI-Imaging/nifti_clib")
  3. set_description("C libraries for NIFTI support")
  4. add_urls("https://github.com/NIFTI-Imaging/nifti_clib.git")
  5. add_versions("2024.01.25", "f24bec503f1a5d501c0413c1bb8aa3d6e04aebda")
  6. add_configs("nifti2", {description = "Build nifti2.", default = false, type = "boolean"})
  7. add_configs("cifti", {description = "Build cifti.", default = false, type = "boolean"})
  8. add_configs("fslio", {description = "Build fslio.", default = false, type = "boolean"})
  9. add_configs("tools", {description = "Build tools.", default = false, type = "boolean"})
  10. add_deps("cmake")
  11. add_deps("zlib")
  12. on_load(function (package)
  13. if package:config("cifti") then
  14. package:add("deps", "expat")
  15. end
  16. end)
  17. on_install("!cross and !wasm", function (package)
  18. local configs = {
  19. "-DBUILD_TESTING=OFF",
  20. "-DNIFTI_INSTALL_NO_DOCS=ON",
  21. "-DNIFTI_INSTALL_LIBRARY_DIR=" .. path.unix(package:installdir("lib"))
  22. }
  23. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  24. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  25. if package:config("shared") and package:is_plat("windows") then
  26. table.insert(configs, "-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON")
  27. io.replace("nifticdf/nifticdf.h", "extern char const * const inam[];", "__declspec(dllimport) char const * const inam[];", {plain = true})
  28. end
  29. table.insert(configs, "-DUSE_NIFTI2_CODE=" .. (package:config("nifti2") and "ON" or "OFF"))
  30. table.insert(configs, "-DUSE_CIFTI_CODE=" .. (package:config("cifti") and "ON" or "OFF"))
  31. table.insert(configs, "-DUSE_FSL_CODE=" .. (package:config("fslio") and "ON" or "OFF"))
  32. table.insert(configs, "-DNIFTI_BUILD_APPLICATIONS=" .. (package:config("tools") and "ON" or "OFF"))
  33. local cxflags
  34. if package:config("cifti") then
  35. cxflags = "-DXML_STATIC"
  36. end
  37. import("package.tools.cmake").install(package, configs, {cxflags = cxflags, packagedeps = "zlib"})
  38. if package:config("tools") then
  39. package:addenv("PATH", "bin")
  40. end
  41. end)
  42. on_test(function (package)
  43. assert(package:has_cfuncs("nifti_stat2cdf", {includes = "nifti/nifticdf.h"}))
  44. end)