Conditions

Conditions are generally used to handle some special compilation platforms.

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

Introduced in version 2.0.1

See also

is_host, is_os, is_plat, is_subarch

edit

is_host

bool is_host(string host, ...)

Is the current compilation host system

Returns true if the current compilation host system is the one specified with host. Returns false otherwise.

Some compilation platforms can be built on multiple different operating systems, for example: android ndk (on linux, macOS and windows).

So, we can use this api to determine the current host operating system.

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

Support hosts:

We can also get it from $(host) or os.host.

Introduced in version 2.1.4

See also

$(host), 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

Introduced in version 2.0.1

See also

is_config, var_mode, os_is_mode

edit

is_os

bool is_os(string os, ...)

Is the current compilation target system

Returns true if the target compilation os is the one specified with os. Returns false otherwise.

if is_os("ios") then
    add_files("src/xxx/*.m")
end

Valid input values are:

Introduced in version 2.0.1

See also

$(os), is_arch, is_host, is_mode, is_plat

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:

See also

is_arch, is_host, is_mode, is_os

edit

is_subarch

bool is_arch(string arch, ...)

Determine the architecture of the current host subsystem environment

At present, it is mainly used for the detection of the architecture under the subsystem environment such as cygwin and msys2 on the windows system. The msvc tool chain is usually used on the windows compilation platform, and the architecture is x64, x86. In the msys/cygwin subsystem environment, the compiler architecture defaults to x86_64/i386, which is different.

We can also quickly view the current subsystem architecture by executing xmake l os.subarch.

Introduced in version 2.0.1

See also

is_arch, is_os, is_plat

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.

Introduced in version 2.3.1

See also

is_host, var_subhost, os.is_subhost

edit
Interfaces
is_arch
is_host
is_mode
is_os
is_plat
is_subarch
is_subhost