xmake.lua 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. package("librealsense")
  2. set_homepage("https://www.intelrealsense.com/")
  3. set_description("Intel® RealSense™ SDK")
  4. set_license("Apache-2.0")
  5. add_urls("https://github.com/IntelRealSense/librealsense/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/IntelRealSense/librealsense.git", {submodules = false})
  7. add_versions("v2.57.4", "3e82f9b545d9345fd544bb65f8bf7943969fb40bcfc73d983e7c2ffcdc05eaeb")
  8. add_patches(">=2.57.3", "patches/2.57.3/missing-headers.patch", "13834e38528e5009cdffc653515602f32a72e042497457c424de684ff5c69723")
  9. add_configs("cuda", {description = "Enable CUDA", default = false, type = "boolean"})
  10. add_configs("openmp", {description = "Use OpenMP", default = false, type = "boolean"})
  11. add_configs("tools", {description = "Build tools", default = false, type = "boolean"})
  12. add_configs("check_for_updates", {description = "Checks for versions updates", default = false, type = "boolean"})
  13. add_links("realsense2", "realsense-file", "rsutils")
  14. if is_plat("windows", "mingw") then
  15. add_syslinks("advapi32", "shell32")
  16. elseif is_plat("macosx") then
  17. add_frameworks("Security")
  18. end
  19. add_deps("cmake")
  20. add_deps("libusb", "lz4")
  21. add_deps("nlohmann_json", {configs = {cmake = true}})
  22. on_check("iphoneos", "bsd", function (package)
  23. raise("package(librealsense) dep(libusb) unsupported platform!")
  24. end)
  25. on_load(function (package)
  26. if package:config("cuda") then
  27. package:add("deps", "cuda")
  28. end
  29. if package:config("openmp") then
  30. package:add("deps", "openmp")
  31. end
  32. if package:config("tools") and package:config("check_for_updates") then
  33. package:add("deps", "libcurl")
  34. end
  35. end)
  36. on_install("!cross and !wasm and !mingw and (!windows or windows|!arm*)", function (package)
  37. -- nlohmann_json
  38. io.replace("third-party/CMakeLists.txt", "include(CMake/external_json.cmake)", "", {plain = true})
  39. io.replace("third-party/rsutils/CMakeLists.txt", "$<BUILD_INTERFACE:${CMAKE_BINARY_DIR}/third-party/json/include>", "", {plain = true})
  40. local file = io.open("third-party/rsutils/CMakeLists.txt", "a")
  41. if file then
  42. file:print("find_package(nlohmann_json CONFIG REQUIRED)")
  43. file:print("target_link_libraries(${PROJECT_NAME} PUBLIC $<BUILD_LOCAL_INTERFACE:nlohmann_json::nlohmann_json>)")
  44. file:close()
  45. end
  46. -- libusb
  47. if package:is_plat("linux") then
  48. io.replace("src/linux/CMakeLists.txt", "target_link_libraries(${LRS_TARGET} PRIVATE udev)", "target_link_libraries(${LRS_TARGET} PRIVATE ${UDEV_LIBRARIES})", {plain = true})
  49. elseif package:is_plat("macosx") then
  50. io.replace("CMake/libusb_config.cmake", "${LIBUSB_LIB}", [[${LIBUSB_LIB} "-framework CoreFoundation" "-framework IOKit" "-framework Security"]], {plain = true})
  51. end
  52. -- libcurl
  53. if package:config("tools") and package:config("check_for_updates") then
  54. io.replace("CMake/global_config.cmake", "include(CMake/external_libcurl.cmake)", "find_package(CURL REQUIRED)", {plain = true})
  55. io.replace("tools/depth-quality/CMakeLists.txt", "add_dependencies(${PROJECT_NAME} libcurl)", "", {plain = true})
  56. io.replace("tools/depth-quality/CMakeLists.txt", "target_link_libraries(${PROJECT_NAME} curl)", "target_link_libraries(${PROJECT_NAME} CURL::libcurl)", {plain = true})
  57. io.replace("tools/realsense-viewer/CMakeLists.txt", "add_dependencies(${PROJECT_NAME} libcurl)", "", {plain = true})
  58. io.replace("tools/realsense-viewer/CMakeLists.txt", "set(RS_VIEWER_LIBS ${RS_VIEWER_LIBS} curl)", "set(RS_VIEWER_LIBS ${RS_VIEWER_LIBS} CURL::libcurl)", {plain = true})
  59. end
  60. -- fix links
  61. io.replace("CMake/windows_config.cmake", [[set(CMAKE_DEBUG_POSTFIX "d")]], "", {plain = true})
  62. local configs = {
  63. "-DENABLE_CCACHE=OFF",
  64. "-DBUILD_EXAMPLES=OFF",
  65. "-DBUILD_WITH_STATIC_CRT=OFF",
  66. "-DBUILD_EASYLOGGINGPP=OFF",
  67. "-DIMPORT_DEPTH_CAM_FW=OFF", -- TODO: unbundle download file
  68. "-DUSE_EXTERNAL_LZ4=ON",
  69. -- Do not merge static library all in one, it will run `CREATE /librealsense2-all.a` and fail with Permission denied
  70. -- We can use policy `package.merge_staticlibs`
  71. "-DBUILD_RS2_ALL=OFF",
  72. }
  73. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
  74. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  75. table.insert(configs, "-DBUILD_ASAN=" .. (package:config("asan") and "ON" or "OFF"))
  76. table.insert(configs, "-DBUILD_WITH_CUDA=" .. (package:config("cuda") and "ON" or "OFF"))
  77. table.insert(configs, "-DBUILD_WITH_OPENMP=" .. (package:config("openmp") and "ON" or "OFF"))
  78. table.insert(configs, "-DBUILD_TOOLS=" .. (package:config("tools") and "ON" or "OFF"))
  79. table.insert(configs, "-DCHECK_FOR_UPDATES=" .. (package:config("check_for_updates") and "ON" or "OFF"))
  80. import("package.tools.cmake").install(package, configs)
  81. end)
  82. on_test(function (package)
  83. assert(package:check_cxxsnippets({test = [[
  84. #include <librealsense2/rs.hpp>
  85. void test() {
  86. rs2::pipeline p;
  87. auto r = rs2_create_pipeline(nullptr, nullptr);
  88. }
  89. ]]}, {configs = {languages = "c++14"}}))
  90. end)