summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2021-10-11 23:39:09 +0800
committerruki <[email protected]>2021-10-11 23:39:09 +0800
commitfbebeff0b41df6856ba8882a1ba1bc9a8d405fd2 (patch)
tree7779a47181b43d86c56b13ce2353858c1147c7f5
parentbeba6cdb749ddafdd9232f6fed30ee4e174b0652 (diff)
add c++17/20 features
-rw-r--r--tests/apis/check_xxx/xmake.lua50
-rw-r--r--xmake/modules/detect/tools/gcc/cxxfeatures.lua54
2 files changed, 104 insertions, 0 deletions
diff --git a/tests/apis/check_xxx/xmake.lua b/tests/apis/check_xxx/xmake.lua
index b412571c4..d5ed6e2fb 100644
--- a/tests/apis/check_xxx/xmake.lua
+++ b/tests/apis/check_xxx/xmake.lua
@@ -42,6 +42,56 @@ target("foo")
configvar_check_macros("NO_GCC", "__GNUC__", {defined = false})
configvar_check_macros("HAS_CXX20", "__cplusplus >= 202002L", {languages = "c++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
+
target("test")
add_deps("foo")
set_kind("binary")
diff --git a/xmake/modules/detect/tools/gcc/cxxfeatures.lua b/xmake/modules/detect/tools/gcc/cxxfeatures.lua
index 96eaecf66..9d628522c 100644
--- a/xmake/modules/detect/tools/gcc/cxxfeatures.lua
+++ b/xmake/modules/detect/tools/gcc/cxxfeatures.lua
@@ -162,6 +162,60 @@ function main()
_set("cxx_variadic_macros", gcc_minver .. " && " .. gcc_cxx0x_defined)
_set("cxx_template_template_parameters", gcc_minver .. " && __cplusplus")
+ -- c++17 language features with predefined macros
+ -- https://en.cppreference.com/w/cpp/feature_test
+ local features_cxx17 = {
+ "__cpp_aggregate_bases",
+ "__cpp_aligned_new",
+ "__cpp_capture_star_this",
+ "__cpp_constexpr",
+ "__cpp_deduction_guides",
+ "__cpp_enumerator_attributes",
+ "__cpp_fold_expressions",
+ "__cpp_guaranteed_copy_elision",
+ "__cpp_hex_float",
+ "__cpp_if_constexpr",
+ "__cpp_inheriting_constructors",
+ "__cpp_inline_variables",
+ "__cpp_namespace_attributes",
+ "__cpp_noexcept_function_type",
+ "__cpp_nontype_template_args",
+ "__cpp_nontype_template_parameter_auto",
+ "__cpp_range_based_for",
+ "__cpp_static_assert",
+ "__cpp_structured_bindings",
+ "__cpp_template_template_args",
+ "__cpp_variadic_using"}
+ for _, feature in ipairs(features_cxx17) do
+ _set((feature:gsub("__cpp", "cxx")), "__cplusplus && defined(" .. feature .. ")")
+ end
+
+ -- c++20 language features with predefined macros
+ -- https://en.cppreference.com/w/cpp/feature_test
+ local features_cxx20 = {
+ "__cpp_aggregate_paren_init",
+ "__cpp_char8_t",
+ "__cpp_concepts",
+ "__cpp_conditional_explicit",
+ "__cpp_consteval",
+ "__cpp_constexpr",
+ "__cpp_constexpr_dynamic_alloc",
+ "__cpp_constexpr_in_decltype",
+ "__cpp_constinit",
+ "__cpp_deduction_guides",
+ "__cpp_designated_initializers",
+ "__cpp_generic_lambdas",
+ "__cpp_impl_coroutine",
+ "__cpp_impl_destroying_delete",
+ "__cpp_impl_three_way_comparison",
+ "__cpp_init_captures",
+ "__cpp_modules",
+ "__cpp_nontype_template_args",
+ "__cpp_using_enum"}
+ for _, feature in ipairs(features_cxx20) do
+ _set((feature:gsub("__cpp", "cxx")), "__cplusplus && defined(" .. feature .. ")")
+ end
+
-- get features
return _g.features
end