xmake.lua 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package("igraph")
  2. set_homepage("https://igraph.org")
  3. set_description("Library for the analysis of networks")
  4. set_license("GPL-2.0")
  5. add_urls("https://github.com/igraph/igraph/releases/download/$(version)/igraph-$(version).tar.gz",
  6. "https://github.com/igraph/igraph.git")
  7. add_versions("0.10.15", "03ba01db0544c4e32e51ab66f2356a034394533f61b4e14d769b9bbf5ad5e52c")
  8. add_configs("glpk", {description = "Compile igraph with GLPK support", default = false, type = "boolean"})
  9. add_configs("graphml", {description = "Compile igraph with GraphML support", default = false, type = "boolean"})
  10. add_configs("openmp", {description = "Use OpenMP for parallelization", default = false, type = "boolean"})
  11. if is_plat("wasm") then
  12. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  13. end
  14. if is_plat("linux", "bsd") then
  15. add_syslinks("pthread")
  16. end
  17. add_deps("cmake")
  18. add_deps("plfit")
  19. on_check(function (package)
  20. if package:is_cross() then
  21. if not package:is_plat("windows", "macosx") then
  22. raise("package(igraph) unsupported cross-compilation now. To support it, see https://igraph.org/c/html/latest/igraph-Installation.html#igraph-Installation-cross-compiling")
  23. end
  24. end
  25. end)
  26. on_load(function (package)
  27. if package:gitref() then
  28. wprint("If build failed with flex/bison, please see https://github.com/igraph/igraph/issues/2713")
  29. package:add("deps", "flex", "bison", {kind = "binary"})
  30. end
  31. -- TODO: unbundle deps gmp, arpack, blas, lapack
  32. -- https://igraph.org/c/html/latest/igraph-Installation.html#igraph-Installation-prerequisites
  33. if package:is_plat("linux", "macosx") then
  34. package:add("deps", "gmp")
  35. end
  36. if package:config("glpk") then
  37. package:add("deps", "glpk")
  38. end
  39. if package:config("graphml") then
  40. package:add("deps", "libxml2")
  41. end
  42. if package:config("openmp") then
  43. package:add("deps", "openmp")
  44. end
  45. if not package:config("shared") then
  46. package:add("defines", "IGRAPH_STATIC")
  47. end
  48. end)
  49. on_install("!cross and !bsd", function (package)
  50. -- Disable test/doc/cpack
  51. io.replace("CMakeLists.txt", "CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME", "0", {plain = true})
  52. if package:config("graphml") then
  53. io.replace("etc/cmake/dependencies.cmake", "find_package(LibXml2 ${LIBXML2_VERSION_MIN} QUIET)", "find_package(LibXml2 CONFIG REQUIRED)", {plain = true})
  54. end
  55. if package:gitref() then
  56. io.writefile("IGRAPH_VERSION", package:version_str())
  57. end
  58. -- https://igraph.org/c/html/latest/igraph-Installation.html
  59. local configs = {
  60. "-DUSE_CCACHE=OFF",
  61. "-DIGRAPH_WARNINGS_AS_ERRORS=OFF",
  62. -- "-DIGRAPH_USE_INTERNAL_GMP=OFF",
  63. -- "-DIGRAPH_USE_INTERNAL_ARPACK=OFF",
  64. -- "-DIGRAPH_USE_INTERNAL_BLAS=OFF",
  65. -- "-DIGRAPH_USE_INTERNAL_LAPACK=OFF",
  66. "-DIGRAPH_USE_INTERNAL_GLPK=OFF",
  67. "-DIGRAPH_USE_INTERNAL_PLFIT=OFF",
  68. }
  69. if package:is_plat("linux", "macosx") then
  70. table.insert(configs, "-DIGRAPH_USE_INTERNAL_GMP=OFF")
  71. end
  72. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  73. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  74. table.insert(configs, "-DIGRAPH_ENABLE_LTO=" .. (package:config("lto") and "ON" or "OFF"))
  75. table.insert(configs, "-DIGRAPH_GLPK_SUPPORT=" .. (package:config("glpk") and "ON" or "OFF"))
  76. table.insert(configs, "-DIGRAPH_OPENMP_SUPPORT=" .. (package:config("openmp") and "ON" or "OFF"))
  77. -- AUTO -> find_package, ON -> find_dependency (unavailable)
  78. table.insert(configs, "-DIGRAPH_GRAPHML_SUPPORT=" .. (package:config("graphml") and "AUTO" or "OFF"))
  79. if package:is_cross() then
  80. -- from https://github.com/microsoft/vcpkg/tree/0857a4b08c14030bbe41e80accb2b1fddb047a74/ports/igraph
  81. local header
  82. if package:is_plat("macosx") then
  83. header = "arith_osx.h"
  84. elseif package:is_plat("windows") then
  85. if package:is_arch64() then
  86. header = "arith_win64.h"
  87. else
  88. header = "arith_win32.h"
  89. end
  90. end
  91. if header then
  92. local header_path = path.unix(path.join(os.scriptdir(), header))
  93. table.insert(configs, "-DF2C_EXTERNAL_ARITH_HEADER=" .. header_path)
  94. end
  95. end
  96. local opt = {}
  97. if package:config("glpk") then
  98. opt.packagedeps = "zlib"
  99. end
  100. import("package.tools.cmake").install(package, configs, opt)
  101. end)
  102. on_test(function (package)
  103. assert(package:has_cfuncs("igraph_rng_seed", {includes = "igraph/igraph.h"}))
  104. end)