summaryrefslogtreecommitdiff
path: root/xmake/includes/check_cflags.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2019-02-17 20:56:09 +0800
committerruki <[email protected]>2019-02-17 20:56:09 +0800
commit7f7e2806ac8a10133f564ad5bbb163dc4e0327d1 (patch)
treefc01a53b97a8d487be6fa36117077740f3ef8ff4 /xmake/includes/check_cflags.lua
parenta75a30ae4ca0defab59f7eb3db423d6f487cc571 (diff)
add check_cflags and check_cxxflags help functions
Diffstat (limited to 'xmake/includes/check_cflags.lua')
-rw-r--r--xmake/includes/check_cflags.lua67
1 files changed, 67 insertions, 0 deletions
diff --git a/xmake/includes/check_cflags.lua b/xmake/includes/check_cflags.lua
new file mode 100644
index 000000000..b0028d499
--- /dev/null
+++ b/xmake/includes/check_cflags.lua
@@ -0,0 +1,67 @@
+--!A cross-platform 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 - 2019, TBOOX Open Source Group.
+--
+-- @author ruki
+-- @file check_cflags.lua
+--
+
+-- check c flags and add macro definition
+--
+-- e.g.
+--
+-- check_cflags("HAS_SSE2", "-msse2")
+-- check_cflags("HAS_SSE2", {"-msse2", "/arch:SSE2"})
+--
+function check_cflags(definition, flags, opt)
+ opt = opt or {}
+ local optname = "__" .. (opt.name or definition)
+ option(optname)
+ add_defines(definition)
+ on_check(function (option)
+ import("core.tool.compiler")
+ if compiler.has_flags("c", flags, opt) then
+ option:enable(true)
+ end
+ end)
+ option_end()
+ add_options(optname)
+end
+
+-- check c flags and add macro definition to the configuration flags
+--
+-- e.g.
+--
+-- configvar_check_cflags("HAS_SSE2", "-msse2")
+-- configvar_check_cflags("HAS_SSE2", {"-msse2", "/arch:SSE2"})
+--
+function configvar_check_cflags(definition, flags, opt)
+ opt = opt or {}
+ local optname = "__" .. (opt.name or definition)
+ option(optname)
+ set_configvar(definition, 1)
+ on_check(function (option)
+ import("core.tool.compiler")
+ if compiler.has_flags("c", flags, opt) then
+ option:enable(true)
+ end
+ end)
+ option_end()
+ add_options(optname)
+end