xmake的使用

简介

XMake是一个基于Lua的轻量级跨平台自动构建工具,支持在各种主流平台上构建项目

xmake的目标是开发者更加关注于项目本身开发,简化项目的描述和构建,并且提供平台无关性,使得一次编写,随处构建

它跟cmake、automake、premake有点类似,但是机制不同,它默认不会去生成IDE相关的工程文件,采用直接编译,并且更加的方便易用
采用lua的工程描述语法更简洁直观,支持在大部分常用平台上进行构建,以及交叉编译

并且xmake提供了创建、配置、编译、打包、安装、卸载、运行等一些actions,使得开发和构建更加的方便和流程化。

不仅如此,它还提供了许多更加高级的特性,例如插件扩展、脚本宏记录、批量打包、自动文档生成等等。。

如果你想要了解更多,请参考:

支持特性
  • 支持windows、mac、linux、ios、android等平台,自动检测不同平台上的编译工具链(也可手动配置)
    编译windows项目采用原生vs的工具链,不需要使用cygwin、mingw(当然这些也支持)

  • 支持自定义平台编译配置,可以很方便的扩展第三方平台支持

  • 采用lua脚本语法描述项目,描述规则简单高效,逻辑规则可灵活修改,并且不会生成相关平台的工程文件,是工程更加简单明了

  • 支持创建模板工程、配置项目、编译项目、运行、打包、安装和卸载等常用功能(后续还会增加:自动生成文档、调试等模块)

  • 支持编译c/c++/objc/swift成静态库、动态库、命令行可执行程序

  • 提供丰富的工程描述api,使用简单灵活,例如添加编译文件只需(还支持过滤排除):

    add_files("src/*.c", "src/asm/**.S", "src/*.m")

  • 支持头文件、接口、链接库依赖、类型的自动检测,并可自动生成配置头文件config.h

  • 支持自定义编译配置开关,例如如果在工程描述文件中增加了enable_xxx的开关,那么配置编译的时候就可以手动进行配置来启用它:

    xmake config --enable_xxx=y

  • 提供一键打包功能,不管在哪个平台上进行打包,都只需要执行一条相同的命令,非常的方便

  • 支持全局配置,一些常用的项目配置,例如工具链、规则描述等等,都可以进行全局配置,这样就不需要每次编译不同工程,都去配置一遍

  • 除了可以自动检测依赖模块,也支持手动强制配置模块,还有各种编译flags。

  • 支持插件扩展、平台扩展、模板扩展、选项自定义等高级功能

  • 提供一些内置的常用插件(例如:自动生成doxygen文档插件,宏脚本记录和运行插件)

  • 宏记录插件里面提供了一些内置的宏脚本(例如:批量打包一个平台的所有archs等),也可以在命令行中手动记录宏并回放执行

  • 提供强大的task任务机制

  • 不依赖makefile和make,实现直接编译,内置自动多任务加速编译, xmake是一个真正的构架工具,而不仅仅是一个工程文件生成器

  • 自动检测ccache,进行自动缓存提升构建速度

  • 自动检测头文件依赖,并且快速自动构建修改的文件

常用Actions
  • config: 构建之前的编译参数配置
  • global: 配置一些全局参数
  • build: 构建项目
  • clean: 清理一些二进制文件、临时文件
  • create: 使用模板创建新工程
  • package: 打包指定目标
  • install: 安装编译后的目标文件
  • uninstall: 卸载安装的所有文件
  • run: 运行可执行的项目目标
一些内置插件
  • doxygen文档生成插件: 从指定源码目录生成doxygen文档
  • 宏记录脚本插件: 记录和回放宏脚本,简化重复的命令操作(例如:批量打包。。)
  • hello插件: 插件开发demo
  • 工程文件生成插件: 创建IDE的工程文件 (目前支持:makefile,后续支持:vs, xcode等等)
支持编译语言
  • C/C++
  • Objc/Objc++
  • Swift
  • Assembly
支持的构建平台
  • Windows (x86, x64, amd64, x86_amd64)
  • Macosx (i386, x86_64)
  • Linux (i386, x86_64, cross-toolchains …)
  • Android (armv5te, armv6, armv7-a, armv8-a, arm64-v8a)
  • iPhoneos (armv7, armv7s, arm64, i386, x86_64)
  • Watchos (armv7k, i386)
  • Mingw (i386, x86_64)
后续任务
  • 自动包依赖管理和下载
  • 创建移植仓库,实现一人移植,多人共享
  • 更多的插件开发(例如:生成.deb, .rpm的安装包)
  • 自动生成vs,xcode等工程文件
  • 添加调试器集成到xmake run -d
简单例子

创建一个c++ console项目:

    xmake create -l c++ -t 1 console
 or xmake create --language=c++ --template=1 console

工程描述文件:xmake.lua

target("console")
    set_kind("binary")
    add_files("src/*.c") 

配置工程:

这个是可选的步骤,如果只想编译当前主机平台的项目,是可以不用配置的,默认编译release版本。

   xmake f -p iphoneos -m debug
or xmake f --plat=macosx --arch=x86_64
or xmake f -p windows
or xmake config --plat=iphoneos --mode=debug
or xmake config --plat=android --arch=armv7-a --ndk=xxxxx
or xmake config -p linux -a i386
or xmake config -p mingw --cross=i386-mingw32- --toolchains=/xxx/bin
or xmake config -p mingw --sdk=/mingwsdk
or xmake config --help

编译工程:

   xmake
or xmake -r
or xmake --rebuild

运行目标:

   xmake r console
or xmake run console

打包所有:

   xmake p
or xmake package
or xmake package console
or xmake package -o /tmp
or xmake package --output=/tmp

通过宏脚本打包所有架构:

   xmake m package 
or xmake m package -p iphoneos
or xmake m package -p macosx -f "-m debug" -o /tmp/
or xmake m package --help

安装目标:

   xmake i
or xmake install
or xmake install console
or xmake install -o /tmp
or xmake install --output=/tmp

详细使用方式和参数说明,请参考文档
或者运行:

   xmake -h
or xmake --help
or xmake config --help
or xmake package --help
or xmake macro --help
...
一些使用xmake的项目:
简单例子
-- the debug mode
if is_mode("debug") then

    -- enable the debug symbols
    set_symbols("debug")

    -- disable optimization
    set_optimize("none")
end

-- the release mode
if is_mode("release") then

    -- set the symbols visibility: hidden
    set_symbols("hidden")

    -- enable fastest optimization
    set_optimize("fastest")

    -- strip all symbols
    set_strip("all")
end

-- add target
target("test")

    -- set kind
    set_kind("static")

    -- add files
    add_files("src/*.c") 
其他

xmake下载

xmake config -m debug
xmake config -m release
xmake config –arch=x64
xmake config -arch x64

xmake config -h
XMake v2.0.4.201608180949, The Make-like Build Utility based on Lua
Copyright (C) 2015-2016 Ruki Wang, tboox.org, xmake.io
Copyright (C) 2005-2015 Mike Pall, luajit.org

Usage: $xmake config|f [options] [target]

Configure the project.

Options:
–backtrace Print backtrace information for debugging.
–version Print the version number and exit.
-h, –help Print this help message and exit.

-F FILE, --file=FILE                   Read a given xmake.lua file.
-P PROJECT, --project=PROJECT          Change to the given project directory.
                                       Search priority:
                                           1. The Given Command Argument
                                           2. The Envirnoment Variable: XMAKE_PROJECT_DIR
                                           3. The Current Directory

-v, --verbose                          Print lots of verbose information.
-c, --clean                            Clean the cached configure and configure all again.

-p PLAT, --plat=PLAT                   Compile for the given platform. (default: windows)
                                           - android
                                           - iphoneos
                                           - linux
                                           - macosx
                                           - mingw
                                           - watchos
                                           - windows
-a ARCH, --arch=ARCH                   Compile for the given architecture. (default: auto)
                                           - android: armv5te armv6 armv7-a armv8-a arm64-v8a
                                           - iphoneos: armv7 armv7s arm64 i386 x86_64
                                           - linux: i386 x86_64
                                           - macosx: i386 x86_64
                                           - mingw: i386 x86_64
                                           - watchos: armv7k i386
                                           - windows: x86 x64 amd64 x86_amd64
-m MODE, --mode=MODE                   Compile for the given mode. (default: release)
                                           - debug
                                           - release
                                           - ... (custom)
-k KIND, --kind=KIND                   Compile for the given target kind. (default: static)
                                           - static
                                           - shared
                                           - binary
    --host=HOST                        The current host environment. (default: windows)

    --ccache=CCACHE                    Enable or disable the c/c++ compiler cache. (default: auto)

    --cross=CROSS                      The cross toolchains prefix
                                       .e.g
                                           - i386-mingw32-
                                           - arm-linux-androideabi-
    --toolchains=TOOLCHAINS            The cross toolchains directory
                                       .e.g
                                           - sdk/bin (/arm-linux-gcc ..)
    --sdk=SDK                          The cross sdk directory
                                       .e.g
                                           - sdk/bin (toolchains)
                                           - sdk/lib
                                           - sdk/include

    --cc=CC                            The C Compiler
    --cxx=CXX                          The C++ Compiler
    --cflags=CFLAGS                    The C Compiler Flags
    --cxflags=CXFLAGS                  The C/C++ compiler Flags
    --cxxflags=CXXFLAGS                The C++ Compiler Flags

    --as=AS                            The Assembler
    --asflags=ASFLAGS                  The Assembler Flags

    --sc=SC                            The Swift Compiler
    --scflags=SCFLAGS                  The Swift Compiler Flags

    --ld=LD                            The Linker
    --ldflags=LDFLAGS                  The Binary Linker Flags

    --ar=AR                            The Static Library Linker
    --arflags=ARFLAGS                  The Static Library Linker Flags

    --sh=SH                            The Shared Library Linker
    --shflags=SHFLAGS                  The Shared Library Linker Flags

    --dd=DD                            The Debugger (default: auto)

    --ndk=NDK                          The NDK Directory
    --ndk_sdkver=NDK_SDKVER            The SDK Version for NDK (default: auto)

    --mm=MM                            the objc compiler
    --mxx=MXX                          the objc++ compiler
    --mflags=MFLAGS                    the objc compiler flags
    --mxflags=MXFLAGS                  the objc/c++ compiler flags
    --mxxflags=MXXFLAGS                the objc++ compiler flags

    --xcode_dir=XCODE_DIR              the xcode application directory (default: auto)
    --xcode_sdkver=XCODE_SDKVER        the sdk version for xcode (default: auto)
    --target_minver=TARGET_MINVER      the target minimal version (default: auto)

    --mobileprovision=MOBILEPROVISION  The Provisioning Profile File (default: auto)
    --codesign=CODESIGN                The Code Signing Indentity (default: auto)
    --entitlements=ENTITLEMENTS        The Code Signing Entitlements (default: auto)

    --vs=VS                            The Microsoft Visual Studio (default: auto)
-o BUILDIR, --buildir=BUILDIR          Set the build directory. (default: build)

target                                 Configure for the given target. (default: all)
简介 XMake 是一个跨平台自动构建工具,支持在各种主流平台上构建项目,类似 cmake、automake、premake,但是更加的方便易用,工程描述语法更简洁直观,支持平台更多,并且集创建、配置、编译、打包、安装、卸载、运行于一体。 支持特性 支持windows、mac、linux、ios、android等平台,自动检测不同平台上的编译工具链(也可手动配置) 编译windows项目采用原生vs的工具链,不需要使用cygwin、mingw(当然这些也支持) 支持自定义平台编译配置,可以很方便的扩展第三方平台支持 采用lua脚本语法描述项目,描述规则简单高效,逻辑规则可灵活修改,并且不会生成相关平台的工程文件,是工程更加简单明了 支持创建模板工程、配置项目、编译项目、运行、打包、安装和卸载等常用功能(后续还会增加:自动生成文档、调试等模块) 支持编译c/c /objc成静态库、动态库、命令行可执行程序(后续还会增加:mac、ios、android的app的生成规则) 提供丰富的工程描述api,使用简单灵活,例如添加编译文件只需(还支持过滤排除): add_files("src/*.c", "src/asm/**.S", "src/*.m") 支持头文件、接口、链接库依赖、类型的自动检测,并可自动生成配置头文件config.h 支持自定义编译配置开关,例如如果在工程描述文件中增加了enable_xxx的开关,那么配置编译的时候就可以手动进行配置来启用它: xmake config --enable_xxx=true 提供一键打包功能,不管在哪个平台上进行打包,都只需要执行一条相同的命令,非常的方便 支持自定义编译工具和规则,例如想要增加对masm/yasm的编译规则,只需将自己写的masm.lua/yasm.lua规则文件,放到当前项目目录下即可。。 支持全局配置,一些常用的项目配置,例如工具链、规则描述等等,都可以进行全局配置,这样就不需要每次编译不同工程,都去配置一遍 除了可以自动检测依赖模块,也支持手动强制配置模块,还有各种编译flags。 简单例子 创建一个c console项目:xmake create -l c  -t 1 console  or xmake create --language=c  --template=1 console 工程描述文件:xmake.luaadd_target("console")     set_kind("binary")     add_files("src/*.c") 配置工程: 这个是可选的步骤,如果只想编译当前主机平台的项目,是可以不用配置的,默认编译release版本。   当然每次配置都会被缓存,不需要每次全部重新配置。xmake f -p iphoneos -m debug or xmake f --ldflags="-Lxxx -lxxx" or xmake f --plat=macosx --arch=x86_64 or xmake config --plat=iphoneos --mode=debug or xmake config --plat=iphonesimulator or xmake config --plat=android --arch=armv7-a --ndk=xxxxx or xmake config --cross=i386-mingw32- --toolchains=/xxx/bin or xmake config --cxflags="-Dxxx -Ixxx" or xmake config --help 编译工程:xmake or xmake -r or xmake --rebuild 运行目标:xmake r console or xmake run console 打包所有:xmake p or xmake p --archs="armv7, arm64" or xmake package or xmake package console or xmake package -o /tmp or xmake package --output=/tmp 安装目标:xmake i or xmake install or xmake install console or xmake install -o /tmp or xmake install --output=/tmp 详细使用方式和参数说明,请参考文档 或者运行:xmake -h or xmake --help or xmake config --help or xmake package --help ... 也可以参考使用xmake的实际项目:TBOX 后续工作 完善打包模块,支持对ios、mac、android的app进行一键打包和签名,生成.ipa、.apk、.app的应用程序文件 完善安装功能,支持对ios、android的app进行安装到设备 实现调试功能 实现自动生成doxygen文档功能 增加一些实用的工程描述api,例如:下载api,可以自动下载缺少的依赖库等等。。 解析automake、cmake的工程,并自动生成xmake的描述文件,实现无缝编译(如果这个实现成功的话,以后移植编译一些开源代码就更方便了) 标签:构建工具
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值