package("assimp") set_homepage("https://assimp.org") set_description("Portable Open-Source library to import various well-known 3D model formats in a uniform manner") set_license("BSD-3-Clause") set_urls("https://github.com/assimp/assimp/archive/refs/tags/$(version).zip", "https://github.com/assimp/assimp.git") add_versions("v5.4.0", "0f3698e9ba0110df0b636dbdd95706e7e28d443ff3dbaf5828926c23bfff778d") if not is_host("windows") then add_extsources("pkgconfig::assimp") end if is_plat("mingw") and is_subhost("msys") then add_extsources("pacman::assimp") elseif is_plat("linux") then add_extsources("pacman::assimp", "apt::libassimp-dev") elseif is_plat("macosx") then add_extsources("brew::assimp") end add_configs("build_tools", {description = "Build the supplementary tools for Assimp.", default = false, type = "boolean"}) add_configs("double_precision", {description = "Enable double precision processing.", default = false, type = "boolean"}) add_configs("no_export", {description = "Disable Assimp's export functionality (reduces library size).", default = false, type = "boolean"}) add_configs("android_jniiosysystem", {description = "Enable Android JNI IOSystem support.", default = false, type = "boolean"}) add_configs("asan", {description = "Enable AddressSanitizer.", default = false, type = "boolean"}) add_configs("ubsan", {description = "Enable Undefined Behavior sanitizer.", default = false, type = "boolean"}) add_deps("cmake", "minizip", "zlib") if is_plat("windows") then add_syslinks("advapi32") end if on_check then on_check("android", function (package) import("core.tool.toolchain") local ndk = toolchain.load("ndk", {plat = package:plat(), arch = package:arch()}) local ndk_sdkver = ndk:config("ndk_sdkver") assert(ndk_sdkver and tonumber(ndk_sdkver) >= 26, "package(assimp): need ndk api level >= 26 for android") end) end on_load(function (package) if not package:gitref() then if package:version():le("5.1.0") then package:add("deps", "irrxml") end if package:version():eq("5.3.0") then package:add("deps", "utfcpp") package:add("defines", "ASSIMP_USE_HUNTER") end end if package:is_plat("linux", "macosx") and package:config("shared") then package:add("links", "assimp" .. (package:is_debug() and "d" or "")) end end) on_install(function (package) if package:is_plat("android") then import("core.tool.toolchain") local ndk = toolchain.load("ndk", {plat = package:plat(), arch = package:arch()}) local ndk_sdkver = ndk:config("ndk_sdkver") assert(ndk_sdkver and tonumber(ndk_sdkver) >= 26, "package(assimp): need ndk api level >= 26 for android") end local configs = {"-DASSIMP_BUILD_SAMPLES=OFF", "-DASSIMP_BUILD_TESTS=OFF", "-DASSIMP_BUILD_DOCS=OFF", "-DASSIMP_BUILD_FRAMEWORK=OFF", "-DASSIMP_INSTALL_PDB=ON", "-DASSIMP_INJECT_DEBUG_POSTFIX=ON", "-DASSIMP_BUILD_ZLIB=OFF", "-DSYSTEM_IRRXML=ON", "-DASSIMP_WARNINGS_AS_ERRORS=OFF"} table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release")) local function add_config_arg(config_name, cmake_name) table.insert(configs, "-D" .. cmake_name .. "=" .. (package:config(config_name) and "ON" or "OFF")) end add_config_arg("shared", "BUILD_SHARED_LIBS") add_config_arg("double_precision", "ASSIMP_DOUBLE_PRECISION") add_config_arg("no_export", "ASSIMP_NO_EXPORT") add_config_arg("asan", "ASSIMP_ASAN") add_config_arg("ubsan", "ASSIMP_UBSAN") if package:is_plat("android") then add_config_arg("android_jniiosysystem", "ASSIMP_ANDROID_JNIIOSYSTEM") end if package:is_plat("windows", "linux", "macosx", "mingw") then add_config_arg("build_tools", "ASSIMP_BUILD_ASSIMP_TOOLS") else table.insert(configs, "-DASSIMP_BUILD_ASSIMP_TOOLS=OFF") end -- ASSIMP_WARNINGS_AS_ERRORS maybe does not work for some old versions for _, cmakefile in ipairs(table.join("CMakeLists.txt", os.files("**/CMakeLists.txt"))) do if package:is_plat("windows") then io.replace(cmakefile, "/W4 /WX", "", {plain = true}) else io.replace(cmakefile, "-Werror", "", {plain = true}) end end -- fix cmake_install failed if not package:gitref() and package:version():ge("v5.3.0") and package:is_plat("windows") and package:is_debug() then io.replace("code/CMakeLists.txt", "IF(GENERATOR_IS_MULTI_CONFIG)", "IF(TRUE)", {plain = true}) end if package:is_plat("mingw") and package:version():lt("v5.1.5") then -- CMAKE_COMPILER_IS_MINGW has been removed: https://github.com/assimp/assimp/pull/4311 io.replace("CMakeLists.txt", "CMAKE_COMPILER_IS_MINGW", "MINGW", {plain = true}) end -- Assimp CMakeLists doesn't find minizip on Windows local packagedeps if package:is_plat("windows") then local minizip = package:dep("minizip") if minizip and not minizip:is_system() then packagedeps = table.join2(packagedeps or {}, "minizip") end end local zlib = package:dep("zlib") if zlib and not zlib:is_system() then local fetchinfo = zlib:fetch({external = false}) if fetchinfo then local includedirs = fetchinfo.includedirs or fetchinfo.sysincludedirs if includedirs and #includedirs > 0 then table.insert(configs, "-DZLIB_INCLUDE_DIR=" .. table.concat(includedirs, " ")) end local libfiles = fetchinfo.libfiles if libfiles then table.insert(configs, "-DZLIB_LIBRARY=" .. table.concat(libfiles, " ")) end end end import("package.tools.cmake").install(package, configs, {packagedeps = packagedeps}) -- copy pdb if package:is_plat("windows") then if package:config("shared") then os.trycp(path.join(package:buildir(), "bin", "**.pdb"), package:installdir("bin")) else os.trycp(path.join(package:buildir(), "lib", "**.pdb"), package:installdir("lib")) end end end)