xmake.lua 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package("open3d")
  2. set_homepage("http://www.open3d.org/")
  3. set_description("Open3D: A Modern Library for 3D Data Processing")
  4. set_license("MIT")
  5. add_urls("https://github.com/isl-org/Open3D/archive/refs/tags/$(version).tar.gz",
  6. "https://github.com/isl-org/Open3D.git")
  7. add_versions("v0.15.1", "4bcfbaa6fcbcc14fba46a4d719b9256fffac09b23f8344a7d561b26394159660")
  8. add_versions("v0.17.0", "a7526efaf54434c4d54276fa0ddc63a1555401c30fb10fec9efa3241326bdd27")
  9. add_configs("python", {description = "Build the python module.", default = false, type = "boolean"})
  10. add_configs("cuda", {description = "Enable CUDA support.", default = false, type = "boolean"})
  11. add_configs("blas", {description = "Choose BLAS vendor.", default = "mkl", type = "string", values = {"mkl", "openblas"}})
  12. add_deps("cmake", "nasm")
  13. add_deps("openssl", {system = false})
  14. add_includedirs("include", "include/open3d/3rdparty")
  15. if is_plat("linux") then
  16. add_syslinks("stdc++fs")
  17. add_deps("libx11", "libxrandr", "libxrender", "libxinerama", "libxcursor", "libxfixes", "libxext", "libxi")
  18. end
  19. on_load("windows|x64", "linux|x86_64", "macosx|x86_64", function (package)
  20. if package:config("cuda") then
  21. package:add("deps", "cuda")
  22. end
  23. if package:config("python") then
  24. package:add("deps", "python 3.x")
  25. else
  26. package:add("deps", "python 3.x", {kind = "binary"})
  27. end
  28. if package:config("blas") ~= "mkl" then
  29. package:add("deps", package:config("blas"))
  30. end
  31. end)
  32. on_install("windows|x64", "linux|x86_64", "macosx|x86_64", function (package)
  33. if package:is_plat("linux") and package:has_tool("cxx", "clang", "clangxx") then
  34. package:add("ldflags", "-fsanitize=safe-stack")
  35. end
  36. io.replace("CMakeLists.txt", "add_subdirectory(docs)", "", {plain = true})
  37. io.replace("CMakeLists.txt", "add_subdirectory(examples)", "", {plain = true})
  38. io.replace("3rdparty/curl/curl.cmake", "add_dependencies", "#", {plain = true})
  39. io.replace("3rdparty/find_dependencies.cmake", "OpenSSL::Crypto", "OpenSSL::SSL OpenSSL::Crypto", {plain = true})
  40. io.writefile("examples/test_data/download_file_list.json", "{}")
  41. local configs = {"-DCMAKE_FIND_FRAMEWORK=LAST",
  42. "-DBUILD_EXAMPLES=OFF",
  43. "-DBUILD_UNIT_TESTS=OFF",
  44. "-DBUILD_BENCHMARKS=OFF",
  45. "-DBUILD_ISPC_MODULE=OFF",
  46. "-DBUILD_WEBRTC=OFF",
  47. "-DUSE_SYSTEM_BLAS=ON",
  48. "-DUSE_SYSTEM_OPENSSL=ON",
  49. "-DBUILD_FILAMENT_FROM_SOURCE=OFF",
  50. "-DBUILD_CURL_FROM_SOURCE=ON",
  51. "-DWITH_IPPICV=OFF",
  52. "-DGLIBCXX_USE_CXX11_ABI=ON",
  53. "-DPREFER_OSX_HOMEBREW=OFF",
  54. "-DDEVELOPER_BUILD=OFF"}
  55. if package:is_plat("windows") then
  56. local msvc = import("core.tool.toolchain").load("msvc")
  57. local vs = msvc:config("vs")
  58. local vstool
  59. if vs == "2015" then vstool = "vc140"
  60. elseif vs == "2017" then vstool = "vc141"
  61. elseif vs == "2019" then vstool = "vc142"
  62. elseif vs == "2022" then vstool = "vc143"
  63. end
  64. assert(vstool, "unknown vs version: %s", vs)
  65. io.replace("3rdparty/assimp/assimp.cmake", "lib_name assimp%-vc.-%-mt", format("lib_name assimp-%s-mt", vstool))
  66. local vs_sdkver = msvc:config("vs_sdkver")
  67. if vs_sdkver then
  68. local build_ver = string.match(vs_sdkver, "%d+%.%d+%.(%d+)%.?%d*")
  69. assert(tonumber(build_ver) >= 18362, "open3d requires Windows SDK to be at least 10.0.18362.0")
  70. table.insert(configs, "-DCMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION=" .. vs_sdkver)
  71. table.insert(configs, "-DCMAKE_SYSTEM_VERSION=" .. vs_sdkver)
  72. end
  73. end
  74. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  75. table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
  76. table.insert(configs, "-DBUILD_PYTHON_MODULE=" .. (package:config("python") and "ON" or "OFF"))
  77. table.insert(configs, "-DBUILD_CUDA_MODULE=" .. (package:config("cuda") and "ON" or "OFF"))
  78. if package:is_plat("windows") then
  79. table.insert(configs, "-DSTATIC_WINDOWS_RUNTIME=" .. (package:config("vs_runtime"):startswith("MT") and "ON" or "OFF"))
  80. end
  81. table.insert(configs, "-DUSE_BLAS=" .. (package:config("blas") == "openblas" and "ON" or "OFF"))
  82. table.insert(configs, "-DBORINGSSL_ROOT_DIR=" .. package:dep("openssl"):installdir())
  83. if package:is_plat("windows") then
  84. import("package.tools.cmake").install(package, configs, {buildir = os.tmpfile() .. ".dir"})
  85. elseif package:is_plat("linux") then
  86. import("package.tools.cmake").install(package, configs, {packagedeps = {"libxrandr", "libxrender", "libxinerama", "libxcursor", "libxfixes", "libxext", "libxi", "libx11"}})
  87. else
  88. import("package.tools.cmake").install(package, configs)
  89. end
  90. if not package:is_plat("windows") then
  91. package:add("links", "Open3D")
  92. for _, f in ipairs(os.files(path.join(package:installdir("lib"), "lib*.a"))) do
  93. if f:match(".+Open3D_3rdparty_.+%.a") then
  94. package:add("links", path.basename(f):match("lib(.+)"))
  95. end
  96. end
  97. end
  98. end)
  99. on_test(function (package)
  100. assert(package:check_cxxsnippets({test = [[
  101. #include <vector>
  102. #include <string>
  103. void test() {
  104. using namespace open3d::utility::filesystem;
  105. std::vector<std::string> filenames;
  106. ListFilesInDirectory(".", filenames);
  107. }
  108. ]]}, {configs = {languages = "c++14"}, includes = "open3d/Open3D.h"}))
  109. end)