summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-06-23 23:26:34 +0800
committerruki <[email protected]>2017-06-23 23:26:34 +0800
commit918093af27a737b7dee986f5b70ca4d43cb1fb2f (patch)
treea0bb743928564c0be7a1da95874b928f110cdeb0
parentb359250e9cdec42b2503ee3f148c52d0e35a32b4 (diff)
add has_ctypes
-rw-r--r--xmake/modules/lib/detect/has_ctypes.lua73
-rw-r--r--xmake/modules/lib/detect/has_snippets.lua33
2 files changed, 90 insertions, 16 deletions
diff --git a/xmake/modules/lib/detect/has_ctypes.lua b/xmake/modules/lib/detect/has_ctypes.lua
new file mode 100644
index 000000000..dad3c77c4
--- /dev/null
+++ b/xmake/modules/lib/detect/has_ctypes.lua
@@ -0,0 +1,73 @@
+--!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 has_ctypes.lua
+--
+
+-- imports
+import("lib.detect.has_snippets")
+
+-- has this ctype?
+function _has_ctype(ctype, opt)
+
+ -- init name and type
+ opt.name = ctype
+ opt.kind = "c type"
+ opt.sourcekind = "cc"
+ opt.extension = ".c"
+
+ -- make snippet
+ local snippet = ""
+ for _, include in ipairs(opt.includes) do
+ snippet = format("%s\n#include <%s>", snippet, include)
+ end
+ snippet = format("%s\n\ntypedef %s __type_xxx;", snippet, ctype)
+
+ -- ok?
+ return has_snippets(snippet, opt)
+end
+
+-- has the given ctypes?
+--
+-- @param ctypes the ctypes
+-- @param opt the argument options, .e.g {verbose = false, target = [target|option], includes = {"stdio.h", "stdlib.h"}}
+--
+-- @return true or false
+--
+-- @code
+-- local ok = has_ctypes("wchar_t")
+-- @endcode
+--
+function main(ctypes, opt)
+
+ -- init options
+ opt = opt or {}
+
+ -- has all ctypes?
+ for _, ctype in ipairs(ctypes) do
+ if not _has_ctype(ctype, opt) then
+ return false
+ end
+ end
+
+ -- ok
+ return true
+end
diff --git a/xmake/modules/lib/detect/has_snippets.lua b/xmake/modules/lib/detect/has_snippets.lua
index 6ae58489e..86036c7e7 100644
--- a/xmake/modules/lib/detect/has_snippets.lua
+++ b/xmake/modules/lib/detect/has_snippets.lua
@@ -24,24 +24,12 @@
-- imports
import("core.base.option")
-import("core.language.language")
import("core.tool.compiler")
+import("core.language.language")
-- has this snippet?
function _has_snippet(snippet, opt)
- -- init cache and key
- local key = opt.name
- local results = _g._RESULTS or {}
-
- -- get result from the cache first
- if key ~= nil then
- local result = results[key]
- if result ~= nil then
- return result
- end
- end
-
-- get the source kind
local sourcekind = opt.sourcekind
if not sourcekind and opt.extension then
@@ -54,6 +42,19 @@ function _has_snippet(snippet, opt)
extension = table.wrap(language.sourcekinds()[opt.sourcekind])[1] or ".c"
end
+ -- init cache and key
+ local key = opt.name
+ local results = _g._RESULTS or {}
+
+ -- get result from the cache first
+ if key ~= nil then
+ key = key .. sourcekind
+ local result = results[key]
+ if result ~= nil then
+ return result
+ end
+ end
+
-- make the source file
local sourcefile = os.tmpfile() .. extension
local objectfile = os.tmpfile() .. ".o"
@@ -68,7 +69,7 @@ function _has_snippet(snippet, opt)
-- trace
if opt.name and (option.get("verbose") or opt.verbose) then
- cprint("checking for the snippets %s ... %s", opt.name, ifelse(result, "${green}ok", "${red}no"))
+ cprint("checking for the %s %s ... %s", opt.kind or "snippet", opt.name, ifelse(result, "${green}ok", "${red}no"))
end
-- save result to cache
@@ -81,10 +82,10 @@ function _has_snippet(snippet, opt)
return result
end
--- has the given snippets for the current tool?
+-- has the given snippets?
--
-- @param snippets the snippets
--- @param opt the argument options, .e.g {name = "", verbose = false, target = [target|option], sourcekind = "[cc|cxx|mm|mxx|sc|dc|gc|rc]", extension = "[.c|.cpp|.m|.mm|.swift|.d|.go|.rs]"}
+-- @param opt the argument options, .e.g {kind = "snippet", name = "", verbose = false, target = [target|option], sourcekind = "[cc|cxx|mm|mxx|sc|dc|gc|rc]", extension = "[.c|.cpp|.m|.mm|.swift|.d|.go|.rs]"}
--
-- @return true or false
--