条件判断
条件判断通常用于处理一些特殊的编译配置。
editis_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
And you can also use the lua regular expression: .*
to check all matched architectures.
被引入的版本 2.0.1
参考
is_host, is_os, is_plat, is_subarch
editis_host
bool is_host(string host, ...)
是否为当前的编译主机系统
如果匹配当前的主机系统,那么返回 true,否则返回 false。
一些目标编译平台能够在不同的操作系统上进行构建,例如:Android NDK 可以在 linux, macOS 和 windows 上编译。
因此,我们能够使用这个 API 去决定当前的操作系统。
支持的主机系统有:
- "windows"
- "linux"
- "macosx"
被引入的版本 2.1.4
参考
is_arch, is_os, is_plat, is_subhost
editis_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.
被引入的版本 2.0.1
参考
is_config, var_mode, os.is_mode
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.
Valid input values are:
- "windows"
- "linux"
- "android"
- "macosx"
- "ios"
被引入的版本 2.0.1
参考
$(os), is_arch, is_host, is_mode, is_plat
editis_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
Support platforms:
- "windows"
- "linux"
- "macosx"
- "android"
- "iphoneos"
- "watchos"
参考
is_arch, is_host, is_mode, is_os
editis_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
.
被引入的版本 2.0.1
参考
editis_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:
- "msys"
- "cygwin"
Configuration example:
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