xmake.lua 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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.5", "01cab8fb880cf4d1cb9c84cb74c6ce291a78c69f443dced5aa2a88fb20bdc3bd")
  8. add_versions("v19.24.4", "d881911d68972d11563bb9db692b8fcea0ac1b3fd2e3f03fa0b94fde6c739e43")
  9. add_versions("v19.22", "5f44b67f762691b92f3e41dcf9c95dd0f4525b59cacb478094e511fdacb5c096")
  10. add_configs("png", {description = "Enable png", default = false, type = "boolean"})
  11. add_configs("jpg", {description = "Enable jpg", default = false, type = "boolean"})
  12. add_configs("gif", {description = "Enable gif", default = false, type = "boolean"})
  13. add_configs("sqlite3", {description = "Enable sqlite3", default = false, type = "boolean"})
  14. add_configs("blas", {description = "Enable blas", default = false, type = "boolean"})
  15. add_configs("mkl", {description = "Enable mkl", default = false, type = "boolean"})
  16. add_configs("jxl", {description = "Enable jpeg xl", default = false, type = "boolean"})
  17. add_configs("ffmpeg", {description = "Enable ffmpeg", default = false, type = "boolean"})
  18. add_configs("webp", {description = "Enable webp", default = false, type = "boolean"})
  19. add_configs("simd", {description = "SIMD acceleration architecture.", type = "string", values = {"sse2", "sse4", "avx", "neon"}})
  20. if is_plat("linux", "bsd") then
  21. add_syslinks("pthread")
  22. end
  23. add_deps("cmake")
  24. on_load(function (package)
  25. if package:config("png") then
  26. package:add("deps", "libpng")
  27. end
  28. if package:config("png") then
  29. package:add("deps", "libjpeg")
  30. end
  31. if package:config("gif") then
  32. package:add("deps", "giflib")
  33. end
  34. if package:config("sqlite3") then
  35. package:add("deps", "sqlite3")
  36. end
  37. if package:config("blas") then
  38. package:add("deps", "openblas")
  39. end
  40. if package:config("mkl") then
  41. package:add("deps", "mkl")
  42. end
  43. if package:config("jxl") then
  44. package:add("deps", "libjxl")
  45. end
  46. if package:config("ffmpeg") then
  47. package:add("deps", "ffmpeg")
  48. end
  49. if package:version():ge("19.24") and package:config("webp") then
  50. package:add("deps", "libwebp")
  51. end
  52. end)
  53. on_install(function (package)
  54. local configs = {
  55. "-DDLIB_IN_PROJECT_BUILD=OFF",
  56. "-DDLIB_ISO_CPP_ONLY=OFF",
  57. "-DDLIB_NO_GUI_SUPPORT=ON"
  58. }
  59. if package:is_plat("windows") then
  60. if package:is_debug() then
  61. table.insert(configs, "-DCMAKE_COMPILE_PDB_OUTPUT_DIRECTORY=''")
  62. end
  63. if package:config("shared") then
  64. table.insert(configs, "-DCMAKE_WINDOWS_EXPORT_ALL_SYMBOLS=ON")
  65. 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})
  66. end
  67. end
  68. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  69. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  70. table.insert(configs, "-DDLIB_PNG_SUPPORT=" .. (package:config("png") and "ON" or "OFF"))
  71. table.insert(configs, "-DDLIB_JPEG_SUPPORT=" .. (package:config("jpg") and "ON" or "OFF"))
  72. table.insert(configs, "-DDLIB_GIF_SUPPORT=" .. (package:config("jpg") and "ON" or "OFF"))
  73. table.insert(configs, "-DDLIB_LINK_WITH_SQLITE3=" .. (package:config("sqlite3") and "ON" or "OFF"))
  74. table.insert(configs, "-DDLIB_USE_BLAS=" .. (package:config("blas") and "ON" or "OFF"))
  75. table.insert(configs, "-DDLIB_USE_MKL_FFT=" .. (package:config("mkl") and "ON" or "OFF"))
  76. table.insert(configs, "-DDLIB_JXL_SUPPORT=" .. (package:config("jxl") and "ON" or "OFF"))
  77. table.insert(configs, "-DDLIB_USE_FFMPEG=" .. (package:config("ffmpeg") and "ON" or "OFF"))
  78. table.insert(configs, "-DDLIB_WEBP_SUPPORT=" .. (package:config("webp") and "ON" or "OFF"))
  79. local simd = package:config("simd")
  80. table.insert(configs, "-DUSE_NEON_INSTRUCTIONS=" .. ((simd == "neon") and "ON" or "OFF"))
  81. table.insert(configs, "-DUSE_SSE2_INSTRUCTIONS=" .. ((simd == "sse2") and "ON" or "OFF"))
  82. table.insert(configs, "-DUSE_SSE4_INSTRUCTIONS=" .. ((simd == "sse4") and "ON" or "OFF"))
  83. table.insert(configs, "-DUSE_AVX_INSTRUCTIONS=" .. ((simd == "avx") and "ON" or "OFF"))
  84. if simd == "sse4" then
  85. package:add("defines", "DLIB_HAVE_SSE2", "DLIB_HAVE_SSE3", "DLIB_HAVE_SSE41")
  86. end
  87. import("package.tools.cmake").install(package, configs)
  88. end)
  89. on_test(function (package)
  90. assert(package:has_cxxtypes("dlib::command_line_parser", {
  91. includes = "dlib/cmd_line_parser.h", configs = {languages = "c++14"}}))
  92. end)