Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions packages/g/glibmm/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package("glibmm")
set_homepage("https://gtkmm.gnome.org")
set_description("A C++ API for parts of glib that are useful for C++.")
set_license("LGPL-2.1-or-later")
-- The giomm library is also built with glibmm. There isn't an option to separate them, under meson build system.

add_urls("https://gitlab.gnome.org/GNOME/glibmm.git")
add_urls("https://download.gnome.org/sources/glibmm/$(version).tar.xz", {version = function (version)
return format("%d.%d/glibmm-%s", version:major(), version:minor(), version)
end})

add_versions("2.88.0", "a6549da3a6c43de83b8717dae5413c57a60d92f6ecc624615c612d0bb0ad0fe2")
add_versions("2.66.8", "64f11d3b95a24e2a8d4166ecff518730f79ecc27222ef41faf7c7e0340fc9329")

add_configs("deprecated_api", {description = "Build deprecated API and include it in the library", default = false, type = "boolean"})
add_configs("shared", {description = "Build shared library.", default = false, type = "boolean"})

add_deps("meson", "ninja")

on_load(function (package)
-- glibmm doesn't allow static build for MSVC-like compilers.
if package:toolchain("msvc") then
package:config_set("shared", true)
end

if package:version():lt("2.68") then
package:add("deps", "libsigcplusplus <3.0.0")
package:add("deps", "glib >=2.61.2")
package:add("languages", "c++11")
else
package:add("deps", "libsigcplusplus >=3.0.0")
package:add("deps", "glib >=2.87.3")
package:add("languages", "c++17")
end

local abi = package:version() and package:version():lt("2.68") and "2.4" or "2.68"
package:add("includedirs",
"include/glibmm-" .. abi,
"lib/glibmm-" .. abi .. "/include",
"include/giomm-" .. abi,
"lib/giomm-" .. abi .. "/include")
end)
Comment on lines +20 to +42
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The on_load block is missing add_links, which is critical for consumers to link against the library. Additionally, it's recommended to specify the required C++ standard (c++11 for ABI 2.4 and c++17 for ABI 2.68) so that it propagates to consumer projects. I've also refactored the logic to be cleaner and avoid duplicated version checks.

    on_load(function (package)
        if package:is_plat("windows") then
            package:config_set("shared", true)
        end

        local version = package:version()
        local is_legacy = version and version:lt("2.68")
        local abi = is_legacy and "2.4" or "2.68"

        if is_legacy then
            package:add("deps", "libsigcplusplus <3.0.0")
            package:add("deps", "glib >=2.61.2")
            package:add("languages", "c++11")
        else
            package:add("deps", "libsigcplusplus >=3.0.0")
            package:add("deps", "glib >=2.87.3")
            package:add("languages", "c++17")
        end

        package:add("links", "glibmm-" .. abi, "giomm-" .. abi)
        package:add("includedirs",
            "include/glibmm-" .. abi,
            "lib/glibmm-" .. abi .. "/include",
            "include/giomm-" .. abi,
            "lib/giomm-" .. abi .. "/include")
    end)


on_install("!android and !wasm and !iphoneos and !bsd", function (package)
local configs = {"-Dbuild-documentation=false", "-Dbuild-examples=false"}
table.insert(configs, "-Dbuild-deprecated-api=" .. (package:config("deprecated_api") and "true" or "false"))
table.insert(configs, "-Ddefault_library=" .. (package:config("shared") and "shared" or "static"))
import("package.tools.meson").install(package, configs)
Comment on lines +45 to +48
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It is better to explicitly pass -Ddefault_library to ensure the build system respects the shared configuration. Also, disabling tests with -Dbuild-tests=false can speed up the installation process.

        local configs = {"-Dbuild-documentation=false", "-Dbuild-examples=false", "-Dbuild-tests=false"}
        table.insert(configs, "-Ddefault_library=" .. (package:config("shared") and "shared" or "static"))
        table.insert(configs, "-Dbuild-deprecated-api=" .. (package:config("deprecated_api") and "true" or "false"))
        import("package.tools.meson").install(package, configs)

end)

on_test(function (package)
assert(package:has_cxxincludes("glibmm.h", {configs = {languages = "c++17"}}))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The test only checks for the presence of the header. It's better to use check_cxxsnippets with a small code snippet to verify that the library can be linked correctly.

        assert(package:check_cxxsnippets({test = [[\n            void test() {\n                Glib::ustring s = "hello";\n            }\n        ]]}, {configs = {languages = "c++17"}, includes = "glibmm.h"}))

end)
Loading