assert

edit

catch

edit

cprint

edit

cprintf

edit

dprint

edit

dprintf

edit

finally

edit

find_package

edit

find_packages

edit

format

edit

get_config

edit

has_config

edit

has_package

edit

import

edit

inherit

edit

ipairs

edit

irpairs

edit

is_arch

bool is_arch(string arch, ...)

Is the current compilation architecture

Returns true if the current compilation architecture is the one specified with arch. Returns false otherwise.

You can use this api to check the configuration command: xmake f -a armv7

-- if the current architecture is x86_64 or i386
if is_arch("x86_64", "i386") then
    add_files("src/xxx/*.c")
end

-- if the current architecture is armv7 or arm64 or armv7s or armv7-a
if is_arch("armv7", "arm64", "armv7s", "armv7-a") then
    -- ...
end

And you can also use the lua regular expression: .* to check all matched architectures.

-- if the current architecture is arm which contains armv7, arm64, armv7s and armv7-a ...
if is_arch("arm.*") then
    -- ...
end

被引入的版本 2.0.1

参考

is_host, is_os, is_plat, is_subarch

edit

is_config

edit

is_host

bool is_host(string host, ...)

是否为当前的编译主机系统

如果匹配当前的主机系统,那么返回 true,否则返回 false。

一些目标编译平台能够在不同的操作系统上进行构建,例如:Android NDK 可以在 linux, macOS 和 windows 上编译。

因此,我们能够使用这个 API 去决定当前的操作系统。

if is_host("windows") then
    add_includedirs("C:\\includes")
else
    add_includedirs("/usr/includess")
end

支持的主机系统有:

被引入的版本 2.1.4

参考

is_arch, is_os, is_plat, is_subhost

edit

is_mode

bool is_mode(string mode, ...)

Is the current compilation mode

You can use this api to check the configuration command: xmake f -m debug

The compilation mode is not builtin mode for xmake, so you can set the mode value by yourself.

We often use these configuration values: debug, release, profile, etc.

-- if the current compilation mode is debug?
if is_mode("debug") then

    -- add macro: DEBUG
    add_defines("DEBUG")

    -- enable debug symbols
    set_symbols("debug")

    -- disable optimization
    set_optimize("none")

end

-- if the current compilation mode is release or profile?
if is_mode("release", "profile") then

    if is_mode("release") then

        -- mark symbols visibility as hidden
        set_symbols("hidden")

        -- strip all symbols
        set_strip("all")

        -- fomit frame pointer
        add_cxflags("-fomit-frame-pointer")
        add_mxflags("-fomit-frame-pointer")

    else

        -- enable debug symbols
        set_symbols("debug")

    end

    -- add vectorexts
    add_vectorexts("sse2", "sse3", "ssse3", "mmx")
end

被引入的版本 2.0.1

参考

is_config, var_mode, os.is_mode

edit

is_plat

bool is_plat(string plat, ...)

Is the current compilation platform

Returns true if the current compilation platform is the one specified with plat. Returns false otherwise.

You can use this api to check the configuration command: xmake f -p iphoneos

-- if the current platform is android
if is_plat("android") then
    add_files("src/xxx/*.c")
end

-- if the current platform is macosx or iphoneos
if is_plat("macosx", "iphoneos") then
    add_frameworks("Foundation")
end

Support platforms:

参考

is_arch, is_host, is_mode, is_os

edit

is_subhost

bool is_subhost(string subhost, ...)

Determine the subsystem environment of the current host

At present, it is mainly used for detection of cygwin, msys2 and other subsystem environments on windows systems. If you run xmake in the msys2 shell environment, then is_subhost("windows") will return false, and is_host("windows") It will still return true.

Currently supported subsystems:

Configuration example:

if is_subhost("msys", "cygwin") then
    -- Currently in the shell environment of msys2/cygwin
end

We can also quickly check the current subsystem platform by executing xmake l os.subhost.

It may also support other subsystem environments under linux and macos systems later, if they exist.

被引入的版本 2.3.1

参考

is_host, var_subhost, os.is_subhost

edit

pairs

edit

print

edit

printf

edit

raise

edit

todisplay

edit

tonumber

edit

tostring

edit

try

edit

type

edit

unpack

edit

val

edit

vformat

edit

vprint

edit

vprintf

edit

wprint

edit
接口
assert
catch
cprint
cprintf
dprint
dprintf
finally
find_package
find_packages
format
get_config
has_config
has_package
import
inherit
ipairs
irpairs
is_arch
is_config
is_host
is_mode
is_plat
is_subhost
pairs
print
printf
raise
todisplay
tonumber
tostring
try
type
unpack
val
vformat
vprint
vprintf
wprint