diff options
| author | ruki <[email protected]> | 2019-02-17 20:56:09 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2019-02-17 20:56:09 +0800 |
| commit | 7f7e2806ac8a10133f564ad5bbb163dc4e0327d1 (patch) | |
| tree | fc01a53b97a8d487be6fa36117077740f3ef8ff4 | |
| parent | a75a30ae4ca0defab59f7eb3db423d6f487cc571 (diff) | |
add check_cflags and check_cxxflags help functions
| -rw-r--r-- | tests/apis/check_xxx/config.h.in | 1 | ||||
| -rw-r--r-- | tests/apis/check_xxx/xmake.lua | 2 | ||||
| -rw-r--r-- | xmake/includes/check_cflags.lua | 67 | ||||
| -rw-r--r-- | xmake/includes/check_cxxflags.lua | 67 |
4 files changed, 137 insertions, 0 deletions
diff --git a/tests/apis/check_xxx/config.h.in b/tests/apis/check_xxx/config.h.in index 11d25bf22..c5e178b44 100644 --- a/tests/apis/check_xxx/config.h.in +++ b/tests/apis/check_xxx/config.h.in @@ -7,3 +7,4 @@ ${define HAS_STATIC_ASSERT} ${define HAS_SETJMP} ${define HAS_CONSTEXPR} ${define HAS_CONSEXPR_AND_STATIC_ASSERT} +${define HAS_SSE2} diff --git a/tests/apis/check_xxx/xmake.lua b/tests/apis/check_xxx/xmake.lua index 4608a8d56..7089bef47 100644 --- a/tests/apis/check_xxx/xmake.lua +++ b/tests/apis/check_xxx/xmake.lua @@ -1,5 +1,6 @@ includes("check_links.lua") includes("check_ctypes.lua") +includes("check_cflags.lua") includes("check_cfuncs.lua") includes("check_features.lua") includes("check_csnippets.lua") @@ -19,3 +20,4 @@ target("test") configvar_check_cfuncs("HAS_SETJMP", "setjmp", {includes = {"signal.h", "setjmp.h"}}) configvar_check_features("HAS_CONSTEXPR", "cxx_constexpr") configvar_check_features("HAS_CONSEXPR_AND_STATIC_ASSERT", {"cxx_constexpr", "c_static_assert"}, {languages = "c++11"}) + configvar_check_cflags("HAS_SSE2", "-msse2") 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 diff --git a/xmake/includes/check_cxxflags.lua b/xmake/includes/check_cxxflags.lua new file mode 100644 index 000000000..00a73b3af --- /dev/null +++ b/xmake/includes/check_cxxflags.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_cxxflags.lua +-- + +-- check c++ flags and add macro definition +-- +-- e.g. +-- +-- check_cxxflags("HAS_SSE2", "-msse2") +-- check_cxxflags("HAS_SSE2", {"-msse2", "/arch:SSE2"}) +-- +function check_cxxflags(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("cxx", 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_cxxflags("HAS_SSE2", "-msse2") +-- configvar_check_cxxflags("HAS_SSE2", {"-msse2", "/arch:SSE2"}) +-- +function configvar_check_cxxflags(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("cxx", flags, opt) then + option:enable(true) + end + end) + option_end() + add_options(optname) +end |
