xmake.lua 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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/$(version).zip",
  6. "https://github.com/assimp/assimp.git")
  7. add_versions("v5.2.4", "713e9aa035ae019e5f3f0de1605de308d63538897249a2ba3a2d7d40036ad2b1")
  8. add_versions("v5.2.3", "9667cfc8ddabd5dd5e83f3aebb99dbf232fce99f17b9fe59540dccbb5e347393")
  9. add_versions("v5.2.2", "7b833182b89917b3c6e8aee6432b74870fb71f432cc34aec5f5411bd6b56c1b5")
  10. add_versions("v5.2.1", "636fe5c2cfe925b559b5d89e53a42412a2d2ab49a0712b7d655d1b84c51ed504")
  11. add_versions("v5.1.4", "59a00cf72fa5ceff960460677e2b37be5cd1041e85bae9c02828c27ade7e4160")
  12. add_versions("v5.0.1", "d10542c95e3e05dece4d97bb273eba2dfeeedb37a78fb3417fd4d5e94d879192")
  13. add_patches("v5.0.1", path.join(os.scriptdir(), "patches", "5.0.1", "fix-mingw.patch"), "a3375489e2bbb2dd97f59be7dd84e005e7e9c628b4395d7022a6187ca66b5abb")
  14. -- issues https://github.com/assimp/assimp/issues/4334 add this patch to fix
  15. add_patches("v5.2.1", path.join(os.scriptdir(), "patches", "5.2.1", "fix_zlib_filefunc_def.patch"), "a9f8a9aa1975888ea751b80c8268296dee901288011eeb1addf518eac40b71b1")
  16. add_patches("v5.2.2", path.join(os.scriptdir(), "patches", "5.2.1", "fix_zlib_filefunc_def.patch"), "a9f8a9aa1975888ea751b80c8268296dee901288011eeb1addf518eac40b71b1")
  17. add_patches("v5.2.3", path.join(os.scriptdir(), "patches", "5.2.1", "fix_zlib_filefunc_def.patch"), "a9f8a9aa1975888ea751b80c8268296dee901288011eeb1addf518eac40b71b1")
  18. add_patches("v5.2.3", path.join(os.scriptdir(), "patches", "5.2.3", "cmake_static_crt.patch"), "3872a69976055bed9e40814e89a24a3420692885b50e9f9438036e8d809aafb4")
  19. add_patches("v5.2.4", path.join(os.scriptdir(), "patches", "5.2.4", "fix_x86_windows_build.patch"), "becb4039c220678cf1e888e3479f8e68d1964c49d58f14c5d247c86b4a5c3293")
  20. if not is_host("windows") then
  21. add_extsources("pkgconfig::assimp")
  22. end
  23. if is_plat("mingw") and is_subhost("msys") then
  24. add_extsources("pacman::assimp")
  25. elseif is_plat("linux") then
  26. add_extsources("pacman::assimp", "apt::libassimp-dev")
  27. elseif is_plat("macosx") then
  28. add_extsources("brew::assimp")
  29. end
  30. add_configs("build_tools", {description = "Build the supplementary tools for Assimp.", default = false, type = "boolean"})
  31. add_configs("double_precision", {description = "Enable double precision processing.", default = false, type = "boolean"})
  32. add_configs("no_export", {description = "Disable Assimp's export functionality (reduces library size).", default = false, type = "boolean"})
  33. add_configs("android_jniiosysystem", {description = "Enable Android JNI IOSystem support.", default = false, type = "boolean"})
  34. add_configs("asan", {description = "Enable AddressSanitizer.", default = false, type = "boolean"})
  35. add_configs("ubsan", {description = "Enable Undefined Behavior sanitizer.", default = false, type = "boolean"})
  36. add_deps("cmake", "zlib")
  37. if is_plat("windows") then
  38. add_syslinks("advapi32")
  39. end
  40. on_load(function (package)
  41. if package:version():le("5.1.0") then
  42. package:add("deps", "irrxml")
  43. end
  44. if package:is_plat("linux", "macosx") and package:config("shared") then
  45. package:add("links", "assimp")
  46. end
  47. end)
  48. on_install("windows", "linux", "macosx", "mingw", function (package)
  49. local configs = {"-DASSIMP_BUILD_SAMPLES=OFF",
  50. "-DASSIMP_BUILD_TESTS=OFF",
  51. "-DASSIMP_BUILD_DOCS=OFF",
  52. "-DASSIMP_BUILD_FRAMEWORK=OFF",
  53. "-DASSIMP_INSTALL_PDB=ON",
  54. "-DASSIMP_INJECT_DEBUG_POSTFIX=ON",
  55. "-DASSIMP_BUILD_ZLIB=ON",
  56. "-DSYSTEM_IRRXML=ON",
  57. "-DASSIMP_WARNINGS_AS_ERRORS=OFF"}
  58. table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release"))
  59. local function add_config_arg(config_name, cmake_name)
  60. table.insert(configs, "-D" .. cmake_name .. "=" .. (package:config(config_name) and "ON" or "OFF"))
  61. end
  62. add_config_arg("shared", "BUILD_SHARED_LIBS")
  63. add_config_arg("double_precision", "ASSIMP_DOUBLE_PRECISION")
  64. add_config_arg("no_export", "ASSIMP_NO_EXPORT")
  65. add_config_arg("asan", "ASSIMP_ASAN")
  66. add_config_arg("ubsan", "ASSIMP_UBSAN")
  67. if package:is_plat("android") then
  68. add_config_arg("android_jniiosysystem", "ASSIMP_ANDROID_JNIIOSYSTEM")
  69. end
  70. if package:is_plat("windows", "linux", "macosx", "mingw") then
  71. add_config_arg("build_tools", "ASSIMP_BUILD_ASSIMP_TOOLS")
  72. else
  73. table.insert(configs, "-DASSIMP_BUILD_ASSIMP_TOOLS=OFF")
  74. end
  75. if package:version():lt("v5.2.4") then
  76. -- ASSIMP_WARNINGS_AS_ERRORS is not supported before v5.2.4
  77. if package:is_plat("windows") then
  78. io.replace("code/CMakeLists.txt", "TARGET_COMPILE_OPTIONS(assimp PRIVATE /W4 /WX)", "", {plain = true})
  79. else
  80. io.replace("code/CMakeLists.txt", "TARGET_COMPILE_OPTIONS(assimp PRIVATE -Werror)", "", {plain = true})
  81. end
  82. end
  83. if package:is_plat("mingw") and package:version():lt("v5.1.5") then
  84. -- CMAKE_COMPILER_IS_MINGW has been removed: https://github.com/assimp/assimp/pull/4311
  85. io.replace("CMakeLists.txt", "CMAKE_COMPILER_IS_MINGW", "MINGW", {plain = true})
  86. end
  87. import("package.tools.cmake").install(package, configs)
  88. -- copy pdb
  89. if package:is_plat("windows") then
  90. if package:config("shared") then
  91. os.trycp(path.join(package:buildir(), "bin", "**.pdb"), package:installdir("bin"))
  92. else
  93. os.trycp(path.join(package:buildir(), "lib", "**.pdb"), package:installdir("lib"))
  94. end
  95. end
  96. end)
  97. on_test(function (package)
  98. assert(package:check_cxxsnippets({test = [[
  99. #include <cassert>
  100. void test() {
  101. Assimp::Importer importer;
  102. }
  103. ]]}, {configs = {languages = "c++11"}, includes = "assimp/Importer.hpp"}))
  104. end)