xmake.lua 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. package("dlib")
  2. set_homepage("https://dlib.net")
  3. set_description("A toolkit for making real world machine learning and data analysis applications in C++")
  4. set_license("Boost")
  5. add_urls("https://github.com/davisking/dlib/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/davisking/dlib.git")
  7. add_versions("v19.24.4", "d881911d68972d11563bb9db692b8fcea0ac1b3fd2e3f03fa0b94fde6c739e43")
  8. add_versions("v19.22", "5f44b67f762691b92f3e41dcf9c95dd0f4525b59cacb478094e511fdacb5c096")
  9. add_configs("png", {description = "Enable png", default = false, type = "boolean"})
  10. add_configs("jpg", {description = "Enable jpg", default = false, type = "boolean"})
  11. add_configs("gif", {description = "Enable gif", default = false, type = "boolean"})
  12. add_configs("sqlite3", {description = "Enable sqlite3", default = false, type = "boolean"})
  13. add_configs("blas", {description = "Enable blas", default = false, type = "boolean"})
  14. add_configs("mkl", {description = "Enable mkl", default = false, type = "boolean"})
  15. add_configs("jxl", {description = "Enable jpeg xl", default = false, type = "boolean"})
  16. add_configs("ffmpeg", {description = "Enable ffmpeg", default = false, type = "boolean"})
  17. add_configs("webp", {description = "Enable webp", default = false, type = "boolean"})
  18. add_configs("simd", {description = "SIMD acceleration architecture.", type = "string", values = {"sse2", "sse4", "avx", "neon"}})
  19. if is_plat("linux", "bsd") then
  20. add_syslinks("pthread")
  21. end
  22. add_deps("cmake")
  23. on_load(function (package)
  24. if package:config("png") then
  25. package:add("deps", "libpng")
  26. end
  27. if package:config("png") then
  28. package:add("deps", "libjpeg")
  29. end
  30. if package:config("gif") then
  31. package:add("deps", "giflib")
  32. end
  33. if package:config("sqlite3") then
  34. package:add("deps", "sqlite3")
  35. end
  36. if package:config("blas") then
  37. package:add("deps", "openblas")
  38. end
  39. if package:config("mkl") then
  40. package:add("deps", "mkl")
  41. end
  42. if package:config("jxl") then
  43. package:add("deps", "libjxl")
  44. end
  45. if package:config("ffmpeg") then
  46. package:add("deps", "ffmpeg")
  47. end
  48. if package:version():ge("19.24") and package:config("webp") then
  49. package:add("deps", "libwebp")
  50. end
  51. end)
  52. on_install(function (package)
  53. local configs = {
  54. "-DDLIB_IN_PROJECT_BUILD=OFF",
  55. "-DDLIB_ISO_CPP_ONLY=OFF",
  56. "-DDLIB_NO_GUI_SUPPORT=ON"
  57. }
  58. if package:is_plat("windows") then
  59. if package:is_debug() then
  60. table.insert(configs, "-DCMAKE_COMPILE_PDB_OUTPUT_DIRECTORY=''")
  61. end
  62. if package:config("shared") then
  63. table.insert(configs, "-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON")
  64. io.replace("dlib/CMakeLists.txt", [[message(FATAL_ERROR "Building dlib as a standalone dll is not supported when using Visual Studio. You are highly encouraged to use static linking instead. See https://github.com/davisking/dlib/issues/1483 for a discussion.")]], "", {plain = true})
  65. end
  66. end
  67. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  68. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  69. table.insert(configs, "-DDLIB_PNG_SUPPORT=" .. (package:config("png") and "ON" or "OFF"))
  70. table.insert(configs, "-DDLIB_JPEG_SUPPORT=" .. (package:config("jpg") and "ON" or "OFF"))
  71. table.insert(configs, "-DDLIB_GIF_SUPPORT=" .. (package:config("jpg") and "ON" or "OFF"))
  72. table.insert(configs, "-DDLIB_LINK_WITH_SQLITE3=" .. (package:config("sqlite3") and "ON" or "OFF"))
  73. table.insert(configs, "-DDLIB_USE_BLAS=" .. (package:config("blas") and "ON" or "OFF"))
  74. table.insert(configs, "-DDLIB_USE_MKL_FFT=" .. (package:config("mkl") and "ON" or "OFF"))
  75. table.insert(configs, "-DDLIB_JXL_SUPPORT=" .. (package:config("jxl") and "ON" or "OFF"))
  76. table.insert(configs, "-DDLIB_USE_FFMPEG=" .. (package:config("ffmpeg") and "ON" or "OFF"))
  77. table.insert(configs, "-DDLIB_WEBP_SUPPORT=" .. (package:config("webp") and "ON" or "OFF"))
  78. local simd = package:config("simd")
  79. table.insert(configs, "-DUSE_NEON_INSTRUCTIONS=" .. ((simd == "neon") and "ON" or "OFF"))
  80. table.insert(configs, "-DUSE_SSE2_INSTRUCTIONS=" .. ((simd == "sse2") and "ON" or "OFF"))
  81. table.insert(configs, "-DUSE_SSE4_INSTRUCTIONS=" .. ((simd == "sse4") and "ON" or "OFF"))
  82. table.insert(configs, "-DUSE_AVX_INSTRUCTIONS=" .. ((simd == "avx") and "ON" or "OFF"))
  83. if simd == "sse4" then
  84. package:add("defines", "DLIB_HAVE_SSE2", "DLIB_HAVE_SSE3", "DLIB_HAVE_SSE41")
  85. end
  86. import("package.tools.cmake").install(package, configs)
  87. end)
  88. on_test(function (package)
  89. assert(package:has_cxxtypes("dlib::command_line_parser", {
  90. includes = "dlib/cmd_line_parser.h", configs = {languages = "c++14"}}))
  91. end)