summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-07-06 00:06:03 +0800
committerruki <[email protected]>2017-07-06 00:06:03 +0800
commit5fd1bfd5c5e2d6a8e72f033325a448a76737d738 (patch)
tree9d0ec595b10b0142cfd8f342f37fe249a068f5c6
parent5a1c8b7a4938745c40f7ad14de4823b09e979b7c (diff)
add gcc and clang features
-rw-r--r--xmake/modules/detect/tools/clang/cfeatures.lua45
-rw-r--r--xmake/modules/detect/tools/clang/cxxfeatures.lua45
-rw-r--r--xmake/modules/detect/tools/clang/features.lua48
-rw-r--r--xmake/modules/detect/tools/clangxx/features.lua27
-rw-r--r--xmake/modules/detect/tools/gcc/cfeatures.lua40
-rw-r--r--xmake/modules/detect/tools/gcc/cxxfeatures.lua41
-rw-r--r--xmake/modules/detect/tools/gcc/features.lua138
-rw-r--r--xmake/modules/detect/tools/gcc/has_flag.lua2
-rw-r--r--xmake/modules/detect/tools/gxx/features.lua27
-rw-r--r--xmake/modules/lib/detect/features.lua6
-rw-r--r--xmake/modules/lib/detect/has_features.lua4
11 files changed, 417 insertions, 6 deletions
diff --git a/xmake/modules/detect/tools/clang/cfeatures.lua b/xmake/modules/detect/tools/clang/cfeatures.lua
new file mode 100644
index 000000000..ef373f4b0
--- /dev/null
+++ b/xmake/modules/detect/tools/clang/cfeatures.lua
@@ -0,0 +1,45 @@
+--!The Make-like Build Utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2017, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file cfeatures.lua
+--
+
+-- imports
+import("detect.tools.gcc.cfeatures")
+
+-- set features
+function _set(feature, condition)
+ _g.features[feature] = condition
+end
+
+-- get features
+function main()
+
+ -- init features
+ _g.features = cfeatures()
+
+ -- TODO
+ -- set("", "")
+
+ -- get features
+ return _g.features
+end
+
diff --git a/xmake/modules/detect/tools/clang/cxxfeatures.lua b/xmake/modules/detect/tools/clang/cxxfeatures.lua
new file mode 100644
index 000000000..e458a2308
--- /dev/null
+++ b/xmake/modules/detect/tools/clang/cxxfeatures.lua
@@ -0,0 +1,45 @@
+--!The Make-like Build Utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2017, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file cxxfeatures.lua
+--
+
+-- imports
+import("detect.tools.gcc.cxxfeatures")
+
+-- set features
+function _set(feature, condition)
+ _g.features[feature] = condition
+end
+
+-- get features
+function main()
+
+ -- init features
+ _g.features = cxxfeatures()
+
+ -- TODO
+ -- set("", "")
+
+ -- get features
+ return _g.features
+end
+
diff --git a/xmake/modules/detect/tools/clang/features.lua b/xmake/modules/detect/tools/clang/features.lua
new file mode 100644
index 000000000..20807bc0c
--- /dev/null
+++ b/xmake/modules/detect/tools/clang/features.lua
@@ -0,0 +1,48 @@
+--!The Make-like Build Utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2017, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file features.lua
+--
+
+-- imports
+inherit("detect.tools.gcc.features")
+import("cfeatures")
+import("cxxfeatures")
+
+-- get features
+--
+-- @param opt the argument options, .e.g {toolname = "", program = "", programver = "", flags = {}}
+--
+-- @return the features
+--
+function main(opt)
+
+ -- set features for c
+ set_features(cfeatures())
+
+ -- set features for c++
+ set_features(cxxfeatures())
+
+ -- check features
+ return check_features(opt)
+end
+
+
diff --git a/xmake/modules/detect/tools/clangxx/features.lua b/xmake/modules/detect/tools/clangxx/features.lua
new file mode 100644
index 000000000..3a809e6c3
--- /dev/null
+++ b/xmake/modules/detect/tools/clangxx/features.lua
@@ -0,0 +1,27 @@
+--!The Make-like Build Utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2017, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file features.lua
+--
+
+-- imports
+inherit("detect.tools.gcc.features")
+
diff --git a/xmake/modules/detect/tools/gcc/cfeatures.lua b/xmake/modules/detect/tools/gcc/cfeatures.lua
new file mode 100644
index 000000000..b6aca4226
--- /dev/null
+++ b/xmake/modules/detect/tools/gcc/cfeatures.lua
@@ -0,0 +1,40 @@
+--!The Make-like Build Utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2017, 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()
+
+ -- static_assert()
+ _set("c_static_assert", "defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201000L")
+
+ -- get features
+ return _g.features
+end
+
diff --git a/xmake/modules/detect/tools/gcc/cxxfeatures.lua b/xmake/modules/detect/tools/gcc/cxxfeatures.lua
new file mode 100644
index 000000000..a0cd1a761
--- /dev/null
+++ b/xmake/modules/detect/tools/gcc/cxxfeatures.lua
@@ -0,0 +1,41 @@
+--!The Make-like Build Utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2017, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file cxxfeatures.lua
+--
+
+-- set features
+function _set(feature, condition)
+ _g.features = _g.features or {}
+ _g.features[feature] = condition
+end
+
+-- get features
+function main()
+
+ -- TODO
+ -- constexpr
+ _set("cxx_constexpr", "defined(0)")
+
+ -- get features
+ return _g.features
+end
+
diff --git a/xmake/modules/detect/tools/gcc/features.lua b/xmake/modules/detect/tools/gcc/features.lua
new file mode 100644
index 000000000..5047cb36c
--- /dev/null
+++ b/xmake/modules/detect/tools/gcc/features.lua
@@ -0,0 +1,138 @@
+--!The Make-like Build Utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2017, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file features.lua
+--
+
+-- imports
+import("cfeatures")
+import("cxxfeatures")
+
+-- get macro defines
+function _get_macro_defines(snippets, extension, opt)
+
+ -- make an stub source file
+ local sourcefile = path.join(os.tmpdir(), "detect", "gcc_features" .. extension)
+ io.writefile(sourcefile, table.concat(table.wrap(snippets), "\n"))
+
+ -- get defines
+ local results = {}
+ local defines = try { function () return os.iorunv(opt.program, table.join(opt.flags or {}, {"-dM", "-E", sourcefile})) end }
+ if defines then
+ for _, define in ipairs(defines:split("\n")) do
+ local name = define:match("#define%s+(.-)%s+")
+ if name then
+ results[name] = true
+ end
+ end
+ end
+
+ -- remove files
+ os.tryrm(sourcefile)
+
+ -- ok?
+ return results
+end
+
+-- set feature with condition
+function _set_feature(feature, condition)
+
+ -- init features
+ _g.features = _g.features or {}
+
+ -- get feature kind
+ local kind = feature:match("^(%w-)_")
+ assert(kind, "unknown kind for the feature: %s", feature)
+
+ -- init language extensions
+ _g.extensions = _g.extensions or {c = ".c", cxx = ".cpp", objc = ".m", objcxx = ".mm"}
+
+ -- get extension
+ local extension = _g.extensions[kind]
+ assert(extension, "not supported kind for the feature: %s", feature)
+
+ -- make snippet
+ local snippet = format([[
+#if (%s)
+# define %s 1
+#endif]], condition, feature)
+
+ -- init features with the given extension
+ local features = _g.features[extension] or {}
+ _g.features[extension] = features
+
+ -- set feature and snippet
+ features[feature] = snippet
+end
+
+-- set features
+function set_features(features)
+ for feature, condition in pairs(features) do
+ _set_feature(feature, condition)
+ end
+end
+
+-- check features
+function check_features(opt)
+
+ -- check features with all extensions
+ local results = {}
+ for extension, features in pairs(_g.features) do
+
+ -- make snippets
+ local snippets = {}
+ for _, snippet in pairs(features) do
+ table.insert(snippets, snippet)
+ end
+
+ -- get defines
+ local defines = _get_macro_defines(snippets, extension, opt)
+
+ -- check features
+ for feature, _ in pairs(features) do
+ if defines[feature] then
+ results[feature] = true
+ end
+ end
+ end
+
+ -- ok?
+ return results
+end
+
+-- get features
+--
+-- @param opt the argument options, .e.g {toolname = "", program = "", programver = "", flags = {}}
+--
+-- @return the features
+--
+function main(opt)
+
+ -- set features for c
+ set_features(cfeatures())
+
+ -- set features for c++
+ set_features(cxxfeatures())
+
+ -- check features
+ return check_features(opt)
+end
+
diff --git a/xmake/modules/detect/tools/gcc/has_flag.lua b/xmake/modules/detect/tools/gcc/has_flag.lua
index 396c460e4..abd0f5955 100644
--- a/xmake/modules/detect/tools/gcc/has_flag.lua
+++ b/xmake/modules/detect/tools/gcc/has_flag.lua
@@ -99,7 +99,7 @@ end
-- has_flag(flag)?
--
--- @param opt the argument options, .e.g {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"}
+-- @param opt the argument options, .e.g {toolname = "", program = "", programver = "", toolkind = "[cc|cxx|ld|ar|sh|gc|mm|mxx]"}
--
-- @return true or false
--
diff --git a/xmake/modules/detect/tools/gxx/features.lua b/xmake/modules/detect/tools/gxx/features.lua
new file mode 100644
index 000000000..3a809e6c3
--- /dev/null
+++ b/xmake/modules/detect/tools/gxx/features.lua
@@ -0,0 +1,27 @@
+--!The Make-like Build Utility based on Lua
+--
+-- Licensed to the Apache Software Foundation (ASF) under one
+-- or more contributor license agreements. See the NOTICE file
+-- distributed with this work for additional information
+-- regarding copyright ownership. The ASF licenses this file
+-- to you 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 - 2017, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file features.lua
+--
+
+-- imports
+inherit("detect.tools.gcc.features")
+
diff --git a/xmake/modules/lib/detect/features.lua b/xmake/modules/lib/detect/features.lua
index e0c11b35f..26ee9a18b 100644
--- a/xmake/modules/lib/detect/features.lua
+++ b/xmake/modules/lib/detect/features.lua
@@ -28,14 +28,14 @@ import("lib.detect.find_tool")
-- get all features of the current tool
--
-- @param name the tool name
--- @param opt the argument options, .e.g {program = "", flags = {}, toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"}
+-- @param opt the argument options, .e.g {program = "", flags = {}}
--
-- @return the features dictionary
--
-- @code
-- local features = features("clang")
-- local features = features("clang", {flags = "-O0", program = "xcrun -sdk macosx clang"})
--- local features = features("clang", {flags = {"-g", "-O0"}, toolkind = "cxx"})
+-- local features = features("clang", {flags = {"-g", "-O0"}})
-- @endcode
--
function main(name, opt)
@@ -56,7 +56,7 @@ function main(name, opt)
opt.programver = tool.version
-- init cache and key
- local key = tool.program .. "_" .. (tool.version or "") .. "_" .. (opt.toolkind or "") .. table.concat(table.wrap(opt.flags), ",")
+ local key = tool.program .. "_" .. (tool.version or "") .. "_" .. table.concat(table.wrap(opt.flags), ",")
_g._RESULTS = _g._RESULTS or {}
local results = _g._RESULTS
diff --git a/xmake/modules/lib/detect/has_features.lua b/xmake/modules/lib/detect/has_features.lua
index dc2950a71..c554845c2 100644
--- a/xmake/modules/lib/detect/has_features.lua
+++ b/xmake/modules/lib/detect/has_features.lua
@@ -30,14 +30,14 @@ import("lib.detect.features", {alias = "get_features"})
--
-- @param name the tool name
-- @param features the features
--- @param opt the argument options, .e.g {verbose = false, flags = {}, program = "", toolkind = "[cc|cxx|ld|ar|sh|gc|rc|dc|mm|mxx]"}
+-- @param opt the argument options, .e.g {verbose = false, flags = {}, program = ""}}
--
-- @return the supported features or nil
--
-- @code
-- local features = has_features("clang", "cxx_constexpr")
-- local features = has_features("clang", {"cxx_constexpr", "c_static_assert"}, {flags = {"-g", "-O0"}, program = "xcrun -sdk macosx clang"})
--- local features = has_features("clang", {"cxx_constexpr", "c_static_assert"}, {flags = "-g", toolkind = "cxx"})
+-- local features = has_features("clang", {"cxx_constexpr", "c_static_assert"}, {flags = "-g"})
-- @endcode
--
function main(name, features, opt)