Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++20 features detection #1528

Closed
xq114 opened this issue Jul 22, 2021 · 7 comments
Closed

C++20 features detection #1528

xq114 opened this issue Jul 22, 2021 · 7 comments

Comments

@xq114
Copy link
Contributor

xq114 commented Jul 22, 2021

你在什么场景下需要该功能?

https://xmake.io/#/manual/extension_modules?id=compilerfeatures

现有的features detection缺少C++20的concepts、text format、modules等

描述可能的解决方案

添加c++20的features detection

@waruqi
Copy link
Member

waruqi commented Jul 22, 2021

特性探测,我看没多少人用,所以一直没咋更新,如果你有兴趣,也可以帮忙改进下,其实也是从 cmake 那边 port 过来的。。

https://github.com/xmake-io/xmake/blob/master/xmake/modules/detect/tools/gcc/cxxfeatures.lua

@xq114
Copy link
Contributor Author

xq114 commented Oct 8, 2021

https://en.cppreference.com/w/cpp/feature_test 似乎c++20之后直接用check_macro就能完成这个检查了

@waruqi
Copy link
Member

waruqi commented Oct 8, 2021

那倒是省事了不少,就先用 check_macro 吧。。而且我看 cmake 的 cxxfeatures 也停留在 c++14 常年不更新了,感觉用的人不是很多。

@waruqi
Copy link
Member

waruqi commented Oct 8, 2021

不过既然有现成的命名和宏,后面有时间放到 check_features 里面也是可以的,也就是个体力活。。毕竟 check_feature 只需要调用一遍编译器,check_macros 每次都要执行一遍。效率上来讲,check_feature 会快不少

@waruqi waruqi added this to the v2.5.9 milestone Oct 8, 2021
@waruqi
Copy link
Member

waruqi commented Oct 10, 2021

不对,都有现成宏了。。直接用不就完事了,为啥还要 check_macro 一遍再去定义个 HAS_XXX 宏。。这不有点多此一举么 = =

@xq114
Copy link
Contributor Author

xq114 commented Oct 10, 2021

不对,都有现成宏了。。直接用不就完事了,为啥还要 check_macro 一遍再去定义个 HAS_XXX 宏。。这不有点多此一举么 = =

编译成库的时候就确定好符号,这样之后换高版本的编译器也能链接,头文件不随编译器变化

@waruqi
Copy link
Member

waruqi commented Oct 11, 2021

c++17/20 的 我搞进去了。。

local features_cxx17 = {
"cxx_aggregate_bases",
"cxx_aligned_new",
"cxx_capture_star_this",
"cxx_constexpr",
"cxx_deduction_guides",
"cxx_enumerator_attributes",
"cxx_fold_expressions",
"cxx_guaranteed_copy_elision",
"cxx_hex_float",
"cxx_if_constexpr",
"cxx_inheriting_constructors",
"cxx_inline_variables",
"cxx_namespace_attributes",
"cxx_noexcept_function_type",
"cxx_nontype_template_args",
"cxx_nontype_template_parameter_auto",
"cxx_range_based_for",
"cxx_static_assert",
"cxx_structured_bindings",
"cxx_template_template_args",
"cxx_variadic_using"}
for _, feature in ipairs(features_cxx17) do
check_features("HAS_17_" .. feature:upper(), feature, {languages = "c++17"})
end
local features_cxx20 = {
"cxx_aggregate_paren_init",
"cxx_char8_t",
"cxx_concepts",
"cxx_conditional_explicit",
"cxx_consteval",
"cxx_constexpr",
"cxx_constexpr_dynamic_alloc",
"cxx_constexpr_in_decltype",
"cxx_constinit",
"cxx_deduction_guides",
"cxx_designated_initializers",
"cxx_generic_lambdas",
"cxx_impl_coroutine",
"cxx_impl_destroying_delete",
"cxx_impl_three_way_comparison",
"cxx_init_captures",
"cxx_modules",
"cxx_nontype_template_args",
"cxx_using_enum"}
for _, feature in ipairs(features_cxx20) do
check_features("HAS_20_" .. feature:upper(), feature, {languages = "c++20"})
end

@waruqi waruqi closed this as completed Oct 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants