How to get "set_languages" value within a package? #10240
|
Is it possible, inside My goal is to assert C++ version before installing a package. Or ideally, during I'd appreciate your feedback :) |
Replies: 1 comment 1 reply
|
I don't think a package can reliably read the consuming target's
package:has_cxxfuncs("foo", {configs = {languages = "cxx17"}})
package:has_cxxsnippets("...", {configs = {languages = "c++20"}})So for a package requirement I would make the C++ standard an explicit package config, then validate/use that config in package("mypkg")
add_configs("cxxstd", {
description = "C++ standard used to build/check this package",
default = "c++17",
values = {"c++17", "c++20", "c++23"}
})
on_check(function (package)
local cxxstd = package:config("cxxstd")
assert(cxxstd == "c++20" or cxxstd == "c++23", "mypkg requires at least C++20")
assert(package:has_cxxsnippets([[#include <version>
int main() { return 0; }]], {configs = {languages = cxxstd}}))
end)Then the consumer chooses it explicitly: add_requires("mypkg", {configs = {cxxstd = "c++20"}})If the check is really about a target rather than the package build, do it in target/project script context and inspect the target there; for a package recipe, pass the requirement as package config. |
I don't think a package can reliably read the consuming target's
set_languages()value directly.set_languages()is target/option-level project configuration, while the package recipe is resolved in package context and may be reused by multiple targets with different language standards. In package scripts the documented interface is the package config API (package:config(...),package:configs()) plus explicit detection configs. The package detection helpers also take the standard explicitly, for example:So for a package requirement I would make the C++ standard…