xmake.lua 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package("cminpack")
  2. set_homepage("https://devernay.github.io/cminpack/")
  3. set_description("A C/C++ rewrite of the MINPACK software (originally in FORTRAN) for solving nonlinear equations and nonlinear least squares problems")
  4. add_urls("https://github.com/devernay/cminpack/archive/refs/tags/$(version).tar.gz",
  5. "https://github.com/devernay/cminpack.git")
  6. add_versions("v1.3.11", "45675fac0a721a1c7600a91a9842fe1ab313069db163538f2923eaeddb0f46de")
  7. add_versions("v1.3.9", "aa37bac5b5caaa4f5805ea5c4240e3834c993672f6dab0b17190ee645e251c9f")
  8. local support_openblas = is_plat("linux", "macosx") or (is_plat("windows") and is_arch("x86", "x64"))
  9. add_configs("blas", {description = "BLAS library to compile with.", default = (support_openblas and "openblas" or nil), type = "string", values = {"openblas", "mkl", "apple"}})
  10. add_configs("long_double", {description = "Enable extended precision.", default = false, type = "boolean"})
  11. if is_plat("linux") then
  12. add_syslinks("m")
  13. end
  14. add_includedirs("include/cminpack-1")
  15. add_deps("cmake")
  16. on_load(function (package)
  17. if package:config("blas") and not package:config("long_double") then
  18. package:add("deps", package:config("blas"))
  19. end
  20. end)
  21. on_install("windows", "linux", "macosx", "mingw", "msys", "android", "iphoneos", "wasm", function (package)
  22. if package:is_plat("windows", "mingw") and (not package:config("shared")) then
  23. package:add("defines", "CMINPACK_NO_DLL")
  24. end
  25. if not package:config("long_double") then
  26. io.replace("CMakeLists.txt", "${SIZEOF_LONG_DOUBLE} GREATER ${SIZEOF_DOUBLE}", "FALSE", {plain = true})
  27. end
  28. local has_blas = package:config("blas") and not package:config("long_double")
  29. local configs = {"-DBUILD_EXAMPLES=OFF", "-DENABLE_TESTING=OFF"}
  30. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  31. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  32. table.insert(configs, "-DUSE_BLAS=" .. (has_blas and "ON" or "OFF"))
  33. if has_blas then
  34. local bla_vendor = {mkl = "Intel10_64lp", openblas = "OpenBLAS", apple = "Apple"}
  35. table.insert(configs, "-DBLA_VENDOR=" .. bla_vendor[package:config("blas")])
  36. if package:dep(package:config("blas")) then
  37. local bla_static = not package:dep(package:config("blas")):config("shared")
  38. table.insert(configs, "-DBLA_STATIC=" .. (bla_static and "ON" or "OFF"))
  39. end
  40. end
  41. import("package.tools.cmake").install(package, configs)
  42. end)
  43. on_test(function (package)
  44. assert(package:has_cfuncs("lmdif", {includes = "minpack.h"}))
  45. end)