Alien-SDL3

 view release on metacpan or  search on metacpan

recipes/packages/l/libsdl3_ttf/xmake.lua  view on Meta::CPAN

                    raise("package(%s): SDL publishes no mingw arm64 prebuilt; use the MSVC toolchain instead",
                          package:name())
                elseif not is_x64 then
                    -- only i686/x86_64 mingw builds are published
                    raise("package(%s): no mingw prebuilt for arch %q; use the MSVC toolchain instead",
                          package:name(), package:arch() or "?")
                end
                local triple = "x86_64-w64-mingw32"
                incdir = path.join(root, triple, "include")
                libdir = path.join(root, triple, "lib")
                bindir = path.join(root, triple, "bin")
            end
            if not os.isdir(libdir) then
                raise("package(%s): prebuilt archive has no %s for arch %q", package:name(), libdir, package:arch() or "?")
            end

            local installdir = package:installdir()
            local incdst = path.join(installdir, "include")
            local libdst = path.join(installdir, "lib")
            local bindst = path.join(installdir, "bin")
            os.mkdir(incdst); os.mkdir(libdst); os.mkdir(bindst)

            -- Copy the *contents* of include/: a bare-dir cp would nest it one level deeper.
            os.cp(path.join(incdir, "*"), incdst)
            -- Import libraries for the linker.
            for _, pattern in ipairs({"*.lib", "*.dll.a", "*.a"}) do
                os.cp(path.join(libdir, pattern), libdst)
            end
            -- Runtime DLLs. Alien::Xrepo picks libpath -- the file FFI dlopens, which
            -- t/affix.t load_library()s -- from the first .dll it finds in the install, so
            -- the DLL must sit in lib/ as well as bin/, and bin/ is what xmake puts on the
            -- PATH it builds for on_test.
            os.cp(path.join(libdir, "*.dll"), libdst)
            os.cp(path.join(bindir, "*.dll"), bindst)
            os.cp(path.join(bindir, "*.dll"), libdst)
            -- The VC layout keeps codec DLLs in a side directory next to the main ones.
            local optional = path.join(libdir, "optional")
            if os.isdir(optional) then
                os.cp(path.join(optional, "*.dll"), libdst)
                os.cp(path.join(optional, "*.dll"), bindst)
            end

            -- CMake normally publishes these; a manual install has to declare them, or
            -- _generate_configs() raises "links not found!" for every consumer (including
            -- this package's own on_test). The dir entries must be relative: the manifest
            -- reader joins them onto the installdir itself
            -- (modules/package/manager/xmake/find_package.lua:81,144), so an absolute path
            -- would come back as installdir/C:/... and find_library would find nothing.
            package:add("includedirs", "include")
            package:add("linkdirs", "lib")
            package:add("bindirs", "bin")
            package:add("links", linkname)
        end

        if package:is_plat("windows") then
            _install_windows_prebuilt(package, "SDL_ttf", "SDL3_ttf", "SDL3_ttf")
            return
        end

        local configs = {"-DSDLTTF_SAMPLES=OFF", "-DSDLTTF_VENDORED=OFF"}
        table.insert(configs, "-DCMAKE_BUILD_TYPE=" .. (package:is_debug() and "Debug" or "Release"))
        table.insert(configs, "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"))
        table.insert(configs, "-DSDLTTF_HARFBUZZ=" .. (package:config("harfbuzz") and "ON" or "OFF"))
        table.insert(configs, "-DSDLTTF_PLUTOSVG=" .. (package:config("plutosvg") and "ON" or "OFF"))
        local freetype = package:dep("freetype")
        if freetype then
            local fetchinfo = freetype:fetch()
            if fetchinfo then
                local includedirs = table.wrap(fetchinfo.includedirs or fetchinfo.sysincludedirs)
                if #includedirs > 0 then
                    -- Freetype fix: see the header comment at the top of this file.
                    table.insert(configs, "-DFREETYPE_INCLUDE_DIR_ft2build=" .. table.concat(includedirs, ";"))
                    table.insert(configs, "-DFREETYPE_INCLUDE_DIR_freetype2=" .. table.concat(includedirs, ";"))
                end
                local libfiles = table.wrap(fetchinfo.libfiles)
                if #libfiles > 0 then
                    table.insert(configs, "-DFREETYPE_LIBRARY=" .. libfiles[1])
                end
                if not freetype:config("shared") then
                    -- Static freetype: CMake records its transitive libraries only
                    -- as link-time requirements, so splice the ones xmake knows
                    -- about onto the Freetype::Freetype link line (the same fix
                    -- the upstream recipe carries). A no-op while every optional
                    -- codec above stays disabled, but it keeps the link correct
                    -- if one is ever turned back on.
                    local deplibs = {}
                    for _, dep in ipairs(freetype:librarydeps()) do
                        local depinfo = dep:fetch()
                        if depinfo then
                            table.join2(deplibs, depinfo.libfiles)
                        end
                    end
                    if #deplibs > 0 then
                        local libraries = ""
                        for _, libfile in ipairs(deplibs) do
                            libraries = libraries .. " " .. (libfile:gsub("\\", "/"))
                        end
                        io.replace("CMakeLists.txt",
                            "target_link_libraries(${sdl3_ttf_target_name} PRIVATE Freetype::Freetype)",
                            "target_link_libraries(${sdl3_ttf_target_name} PRIVATE Freetype::Freetype " .. libraries .. ")",
                            {plain = true})
                    end
                end
            end
        end
        local install_deps = {"plutovg"}
        if package:is_plat("windows") then
            -- Let xmake generate the FindFreetype module for CMake; hand-passed
            -- -DFREETYPE_* cache vars are unreliable on some Windows toolchains.
            table.insert(install_deps, "freetype")
        end
        import("package.tools.cmake").install(package, configs, {packagedeps = install_deps})
    end)

    on_test(function (package)
        assert(package:has_cfuncs("TTF_Init", {includes = "SDL3_ttf/SDL_ttf.h"}))
    end)



( run in 1.469 second using v1.01-cache-2.11-cpan-c32d3c3b8f1 )