diff options
| author | ruki <[email protected]> | 2021-09-29 23:19:52 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2021-09-29 23:19:52 +0800 |
| commit | d4397494c7585d62364df8026c1626f1f682baa5 (patch) | |
| tree | 7f7f0b14b3840f79441b1c3683a5d797e567c800 | |
| parent | 2904ba8f0e7eb87eab4b47a6021c1ce9039a40ba (diff) | |
add cxx_std_ features
| -rw-r--r-- | tests/apis/check_xxx/config.h.in | 8 | ||||
| -rw-r--r-- | tests/apis/check_xxx/xmake.lua | 8 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/cl/cfeatures.lua | 5 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/cl/cxxfeatures.lua | 10 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/clang/cfeatures.lua | 5 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/clang/cxxfeatures.lua | 11 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/gcc/cfeatures.lua | 5 | ||||
| -rw-r--r-- | xmake/modules/detect/tools/gcc/cxxfeatures.lua | 10 | ||||
| -rw-r--r-- | xmake/modules/lib/detect/features.lua | 5 |
9 files changed, 62 insertions, 5 deletions
diff --git a/tests/apis/check_xxx/config.h.in b/tests/apis/check_xxx/config.h.in index a8baad68d..5fc62415e 100644 --- a/tests/apis/check_xxx/config.h.in +++ b/tests/apis/check_xxx/config.h.in @@ -8,6 +8,14 @@ ${define HAS_CONSTEXPR} ${define HAS_CONSEXPR_AND_STATIC_ASSERT} ${define HAS_SSE2} ${define HAS_LONG_8} +${define HAS_CXX_STD_98} +${define HAS_CXX_STD_11} +${define HAS_CXX_STD_14} +${define HAS_CXX_STD_17} +${define HAS_CXX_STD_20} +${define HAS_C_STD_89} +${define HAS_C_STD_99} +${define HAS_C_STD_11} ${define PTR_SIZE} ${define HAVE_VISIBILITY} ${define CUSTOM_ASSERT} diff --git a/tests/apis/check_xxx/xmake.lua b/tests/apis/check_xxx/xmake.lua index ffd9f9242..59a648c5c 100644 --- a/tests/apis/check_xxx/xmake.lua +++ b/tests/apis/check_xxx/xmake.lua @@ -23,6 +23,14 @@ target("test") configvar_check_cfuncs("HAS_SETJMP", "setjmp", {includes = {"signal.h", "setjmp.h"}}) configvar_check_features("HAS_CONSTEXPR", "cxx_constexpr", {languages = "c++11"}) configvar_check_features("HAS_CONSEXPR_AND_STATIC_ASSERT", {"cxx_constexpr", "c_static_assert"}, {languages = "c++11"}) + configvar_check_features("HAS_CXX_STD_98", "cxx_std_98") + configvar_check_features("HAS_CXX_STD_11", "cxx_std_11", {languages = "c++11"}) + configvar_check_features("HAS_CXX_STD_14", "cxx_std_14", {languages = "c++14"}) + configvar_check_features("HAS_CXX_STD_17", "cxx_std_17", {languages = "c++17"}) + configvar_check_features("HAS_CXX_STD_20", "cxx_std_20", {languages = "c++20"}) + configvar_check_features("HAS_C_STD_89", "c_std_89") + configvar_check_features("HAS_C_STD_99", "c_std_99") + configvar_check_features("HAS_C_STD_11", "c_std_11", {languages = "c11"}) configvar_check_cflags("HAS_SSE2", "-msse2") configvar_check_csnippets("HAS_LONG_8", "return (sizeof(long) == 8)? 0 : -1;", {tryrun = true}) configvar_check_csnippets("PTR_SIZE", 'printf("%d", sizeof(void*)); return 0;', {output = true, number = true}) diff --git a/xmake/modules/detect/tools/cl/cfeatures.lua b/xmake/modules/detect/tools/cl/cfeatures.lua index 88c65559f..9b043f7e1 100644 --- a/xmake/modules/detect/tools/cl/cfeatures.lua +++ b/xmake/modules/detect/tools/cl/cfeatures.lua @@ -31,6 +31,11 @@ function main() local msvc_minver = "_MSC_VER >= 1200" local msvc_2005 = "_MSC_VER >= 1400" local msvc_2010 = "_MSC_VER >= 1600" + local msvc_2019 = "_MSC_VER >= 1920" + + -- set language standard supports + _set("c_std_89", msvc_2005) + _set("c_std_99", msvc_2019) -- set features _set("c_static_assert", msvc_2010) diff --git a/xmake/modules/detect/tools/cl/cxxfeatures.lua b/xmake/modules/detect/tools/cl/cxxfeatures.lua index 661af6640..c8b683e6f 100644 --- a/xmake/modules/detect/tools/cl/cxxfeatures.lua +++ b/xmake/modules/detect/tools/cl/cxxfeatures.lua @@ -32,6 +32,7 @@ end -- http://www.visualstudio.com/en-us/news/vs2015-preview-vs.aspx -- http://blogs.msdn.com/b/vcblog/archive/2015/04/29/c-11-14-17-features-in-vs-2015-rc.aspx -- http://blogs.msdn.com/b/vcblog/archive/2015/06/19/c-11-14-17-features-in-vs-2015-rtm.aspx +-- https://docs.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance?view=msvc-160 -- -- porting from Modules/Compiler/MSVC-CXX-FeatureTests.cmake -- @@ -49,6 +50,15 @@ function main() local msvc_2013 = "_MSC_VER >= 1800" local msvc_2015 = "_MSC_VER >= 1900" local msvc_2017 = "_MSC_VER >= 1910" + local msvc_2019 = "_MSC_VER >= 1920" + local msvc_2022 = "_MSC_VER >= 1930" + + -- set language standard supports + _set("cxx_std_98", msvc_2005) + _set("cxx_std_11", msvc_2015) + _set("cxx_std_14", msvc_2017) + _set("cxx_std_17", msvc_2019) + _set("cxx_std_20", msvc_2022) -- VS version 15 (not 2015) introduces support for aggregate initializers. _set("cxx_aggregate_default_initializers", "_MSC_FULL_VER >= 190024406") diff --git a/xmake/modules/detect/tools/clang/cfeatures.lua b/xmake/modules/detect/tools/clang/cfeatures.lua index 8cdfadfd0..8c462a16f 100644 --- a/xmake/modules/detect/tools/clang/cfeatures.lua +++ b/xmake/modules/detect/tools/clang/cfeatures.lua @@ -38,6 +38,11 @@ function main() local c99 = clang_minver .. " && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L" local c90 = clang_minver + -- set language standard supports + _set("c_std_89", c90) + _set("c_std_99", c99) + _set("c_std_11", c11) + -- set features _set("c_static_assert", c11) _set("c_restrict", c99) diff --git a/xmake/modules/detect/tools/clang/cxxfeatures.lua b/xmake/modules/detect/tools/clang/cxxfeatures.lua index bbf3da8b8..6a468db00 100644 --- a/xmake/modules/detect/tools/clang/cxxfeatures.lua +++ b/xmake/modules/detect/tools/clang/cxxfeatures.lua @@ -28,6 +28,8 @@ end -- get features -- +-- @see http://clang.llvm.org/cxx_status.html +-- -- porting from Modules/Compiler/Clang-CXX-FeatureTests.cmake -- function main() @@ -37,11 +39,20 @@ function main() -- init conditions local clang_minver = "((__clang_major__ * 100) + __clang_minor__) >= 301" + local clang80_cxx20 = "((__clang_major__ * 100) + __clang_minor__) >= 800 && __cplusplus > 201707L" + local clang50_cxx17 = "((__clang_major__ * 100) + __clang_minor__) >= 500 && __cplusplus > 201703L" local clang34_cxx14 = "((__clang_major__ * 100) + __clang_minor__) >= 304 && __cplusplus > 201103L" local clang31_cxx11 = clang_minver .. " && __cplusplus >= 201103L" local clang29_cxx11 = clang_minver .. " && __cplusplus >= 201103L" local clang_cxx98 = clang_minver .. " && __cplusplus >= 199711L" + -- set language standard supports + _set("cxx_std_98", clang_cxx98) + _set("cxx_std_11", clang29_cxx11) + _set("cxx_std_14", clang34_cxx14) + _set("cxx_std_17", clang50_cxx17) + _set("cxx_std_20", clang80_cxx20) + -- set features for __has_feature() local features_of_has_feature = { diff --git a/xmake/modules/detect/tools/gcc/cfeatures.lua b/xmake/modules/detect/tools/gcc/cfeatures.lua index 664892720..9f4ee275b 100644 --- a/xmake/modules/detect/tools/gcc/cfeatures.lua +++ b/xmake/modules/detect/tools/gcc/cfeatures.lua @@ -33,6 +33,11 @@ function main() local gcc34_c99 = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 304 && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L" local gcc_c90 = gcc_minver + -- set language standard supports + _set("c_std_89", gcc46_c90) + _set("c_std_99", gcc34_c99) + _set("c_std_11", gcc46_c11) + -- set features _set("c_static_assert", gcc46_c11) -- GNU 4.7 correctly sets __STDC_VERSION__ to 201112L, but GNU 4.6 sets it to 201000L _set("c_restrict", gcc34_c99) diff --git a/xmake/modules/detect/tools/gcc/cxxfeatures.lua b/xmake/modules/detect/tools/gcc/cxxfeatures.lua index 4edb33a27..e40eadf13 100644 --- a/xmake/modules/detect/tools/gcc/cxxfeatures.lua +++ b/xmake/modules/detect/tools/gcc/cxxfeatures.lua @@ -28,6 +28,7 @@ end -- -- http://gcc.gnu.org/projects/cxx0x.html -- http://gcc.gnu.org/projects/cxx1y.html +-- https://gcc.gnu.org/projects/cxx-status.html -- -- porting from Modules/Compiler/GNU-CXX-FeatureTests.cmake -- @@ -35,6 +36,8 @@ function main() -- init conditions local gcc_minver = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 404" + local gcc90_cxx20 = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 900 && __cplusplus >= 201709L" + local gcc70_cxx17 = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 700 && __cplusplus >= 201703L" local gcc50_cxx14 = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 500 && __cplusplus >= 201402L" local gcc49_cxx14 = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 409 && __cplusplus > 201103L" local gcc481_cxx11 = "((__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) >= 40801) && __cplusplus >= 201103L" @@ -46,6 +49,13 @@ function main() local gcc44_cxx11 = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 404 && " .. gcc_cxx0x_defined local gcc43_cxx11 = gcc_minver .. " && " .. gcc_cxx0x_defined + -- set language standard supports + _set("cxx_std_98", gcc_minver) + _set("cxx_std_11", gcc43_cxx11) + _set("cxx_std_14", gcc49_cxx14) + _set("cxx_std_17", gcc70_cxx17) + _set("cxx_std_20", gcc90_cxx20) + -- set features _set("cxx_variable_templates", gcc50_cxx14) _set("cxx_relaxed_constexpr", gcc50_cxx14) diff --git a/xmake/modules/lib/detect/features.lua b/xmake/modules/lib/detect/features.lua index 614d8c592..8b9bde45b 100644 --- a/xmake/modules/lib/detect/features.lua +++ b/xmake/modules/lib/detect/features.lua @@ -79,12 +79,7 @@ function main(name, opt) end _g._checking = nil - -- no features? result = result or {} - - -- save result to cache results[key] = result - - -- ok? return result end |
