summaryrefslogtreecommitdiff
path: root/xmake/modules/core/tools/gcc/cfeatures.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2025-01-25 00:59:17 +0800
committerruki <[email protected]>2025-01-25 00:59:17 +0800
commit35677f50e4eb8ecb5aabe70e6ce900e28fd0adc2 (patch)
treef88df0f22e606bc8bf4361f13059bd3cb00ab0ed /xmake/modules/core/tools/gcc/cfeatures.lua
parentd1b1492b07d370f9cf06414490fc489c1dda6ed8 (diff)
move has_flags.lua
Diffstat (limited to 'xmake/modules/core/tools/gcc/cfeatures.lua')
-rw-r--r--xmake/modules/core/tools/gcc/cfeatures.lua52
1 files changed, 52 insertions, 0 deletions
diff --git a/xmake/modules/core/tools/gcc/cfeatures.lua b/xmake/modules/core/tools/gcc/cfeatures.lua
new file mode 100644
index 000000000..b9ebaa036
--- /dev/null
+++ b/xmake/modules/core/tools/gcc/cfeatures.lua
@@ -0,0 +1,52 @@
+--!A cross-platform build utility based on Lua
+--
+-- Licensed under the Apache License, Version 2.0 (the "License");
+-- you may not use this file except in compliance with the License.
+-- You may obtain a copy of the License at
+--
+-- http://www.apache.org/licenses/LICENSE-2.0
+--
+-- Unless required by applicable law or agreed to in writing, software
+-- distributed under the License is distributed on an "AS IS" BASIS,
+-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+-- See the License for the specific language governing permissions and
+-- limitations under the License.
+--
+-- Copyright (C) 2015-present, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file cfeatures.lua
+--
+
+-- set features
+function _set(feature, condition)
+ _g.features = _g.features or {}
+ _g.features[feature] = condition
+end
+
+-- get features
+function main()
+
+ -- init conditions
+ local gcc_minver = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 304"
+ local gcc10_c17 = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 1000 && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201710L"
+ local gcc46_c11 = "(__GNUC__ * 100 + __GNUC_MINOR__) >= 406 && defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201000L"
+ 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("c_std_17", gcc46_c17)
+
+ -- 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)
+ _set("c_variadic_macros", gcc34_c99)
+ _set("c_function_prototypes", gcc_c90)
+
+ -- get features
+ return _g.features
+end
+