xmake.lua 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. package("assimp")
  2. set_homepage("https://assimp.org")
  3. set_description("Portable Open-Source library to import various well-known 3D model formats in a uniform manner")
  4. set_license("BSD-3-Clause")
  5. set_urls("https://github.com/assimp/assimp/archive/refs/tags/$(version).zip",
  6. "https://github.com/assimp/assimp.git")
  7. add_versions("v5.4.0", "0f3698e9ba0110df0b636dbdd95706e7e28d443ff3dbaf5828926c23bfff778d")
  8. add_versions("v5.3.1", "f4020735fe4601de9d85cb335115568cce0e027a65e546dd8895081696d624bd")
  9. add_versions("v5.3.0", "cccbd20522b577613096b0b157f62c222f844bc177356b8301cd74eee3fecadb")
  10. add_versions("v5.2.5", "5384877d53be7b5bbf50c26ab3f054bec91b3df8614372dcd7240f44f61c509b")
  11. add_versions("v5.2.4", "713e9aa035ae019e5f3f0de1605de308d63538897249a2ba3a2d7d40036ad2b1")
  12. add_versions("v5.2.3", "9667cfc8ddabd5dd5e83f3aebb99dbf232fce99f17b9fe59540dccbb5e347393")
  13. add_versions("v5.2.2", "7b833182b89917b3c6e8aee6432b74870fb71f432cc34aec5f5411bd6b56c1b5")
  14. add_versions("v5.2.1", "636fe5c2cfe925b559b5d89e53a42412a2d2ab49a0712b7d655d1b84c51ed504")
  15. add_versions("v5.1.4", "59a00cf72fa5ceff960460677e2b37be5cd1041e85bae9c02828c27ade7e4160")
  16. add_versions("v5.0.1", "d10542c95e3e05dece4d97bb273eba2dfeeedb37a78fb3417fd4d5e94d879192")
  17. add_patches("v5.0.1", path.join(os.scriptdir(), "patches", "5.0.1", "fix-mingw.patch"), "a3375489e2bbb2dd97f59be7dd84e005e7e9c628b4395d7022a6187ca66b5abb")
  18. add_patches("v5.2.1", path.join(os.scriptdir(), "patches", "5.2.1", "fix_zlib_filefunc_def.patch"), "a9f8a9aa1975888ea751b80c8268296dee901288011eeb1addf518eac40b71b1")
  19. add_patches("v5.2.2", path.join(os.scriptdir(), "patches", "5.2.1", "fix_zlib_filefunc_def.patch"), "a9f8a9aa1975888ea751b80c8268296dee901288011eeb1addf518eac40b71b1")
  20. add_patches("v5.2.3", path.join(os.scriptdir(), "patches", "5.2.1", "fix_zlib_filefunc_def.patch"), "a9f8a9aa1975888ea751b80c8268296dee901288011eeb1addf518eac40b71b1")
  21. add_patches("v5.2.3", path.join(os.scriptdir(), "patches", "5.2.3", "cmake_static_crt.patch"), "3872a69976055bed9e40814e89a24a3420692885b50e9f9438036e8d809aafb4")
  22. add_patches("v5.2.4", path.join(os.scriptdir(), "patches", "5.2.4", "fix_x86_windows_build.patch"), "becb4039c220678cf1e888e3479f8e68d1964c49d58f14c5d247c86b4a5c3293")
  23. if not is_host("windows") then
  24. add_extsources("pkgconfig::assimp")
  25. end
  26. if is_plat("mingw") and is_subhost("msys") then
  27. add_extsources("pacman::assimp")
  28. elseif is_plat("linux") then
  29. add_extsources("pacman::assimp", "apt::libassimp-dev")
  30. elseif is_plat("macosx") then
  31. add_extsources("brew::assimp")
  32. end
  33. add_configs("build_tools", {description = "Build the supplementary tools for Assimp.", default = false, type = "boolean"})
  34. add_configs("double_precision", {description = "Enable double precision processing.", default = false, type = "boolean"})
  35. add_configs("no_export", {description = "Disable Assimp's export functionality (reduces library size).", default = false, type = "boolean"})
  36. add_configs("android_jniiosysystem", {description = "Enable Android JNI IOSystem support.", default = false, type = "boolean"})
  37. add_configs("asan", {description = "Enable AddressSanitizer.", default = false, type = "boolean"})
  38. add_configs("ubsan", {description = "Enable Undefined Behavior sanitizer.", default = false, type = "boolean"})
  39. add_deps("cmake", "minizip", "zlib")
  40. if is_plat("windows") then
  41. add_syslinks("advapi32")
  42. end
  43. on_load(function (package)
  44. if not package:gitref() then
  45. if package:version():le("5.1.0") then
  46. package:add("deps", "irrxml")
  47. end
  48. if package:version():eq("5.3.0") then
  49. package:add("deps", "utfcpp")
  50. package:add("defines", "ASSIMP_USE_HUNTER")
  51. end
  52. end
  53. if package:is_plat("linux", "macosx") and package:config("shared") then
  54. package:add("links", "assimp" .. (package:is_debug() and "d" or ""))
  55. end
  56. end)
  57. on_install(function (package)
  58. if package:is_plat("android") then
  59. import("core.tool.toolchain")
  60. local ndk = toolchain.load("ndk", {plat = package:plat(), arch = package:arch()})
  61. local ndk_sdkver = ndk:config("ndk_sdkver")
  62. assert(ndk_sdkver and tonumber(ndk_sdkver) >= 26, "package(assimp): need ndk api level >= 26 for android")
  63. end
  64. local configs = {"-DASSIMP_BUILD_SAMPLES=OFF",
  65. "-DASSIMP_BUILD_TESTS=OFF",
  66. "-DASSIMP_BUILD_DOCS=OFF",
  67. "-DASSIMP_BUILD_FRAMEWORK=OFF",
  68. "-DASSIMP_INSTALL_PDB=ON",
  69. "-DASSIMP_INJECT_DEBUG_POSTFIX=ON",
  70. "-DASSIMP_BUILD_ZLIB=OFF",
  71. "-DSYSTEM_IRRXML=ON",
  72. "-DASSIMP_WARNINGS_AS_ERRORS=OFF"}
  73. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  74. local function add_config_arg(config_name, cmake_name)
  75. table.insert(configs, "-D" .. cmake_name .. "=" .. (package:config(config_name) and "ON" or "OFF"))
  76. end
  77. add_config_arg("shared", "BUILD_SHARED_LIBS")
  78. add_config_arg("double_precision", "ASSIMP_DOUBLE_PRECISION")
  79. add_config_arg("no_export", "ASSIMP_NO_EXPORT")
  80. add_config_arg("asan", "ASSIMP_ASAN")
  81. add_config_arg("ubsan", "ASSIMP_UBSAN")
  82. if package:is_plat("android") then
  83. add_config_arg("android_jniiosysystem", "ASSIMP_ANDROID_JNIIOSYSTEM")
  84. end
  85. if package:is_plat("windows", "linux", "macosx", "mingw") then
  86. add_config_arg("build_tools", "ASSIMP_BUILD_ASSIMP_TOOLS")
  87. else
  88. table.insert(configs, "-DASSIMP_BUILD_ASSIMP_TOOLS=OFF")
  89. end
  90. -- ASSIMP_WARNINGS_AS_ERRORS maybe does not work for some old versions
  91. for _, cmakefile in ipairs(table.join("CMakeLists.txt", os.files("**/CMakeLists.txt"))) do
  92. if package:is_plat("windows") then
  93. io.replace(cmakefile, "/W4 /WX", "", {plain = true})
  94. else
  95. io.replace(cmakefile, "-Werror", "", {plain = true})
  96. end
  97. end
  98. -- fix cmake_install failed
  99. if not package:gitref() and package:version():ge("v5.3.0") and package:is_plat("windows") and package:is_debug() then
  100. io.replace("code/CMakeLists.txt", "IF(GENERATOR_IS_MULTI_CONFIG)", "IF(TRUE)", {plain = true})
  101. end
  102. if package:is_plat("mingw") and package:version():lt("v5.1.5") then
  103. -- CMAKE_COMPILER_IS_MINGW has been removed: https://github.com/assimp/assimp/pull/4311
  104. io.replace("CMakeLists.txt", "CMAKE_COMPILER_IS_MINGW", "MINGW", {plain = true})
  105. end
  106. -- Assimp CMakeLists doesn't find minizip on Windows
  107. local packagedeps
  108. if package:is_plat("windows") then
  109. local minizip = package:dep("minizip")
  110. if minizip and not minizip:is_system() then
  111. packagedeps = table.join2(packagedeps or {}, "minizip")
  112. end
  113. end
  114. local zlib = package:dep("zlib")
  115. if zlib and not zlib:is_system() then
  116. local fetchinfo = zlib:fetch({external = false})
  117. if fetchinfo then
  118. local includedirs = fetchinfo.includedirs or fetchinfo.sysincludedirs
  119. if includedirs and #includedirs > 0 then
  120. table.insert(configs, "-DZLIB_INCLUDE_DIR=" .. table.concat(includedirs, " "))
  121. end
  122. local libfiles = fetchinfo.libfiles
  123. if libfiles then
  124. table.insert(configs, "-DZLIB_LIBRARY=" .. table.concat(libfiles, " "))
  125. end
  126. end
  127. end
  128. import("package.tools.cmake").install(package, configs, {packagedeps = packagedeps})
  129. -- copy pdb
  130. if package:is_plat("windows") then
  131. if package:config("shared") then
  132. os.trycp(path.join(package:buildir(), "bin", "**.pdb"), package:installdir("bin"))
  133. else
  134. os.trycp(path.join(package:buildir(), "lib", "**.pdb"), package:installdir("lib"))
  135. end
  136. end
  137. end)
  138. on_test(function (package)
  139. assert(package:check_cxxsnippets({test = [[
  140. #include <cassert>
  141. void test() {
  142. Assimp::Importer importer;
  143. }
  144. ]]}, {configs = {languages = "c++11"}, includes = "assimp/Importer.hpp"}))
  145. end)