diff options
| author | ruki <waruqi@gmail.com> | 2019-08-22 22:16:29 +0800 |
|---|---|---|
| committer | ruki <waruqi@gmail.com> | 2019-08-22 07:38:57 +0800 |
| commit | 576c0ac8f27626ce7151ad3777e55e46111f481c (patch) | |
| tree | d1a1280862db01e041778a030aed86f830d67e80 /old | |
| parent | 6c94dc0ffe5ad866eb81b86199d245a7f421e8f1 (diff) | |
| download | xmake-docs-576c0ac8f27626ce7151ad3777e55e46111f481c.tar.gz xmake-docs-576c0ac8f27626ce7151ad3777e55e46111f481c.zip | |
improve search and cover
Diffstat (limited to 'old')
| -rw-r--r-- | old/README.md | 1797 | ||||
| -rw-r--r-- | old/zh/README.md | 1888 |
2 files changed, 0 insertions, 3685 deletions
diff --git a/old/README.md b/old/README.md deleted file mode 100644 index 9f547b1f..00000000 --- a/old/README.md +++ /dev/null @@ -1,1797 +0,0 @@ - -<p> -<div align="center"> - <a href="https://xmake.io"> - <img width="200" heigth="200" src="https://tboox.org/static/img/xmake/logo256c.png"> - </a> - - <h1>xmake</h1> - - <div> - <a href="https://travis-ci.org/xmake-io/xmake"> - <img src="https://img.shields.io/travis/xmake-io/xmake/master.svg?style=flat-square" alt="travis-ci" /> - </a> - <a href="https://ci.appveyor.com/project/waruqi/xmake/branch/master"> - <img src="https://img.shields.io/appveyor/ci/waruqi/xmake/master.svg?style=flat-square" alt="appveyor-ci" /> - </a> - <a href="https://aur.archlinux.org/packages/xmake"> - <img src="https://img.shields.io/aur/votes/xmake.svg?style=flat-square" alt="AUR votes" /> - </a> - <a href="https://github.com/xmake-io/xmake/releases"> - <img src="https://img.shields.io/github/release/xmake-io/xmake.svg?style=flat-square" alt="Github All Releases" /> - </a> - </div> - <div> - <a href="https://github.com/xmake-io/xmake/blob/master/LICENSE.md"> - <img src="https://img.shields.io/github/license/xmake-io/xmake.svg?colorB=f48041&style=flat-square" alt="license" /> - </a> - <a href="https://www.reddit.com/r/tboox/"> - <img src="https://img.shields.io/badge/chat-on%20reddit-ff3f34.svg?style=flat-square" alt="Reddit" /> - </a> - <a href="https://gitter.im/tboox/tboox?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"> - <img src="https://img.shields.io/gitter/room/tboox/tboox.svg?style=flat-square&colorB=96c312" alt="Gitter" /> - </a> - <a href="https://t.me/tbooxorg"> - <img src="https://img.shields.io/badge/chat-on%20telegram-blue.svg?style=flat-square" alt="Telegram" /> - </a> - <a href="https://jq.qq.com/?_wv=1027&k=5hpwWFv"> - <img src="https://img.shields.io/badge/chat-on%20QQ-ff69b4.svg?style=flat-square" alt="QQ" /> - </a> - <a href="https://xmake.io/pages/donation.html#donate"> - <img src="https://img.shields.io/badge/donate-us-orange.svg?style=flat-square" alt="Donate" /> - </a> - </div> - - <p>A cross-platform build utility based on Lua</p> -</div> -</p> - -## Introduction - -xmake is a cross-platform build utility based on lua. - -The project focuses on making development and building easier and provides many features (.e.g package, install, plugin, macro, action, option, task ...), -so that any developer can quickly pick it up and enjoy the productivity boost when developing and building project. - -## Installation - -#### Master - -##### via curl - -```bash -bash <(curl -fsSL https://raw.githubusercontent.com/tboox/xmake/master/scripts/get.sh) -``` - -##### via wget - -```bash -bash <(wget https://raw.githubusercontent.com/tboox/xmake/master/scripts/get.sh -O -) -``` - -##### via powershell - -```bash -Invoke-Expression (Invoke-Webrequest 'https://raw.githubusercontent.com/tboox/xmake/master/scripts/get.ps1' -UseBasicParsing).Content -``` - -#### Windows - -##### via installer - -1. Download xmake windows installer from [Releases](https://github.com/xmake-io/xmake/releases) -2. Run xmake-[version].exe - -##### via scoop - -```bash -scoop install xmake -``` - -#### MacOS - -```bash -$ brew install xmake -``` - -#### Linux - -On Archlinux: - -```bash -$ yaourt xmake -``` - -On Ubuntu: - -```bash -$ sudo add-apt-repository ppa:tboox/xmake -$ sudo apt update -$ sudo apt install xmake -``` - -Or add xmake package source manually: - -``` -deb http://ppa.launchpad.net/tboox/xmake/ubuntu yakkety main -deb-src http://ppa.launchpad.net/tboox/xmake/ubuntu yakkety main -``` - -Then we run: - -```bash -$ sudo apt update -$ sudo apt install xmake -``` - -Or download deb package to install it: - -1. Download xmake `.deb` install package from [Releases](https://github.com/xmake-io/xmake/releases) -2. Run `dpkg -i xmake-xxxx.deb` - -#### Compilation - -Compile and install: - -```bash -$ git clone https://github.com/xmake-io/xmake.git -$ cd ./xmake -$ ./scripts/get.sh __local__ -``` - -Only install and update lua scripts: - -```bash -$ ./scripts/get.sh __local__ __install_only__ -``` - -Uninstall: - -```bash -$ ./scripts/get.sh __uninstall__ -``` - -Or compile and install via make: - -```bash -$ make build; sudo make install -``` - -Install to other given directory: - -```bash -$ sudo make install prefix=/usr/local -``` - -Uninstall: - -```bash -$ sudo make uninstall -``` - -#### Update - -We can run `xmake update` to update xmake version after v2.2.3 and we can also update to the given version: - -```bash -$ xmake update 2.2.4 -``` - -We can also specify an update to the master/dev branch version: - -```bash -$ xmake update master -$ xmake update dev -``` - -Finally, if we want to uninstall xmake, it is also supported: `xmake update --uninstall`. - -## Quick Start - -[](https://asciinema.org/a/133693) - -#### Create Project - -```bash -$ xmake create -l c -P ./hello -``` - -And xmake will generate some files for c language project: - -``` -hello -├── src -│ └── main.c -└── xmake.lua -``` - -It is a simple console program only for printing `hello xmake!` - -The content of `xmake.lua` is very simple: - -```lua -target("hello") - set_kind("binary") - add_files("src/*.c") -``` - -Support languages: - -* c/c++ -* objc/c++ -* cuda -* asm -* swift -* dlang -* golang -* rust - -<p class="tip"> - If you want to known more options, please run: `xmake create --help` -</p> - -#### Build Project - -```bash -$ xmake -``` - -#### Run Program - -```bash -$ xmake run hello -``` - -#### Debug Program - -```bash -$ xmake run -d hello -``` - -It will start the debugger (.e.g lldb, gdb, windbg, vsjitdebugger, ollydbg ..) to load our program. - -```bash -[lldb]$target create "build/hello" -Current executable set to 'build/hello' (x86_64). -[lldb]$b main -Breakpoint 1: where = hello`main, address = 0x0000000100000f50 -[lldb]$r -Process 7509 launched: '/private/tmp/hello/build/hello' (x86_64) -Process 7509 stopped -* thread #1: tid = 0x435a2, 0x0000000100000f50 hello`main, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1 - frame #0: 0x0000000100000f50 hello`main -hello`main: --> 0x100000f50 <+0>: pushq %rbp - 0x100000f51 <+1>: movq %rsp, %rbp - 0x100000f54 <+4>: leaq 0x2b(%rip), %rdi ; "hello world!" - 0x100000f5b <+11>: callq 0x100000f64 ; symbol stub for: puts -[lldb]$ -``` - -<p class="tip"> - You can also use short command option, for exmaple: `xmake r` or `xmake run` -</p> - -## Project Examples - -#### Executable Program - -```lua -target("test") - set_kind("binary") - add_files("src/*c") -``` - -#### Static Library Program - -```lua -target("library") - set_kind("static") - add_files("src/library/*.c") - -target("test") - set_kind("binary") - add_files("src/*c") - add_deps("library") -``` - -We use `add_deps` to link a static library to test target. - -#### Share Library Program - -```lua -target("library") - set_kind("shared") - add_files("src/library/*.c") - -target("test") - set_kind("binary") - add_files("src/*c") - add_deps("library") -``` - -We use `add_deps` to link a share library to test target. - -#### Qt Program - -Create an empty project: - -```console -$ xmake create -l c++ -t console_qt test -$ xmake create -l c++ -t static_qt test -$ xmake create -l c++ -t shared_qt test -$ xmake create -l c++ -t quickapp_qt test -``` - -xmake will detect Qt SDK automatically and we can also set the SDK directory manually. - -```console -$ xmake f --qt=~/Qt/Qt5.9.1 -``` - -If you want to use the MinGW Qt environment on windows, you can set the MinGW platform configuration and specify the SDK path for the MinGW compilation environment, for example: - -```console -$ xmake f -p mingw --sdk=C:\Qt\Qt5.10.1\Tools\mingw530_32 -``` - -If you want to known more information, you can see [#160](https://github.com/xmake-io/xmake/issues/160). - -##### Static Library - -```lua -target("qt_static_library") - add_rules("qt.static") - add_files("src/*.cpp") - add_frameworks("QtNetwork", "QtGui") -``` - -##### Shared Library - -```lua -target("qt_shared_library") - add_rules("qt.shared") - add_files("src/*.cpp") - add_frameworks("QtNetwork", "QtGui") -``` - -##### Console Program - -```lua -target("qt_console") - add_rules("qt.console") - add_files("src/*.cpp") -``` - -##### Quick Application - -```lua -target("qt_quickapp") - add_rules("qt.application") - add_files("src/*.cpp") - add_files("src/qml.qrc") - add_frameworks("QtQuick") -``` - -##### Widgets Application - -```lua -target("qt_widgetapp") - add_rules("qt.application") - add_files("src/*.cpp") - add_files("src/mainwindow.ui") - add_files("src/mainwindow.h") -- add files with Q_OBJECT meta (only for qt.moc) - add_frameworks("QtWidgets") -``` - -##### Android Application - -After the 2.2.6 version, you can directly switch to the android platform to compile the Quick/Widgets application, generate the apk package, and install it to the device via the `xmake install` command. - -```console -$ xmake create -t quickapp_qt -l c ++ appdemo -$ cd appdemo -$ xmake f -p android --ndk=~/Downloads/android-ndk-r19c/ --android_sdk=~/Library/Android/sdk/ -c -$ xmake -[0%]: compiling.qt.qrc src/qml.qrc -[ 50%]: ccache compiling.release src/main.cpp -[100%]: linking.release libappdemo.so -[100%]: generating.qt.app appdemo.apk -``` - -Then install to the device: - -```console -$ xmake install -installing appdemo ... -installing build/android/armv7-a/release/appdemo.apk .. -success -install ok!👌 -``` - -#### Cuda Program - -Create an empty project: - -```console -$ xmake create -P test -l cuda -$ cd test -$ xmake -``` - -```lua --- define target -target("cuda_console") - set_kind("binary") - add_files("src/*.cu") - -- generate SASS code for SM architecture of current host - add_cugencodes("native") - -- generate PTX code for the virtual architecture to guarantee compatibility - add_cugencodes("compute_30") -``` - -<p class="tip"> -Starting with v2.2.7, the default build will enable device-link, @see https://devblogs.nvidia.com/separate-compilation-linking-cuda-device-code/ -If you want to disable device-link, you can set it with `add_values("cuda.devlink", false)`. -</p> - -xmake will detect Cuda SDK automatically and we can also set the SDK directory manually. - -```console -$ xmake f --cuda=/usr/local/cuda-9.1/ -$ xmake -``` - -If you want to known more information, you can see [#158](https://github.com/xmake-io/xmake/issues/158). - -#### WDK Driver Program - -xmake will detect WDK automatically and we can also set the WDK directory manually. - -```console -$ xmake f --wdk="G:\Program Files\Windows Kits\10" -c -$ xmake -``` - -If you want to known more information, you can see [#159](https://github.com/xmake-io/xmake/issues/159). - -##### UMDF Driver Program - -```lua -target("echo") - add_rules("wdk.driver", "wdk.env.umdf") - add_files("driver/*.c") - add_files("driver/*.inx") - add_includedirs("exe") - -target("app") - add_rules("wdk.binary", "wdk.env.umdf") - add_files("exe/*.cpp") -``` - -##### KMDF Driver Program - -```lua -target("nonpnp") - add_rules("wdk.driver", "wdk.env.kmdf") - add_values("wdk.tracewpp.flags", "-func:TraceEvents(LEVEL,FLAGS,MSG,...)", "-func:Hexdump((LEVEL,FLAGS,MSG,...))") - add_files("driver/*.c", {rule = "wdk.tracewpp"}) - add_files("driver/*.rc") - -target("app") - add_rules("wdk.binary", "wdk.env.kmdf") - add_files("exe/*.c") - add_files("exe/*.inf") -``` - -##### WDM Driver Program - -```lua -target("kcs") - add_rules("wdk.driver", "wdk.env.wdm") - add_values("wdk.man.flags", "-prefix Kcs") - add_values("wdk.man.resource", "kcsCounters.rc") - add_values("wdk.man.header", "kcsCounters.h") - add_values("wdk.man.counter_header", "kcsCounters_counters.h") - add_files("*.c", "*.rc", "*.man") -``` - -```lua -target("msdsm") - add_rules("wdk.driver", "wdk.env.wdm") - add_values("wdk.tracewpp.flags", "-func:TracePrint((LEVEL,FLAGS,MSG,...))") - add_files("*.c", {rule = "wdk.tracewpp"}) - add_files("*.rc", "*.inf") - add_files("*.mof|msdsm.mof") - add_files("msdsm.mof", {values = {wdk_mof_header = "msdsmwmi.h"}}) -``` - -##### Package Driver - -We can run the following command to generate a .cab driver package. - -```console -$ xmake [p|package] -$ xmake [p|package] -o outputdir -``` - -The output files like: - -``` - - drivers - - sampledsm - - debug/x86/sampledsm.cab - - release/x64/sampledsm.cab - - debug/x86/sampledsm.cab - - release/x64/sampledsm.cab -``` - -##### Driver Signing - -The driver signing is disabled when we compile driver in default case, -but we can add `set_values("wdk.sign.mode")` to enable test/release sign. - -###### TestSign - -We can use test certificate of xmake to do testsign, but please run `$xmake l utils.wdk.testcert` install as admin to install a test certificate first (only once)! - -```lua -target("msdsm") - add_rules("wdk.driver", "wdk.env.wdm") - set_values("wdk.sign.mode", "test") -``` - -Or we set a valid certificate thumbprint to do it in local machine. - -```lua -target("msdsm") - add_rules("wdk.driver", "wdk.env.wdm") - set_values("wdk.sign.mode", "test") - set_values("wdk.sign.thumbprint", "032122545DCAA6167B1ADBE5F7FDF07AE2234AAA") -``` - -We can also do testsign via setting store/company info. - -```lua -target("msdsm") - add_rules("wdk.driver", "wdk.env.wdm") - set_values("wdk.sign.mode", "test") - set_values("wdk.sign.store", "PrivateCertStore") - set_values("wdk.sign.company", "tboox.org(test)") -``` - -###### ReleaseSign - -We can set a certificate file for release signing. - -```lua -target("msdsm") - add_rules("wdk.driver", "wdk.env.wdm") - set_values("wdk.sign.mode", "release") - set_values("wdk.sign.company", "xxxx") - set_values("wdk.sign.certfile", path.join(os.projectdir(), "xxxx.cer")) -``` - -##### Support Low-version System - -We can set `wdk.env.winver` to generate a driver package that is compatible with a low version system. - -```lua -set_values("wdk.env.winver", "win10") -set_values("wdk.env.winver", "win10_rs3") -set_values("wdk.env.winver", "win81") -set_values("wdk.env.winver", "win8") -set_values("wdk.env.winver", "win7") -set_values("wdk.env.winver", "win7_sp1") -set_values("wdk.env.winver", "win7_sp2") -set_values("wdk.env.winver", "win7_sp3") -``` - -We can also set windows version for WDK driver program: - -```console -$ xmake f --wdk_winver=[win10_rs3|win8|win7|win7_sp1] -$ xmake -``` - -#### WinSDK Application Program - -```lua -target("usbview") - add_rules("win.sdk.application") - - add_files("*.c", "*.rc") - add_files("xmlhelper.cpp", {rule = "win.sdk.dotnet"}) -``` - -If you want to known more information, you can see [#173](https://github.com/xmake-io/xmake/issues/173). - -## Configuration - -Set compilation configuration before building project with command `xmake f|config`. - -And if you want to known more options, please run: `xmake f --help`。 - -<p class="tip"> - You can use short or long command option, for exmaple: <br> - `xmake f` or `xmake config`.<br> - `xmake f -p linux` or `xmake config --plat=linux`. -</p> - -#### Target Platforms - -##### Current Host - -```bash -$ xmake -``` - -<p class="tip"> - XMake will detect the current host platform automatically and build project. -</p> - -##### Linux - -```bash -$ xmake f -p linux [-a i386|x86_64] -$ xmake -``` - -##### Android - -```bash -$ xmake f -p android --ndk=~/files/android-ndk-r10e/ [-a armv5te|armv6|armv7-a|armv8-a|arm64-v8a] -$ xmake -``` - -If you want to set the other android toolchains, you can use [--bin](#-bin) option. - -For example: - -```bash -$ xmake f -p android --ndk=~/files/android-ndk-r10e/ -a arm64-v8a --bin=~/files/android-ndk-r10e/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin -``` - -The [--bin](#-bin) option is used to set `bin` directory of toolchains. - -<p class="tip"> -Please attempt to set `--arch=` option if it had failed to check compiler. -</p> - -##### iPhoneOS - -```bash -$ xmake f -p iphoneos [-a armv7|armv7s|arm64|i386|x86_64] -$ xmake -``` - -##### Windows - -```bash -$ xmake f -p windows [-a x86|x64] -$ xmake -``` - -##### Mingw - -```bash -$ xmake f -p mingw --sdk=/usr/local/i386-mingw32-4.3.0/ [-a i386|x86_64] -$ xmake -``` - -##### Apple WatchOS - -```bash -$ xmake f -p watchos [-a i386|armv7k] -$ xmake -``` - -##### Cross Compilation - -For linux platform: - -```bash -$ xmake f -p linux --sdk=/usr/local/arm-linux-gcc/ [--bin=/sdk/bin] [--cross=arm-linux-] -$ xmake -``` - -Fro other cross platform: - -```bash -$ xmake f -p cross --sdk=/usr/local/arm-xxx-gcc/ [--bin=/sdk/bin] [--cross=arm-linux-] -$ xmake -``` - -For custem cross platform (`is_plat("myplat")`): - -```bash -$ xmake f -p myplat --sdk=/usr/local/arm-xxx-gcc/ [--bin=/sdk/bin] [--cross=arm-linux-] -$ xmake -``` - -| Configuration Option | Description | -| ---------------------------- | -------------------------------------------- | -| [--sdk](#-sdk) | Set the sdk root directory of toolchains | -| [--bin](#-bin) | Set the `bin` directory of toolchains | -| [--cross](#-cross) | Set the prefix of compilation tools | -| [--as](#-as) | Set `asm` assembler | -| [--cc](#-cc) | Set `c` compiler | -| [--cxx](#-cxx) | Set `c++` compiler | -| [--mm](#-mm) | Set `objc` compiler | -| [--mxx](#-mxx) | Set `objc++` compiler | -| [--sc](#-sc) | Set `swift` compiler | -| [--gc](#-gc) | Set `golang` compiler | -| [--dc](#-dc) | Set `dlang` compiler | -| [--rc](#-rc) | Set `rust` compiler | -| [--cu](#-cu) | Set `cuda` compiler | -| [--ld](#-ld) | Set `c/c++/objc/asm` linker | -| [--sh](#-sh) | Set `c/c++/objc/asm` shared library linker | -| [--ar](#-ar) | Set `c/c++/objc/asm` static library archiver | -| [--sc-ld](#-sc-ld) | Set `swift` linker | -| [--sc-sh](#-sc-sh) | Set `swift` shared library linker | -| [--gc-ld](#-gc-ld) | Set `golang` linker | -| [--gc-ar](#-gc-ar) | Set `golang` static library archiver | -| [--dc-ld](#-dc-ld) | Set `dlang` linker | -| [--dc-sh](#-dc-sh) | Set `dlang` shared library linker | -| [--dc-ar](#-dc-ar) | Set `dlang` static library archiver | -| [--rc-ld](#-rc-ld) | Set `rust` linker | -| [--rc-sh](#-rc-sh) | Set `rust` shared library linker | -| [--rc-ar](#-rc-ar) | Set `rust` static library archiver | -| [--cu-cxx](#-cu-cxx) | Set `cuda` host compiler | -| [--cu-ld](#-cu-ld) | Set `cuda` linker | -| [--asflags](#-asflags) | Set `asm` assembler option | -| [--cflags](#-cflags) | Set `c` compiler option | -| [--cxflags](#-cxflags) | Set `c/c++` compiler option | -| [--cxxflags](#-cxxflags) | Set `c++` compiler option | -| [--mflags](#-mflags) | Set `objc` compiler option | -| [--mxflags](#-mxflags) | Set `objc/c++` compiler option | -| [--mxxflags](#-mxxflags) | Set `objc++` compiler option | -| [--scflags](#-scflags) | Set `swift` compiler option | -| [--gcflags](#-gcflags) | Set `golang` compiler option | -| [--dcflags](#-dcflags) | Set `dlang` compiler option | -| [--rcflags](#-rcflags) | Set `rust` compiler option | -| [--cuflags](#-cuflags) | Set `cuda` compiler option | -| [--ldflags](#-ldflags) | Set linker option | -| [--shflags](#-shflags) | Set shared library linker option | -| [--arflags](#-arflags) | Set static library archiver option | - -<p class="tip"> -if you want to known more options, please run: `xmake f --help`。 -</p> - -###### --sdk - -- Set the sdk root directory of toolchains - -xmake provides a convenient and flexible cross-compiling support. -In most cases, we need not to configure complex toolchains prefix, for example: `arm-linux-` - -As long as this toolchains meet the following directory structure: - -``` -/home/toolchains_sdkdir - - bin - - arm-linux-gcc - - arm-linux-ld - - ... - - lib - - libxxx.a - - include - - xxx.h -``` - -Then,we can only configure the sdk directory and build it. - -```bash -$ xmake f -p linux --sdk=/home/toolchains_sdkdir -$ xmake -``` - -xmake will detect the prefix: arm-linux- and add the include and library search directory automatically. - -``` --I/home/toolchains_sdkdir/include -L/home/toolchains_sdkdir/lib -``` - -###### --bin - -- Set the `bin` directory of toolchains - -We need set it manually if the toolchains /bin directory is in other places, for example: - -```bash -$ xmake f -p linux --sdk=/home/toolchains_sdkdir --bin=/usr/opt/bin -$ xmake -``` - -<p class="tip"> -Before v2.2.1 version, this parameter name is `--toolchains`, exists more ambiguous, so we changed to `--bin=` to set the bin directory. -</p> - -###### --cross - -- Set the prefix of compilation tools - -For example, under the same toolchains directory at the same time, there are two different compilers: - -``` -/opt/bin - - armv7-linux-gcc - - aarch64-linux-gcc -``` - -If we want to use the `armv7-linux-gcc` compiler, we can run the following command: - -```bash -$ xmake f -p linux --sdk=/usr/toolsdk --bin=/opt/bin --cross=armv7-linux- -``` - -###### --as - -- Set `asm` assembler - -```bash -$ xmake f -p linux --sdk=/user/toolsdk --as=armv7-linux-as -``` - -If the 'AS' environment variable exists, it will use the values specified in the current environment variables. - -<p class="tip"> -We can set a unknown compiler as like-gcc/clang compiler, .e.g `xmake f --as=gcc@/home/xxx/asmips.exe` -</p> - -###### --cc - -- Set c compiler - -```bash -$ xmake f -p linux --sdk=/user/toolsdk --cc=armv7-linux-clang -``` - -If the 'CC' environment variable exists, it will use the values specified in the current environment variables. - -<p class="tip"> -We can set a unknown compiler as like-gcc/clang compiler, .e.g `xmake f --cc=gcc@/home/xxx/ccmips.exe` -</p> - -###### --cxx - -- Set `c++` compiler - -```bash -$ xmake f -p linux --sdk=/user/toolsdk --cxx=armv7-linux-clang++ -``` - -If the 'CXX' environment variable exists, it will use the values specified in the current environment variables. - -<p class="tip"> -We can set a unknown compiler as like-gcc/clang compiler, .e.g `xmake f --cxx=g++@/home/xxx/c++mips.exe` -</p> - -###### --ld - -- Set `c/c++/objc/asm` linker - -```bash -$ xmake f -p linux --sdk=/user/toolsdk --ld=armv7-linux-clang++ -``` - -If the 'LD' environment variable exists, it will use the values specified in the current environment variables. - -<p class="tip"> -We can set a unknown compiler as like-gcc/clang linker, .e.g `xmake f --ld=g++@/home/xxx/c++mips.exe` -</p> - -###### --sh - -- Set `c/c++/objc/asm` shared library linker - -```bash -$ xmake f -p linux --sdk=/user/toolsdk --sh=armv7-linux-clang++ -``` - -If the 'SH' environment variable exists, it will use the values specified in the current environment variables. - -<p class="tip"> -We can set a unknown compiler as like-gcc/clang linker, .e.g `xmake f --sh=g++@/home/xxx/c++mips.exe` -</p> - -###### --ar - -- Set `c/c++/objc/asm` static library archiver - -```bash -$ xmake f -p linux --sdk=/user/toolsdk --ar=armv7-linux-ar -``` - -If the 'AR' environment variable exists, it will use the values specified in the current environment variables. - -<p class="tip"> -We can set a unknown compiler as like-ar archiver, .e.g `xmake f --ar=ar@/home/xxx/armips.exe` -</p> - -#### Global Configuration - -You can save to the global configuration for simplfying operation. - -For example: - -```bash -$ xmake g --ndk=~/files/android-ndk-r10e/ -``` - -Now, we config and build project for android again. - -```bash -$ xmake f -p android -$ xmake -``` - -<p class="tip"> - You can use short or long command option, for exmaple: `xmake g` or `xmake global`.<br> -</p> - -#### Clean Configuration - -We can clean all cached configuration and re-configure projecct. - -```bash -$ xmake f -c -$ xmake -``` - -or - -```bash -$ xmake f -p iphoneos -c -$ xmake -``` - -## Syntax Description - -xmake's project description file xmake.lua is based on the lua syntax, but in order to make the project build logic more convenient and concise, xmake encapsulates it, making writing xmake.lua not as cumbersome as some makefiles. - -Basically write a simple project build description, just three lines, for example: - -```lua -target("test") - set_kind("binary") - add_files("src/*.c") -``` - -#### Scope - -The description syntax of xmake is divided by scope, which is mainly divided into: - -- external scope -- Internal scope -- Interface scope - -Which ones belong to the outside and which ones belong to the inside? if you look at the comments below, you know what it is: - -```lua --- external scope -target("test") - - -- external scope - set_kind("binary") - add_files("src/*.c") - - on_run(function () - -- Internal scope - end) - - after_package(function () - -- Internal scope - end) - --- external scope -task("hello") - - -- external scope - on_run(function () - -- Internal scope - end) -``` - -Simply put, all within the custom script `function () end` belongs to the internal scope, which is the script scope, and all other places belong to the external scope. . - -##### external Scope - -For most projects, you don't need complicated engineering descriptions, and you don't need custom scripting support. You just need a simple `set_xxx` or `add_xxx` to meet your needs. - -Then according to the 28th law, 80% of the cases, we only need to write: - -```lua -target("test") - set_kind("static") - add_files("src/test/*.c") - -target("demo") - add_deps("test") - set_kind("binary") - add_links("test") - add_files("src/demo/*.c") -``` - -No complicated api calls, no complicated variable definitions, and if judgments and for loops. It's succinct and readable. At a glance, it doesn't matter if you don't understand lua grammar. - -As a simple description of the syntax, it looks a bit like a function call, you will know how to configure it at a basic point of programming. - -In order to be concise and secure, in this scope, many lua built-in apis are not open, especially related to writing files and modifying the operating environment, only providing some basic read-only interfaces, and logical operations. - -The current external scope lating lua built-in apis are: - -- table -- string -- pairs -- ipairs -- print -- os - -Of course, although the built-in lua api does not provide much, xmake also provides a lot of extension APIs. It is not much to describe the api. For details, please refer to: [API Manual] (https://xmake.io/#/zh/manual) - -There are also some auxiliary apis, for example: - -- dirs: scan to get all the directories in the currently specified path -- files: scan to get all the files in the current specified path -- format: format string, short version of string.format - -There are also variable definitions and logical operations that can be used. after all, it is based on lua. The basic syntax is still there. We can switch the compiled files by if: - -```lua -target("test") - set_kind("static") - if is_plat("iphoneos") then - add_files("src/test/ios/*.c") - else - add_files("src/test/*.c") - end -``` - -It should be noted that the variable definition is divided into global variables and local variables. The local variables are only valid for the current xmake.lua, and do not affect the child xmake.lua. - -```lua --- local variables, only valid for current xmake.lua -local var1 = 0 - --- global variables that affect all subsmake.lua included after includes() -var2 = 1 - -Includes("src") -``` - -##### Internal Scope - -Also known as plug-ins, script scope, provide more complex and flexible script support, generally used to write some custom scripts, plug-in development, custom task tasks, custom modules, etc. - -Usually included by `function () end`, and passed to the `on_xxx`, `before_xxx` and `after_xxx` interfaces, are all self-scoped. - -E.g: - -```lua --- custom script -target("hello") - after_build(function () - -- Internal scope - end) - --- custom tasks, plugins -task("hello") - on_run(function () - -- Internal scope - end) -``` - -In this scope, not only can you use most lua apis, but you can also use many extension modules provided by xmake. All extension modules are imported through import. - -For details, please refer to: [import module document](https://xmake.io/#/zh/manual?id=import) - -Here we give a simple example, after the compilation is complete, ldid signature on the ios target program: - -```lua -target("iosdemo") - set_kind("binary") - add_files("*.m") - after_build(function (target) - - -- Execute signature, if it fails, automatically interrupt, giving a highlight error message - Os.run("ldid -S$(projectdir)/entitlements.plist %s", target:targetfile()) - end) -``` - -It should be noted that in the internal scope, all calls are enabled with the exception catching mechanism. if the operation is wrong, xmake will be automatically interrupted and an error message will be given. - -Therefore, the script is written without the cumbersome `if retval then` judgment, and the script logic is more clear. - -##### Interface Scope - -All descriptions of api settings in the external scope are also scoped. They are called in different places and have different scopes of influence, for example: - -```lua --- global root scope, affecting all targets, including subproject target settings in includes() -add_defines("DEBUG") - --- define or enter the demo target scope (support multiple entry to append settings) -target("demo") - set_kind("shared") - add_files("src/*.c") - -- the current target scope only affects the current target - add_defines("DEBUG2") - --- option settings, only local settings are supported, not affected by global api settings -option("test") - -- local scope of the current option - set_default(false) - --- other target settings, -DDEBUG will also be set -target("demo2") - set_kind("binary") - add_files("src/*.c") - --- re-enter the demo target scope -target("demo") - -- append macro definitions, only valid for the current demo target - add_defines("DEBUG3") -``` - -Normally, entering another target/option domain setting will automatically leave the previous target/option field, but sometimes in order to compare some scope pollution, we can show off a domain, for example: - -```lua -option("test") - set_default(false) -option_end() - -target("demo") - set_kind("binary") - add_files("src/*.c") -target_end() -``` - -Call `option_end()`, `target_end()` to explicitly leave the current target/option field setting. - -##### Scope indentation - -Indentation in xmake.lua is just a specification for more clear distinction. The current setting is for that scope, although it is ok even if it is not indented, but it is not very readable. . - -e.g: - -```lua -target("xxxx") - set_kind("binary") - add_files("*.c") -``` - -with - -```lua -target("xxxx") -set_kind("binary") -add_files("*.c") -``` - -The above two methods are the same in effect, but in understanding, the first one is more intuitive. At first glance, you know that `add_files` is only set for target, not global. - -Therefore, proper indentation helps to better maintain xmake.lua - -Finally attached, tbox's [xmake.lua](https://github.com/tboox/tbox/blob/master/src/tbox/xmake.lua) description, for reference only. . - -#### Syntax simplification - -The configuration field syntax of xmake.lua is very flexible and can be used in a variety of complex and flexible configurations in the relevant domain, but for many streamlined small block configurations, this time is slightly redundant: - -```lua -option("test1") - set_default(true) - set_showmenu(true) - set_description("test1 option") - -option("test2") - set_default(true) - set_showmeu(true) - -option("test3") - set_default("hello") -``` - -xmake 2.2.6 or later, for the above small block option domain settings, we can simplify the description into a single line: - -```lua -option("test1", {default = true, showmenu = true, description = "test1 option"}) -option("test2", {default = true, showmenu = true}) -option("test3", {default = "hello"}) -``` - -In addition to the option field, this simplified writing is also supported for other domains, such as: - -```lua -target("demo") - set_kind("binary") - add_files("src/*.c") -``` - -Simplified to: - -```lua -target("demo", {kind = "binary", files = "src/*.c"}) -``` - -Of course, if the configuration requirements are more complicated, or the original multi-line setting method is more convenient, this depends on your own needs to evaluate which method is used. - -## Dependency Package Management - -#### Local Package Mode - -By including a dependency package directory and a binary package file in the project, it is convenient to integrate some third-party dependency libraries. This method is relatively simple and straightforward, but the disadvantages are also obvious and inconvenient to manage. - -Take the tbox project as an example. The dependency package is as follows: - -``` -- base.pkg -- zlib.pkg -- polarssl.pkg -- openssl.pkg -- mysql.pkg -- pcre.pkg -- ... -``` - -If you want the current project to recognize loading these packages, you first need to specify the package directory path, for example: - -```lua -add_packagedirs("packages") -``` - -Once specified, you can add integration package dependencies in the target scope via the [add_packages](https://xmake.io/#/zh/manual?id=targetadd_packages) interface, for example: - -```lua -target("tbox") - add_packages("zlib", "polarssl", "pcre", "mysql") -``` - -So how to generate a *.pkg package, if it is based on xmake project, the generation method is very simple, only need: - -```console -$ cd tbox -$ xmake package -``` - -You can generate a tbox.pkg cross-platform package in the build directory for use by third-party projects. I can also directly set the output directory and compile and generate it into the other project, for example: - -```console -$ cd tbox -$ xmake package -o ../test/packages -``` - -In this way, the test project can pass [add_packages](https://xmake.io/#/zh/manual?id=targetadd_packages) and [add_packagedirs](https://xmake.io/#/zh/manual?id= add_packagedirs) to configure and use the tbox.pkg package. - -For a detailed description of the built-in package, you can also refer to the following related article, which is described in detail: [Dependency package addition and automatic detection mechanism](https://tboox.org/cn/2016/08/06/add-package-and-autocheck/) - -#### System Search Mode - -If you feel that the above built-in package management method is very inconvenient, you can use the extension interface [lib.detect.find_package] provided by xmake (https://xmake.io/#/zh/manual?id=detect-find_package) to find the system. Existing dependencies. - -Currently this interface supports the following package management support: - -* vcpkg -* homebrew -* pkg-config - -And through the system and third-party package management tools for the installation of the dependency package, and then integrated with xmake, for example, we look for an openssl package: - -```lua -local packages = find_packages("openssl", "zlib") -``` - -The returned results are as follows: - -```lua -{ - {links = {"ssl", "crypto"}, linkdirs = {"/usr/local/lib"}, includedirs = {"/usr/local/include"}}, - {links = {"z"}, linkdirs = {"/usr/local/lib"}, includedirs = {"/usr/local/include"}} -} -``` - -If the search is successful, return a table containing all the package information, if it fails, return nil - -The return result here can be directly passed as the parameter of `target:add`, `option:add`, which is used to dynamically increase the configuration of `target/option`: - -```lua -option("zlib") - set_showmenu(true) - before_check(function (option) - option:add(find_packages("openssl", "zlib")) - end) -``` - -```lua -target("test") - on_load(function (target) - target:add(find_packages("openssl", "zlib")) - end) -``` - -If third-party tools such as `homebrew`, `pkg-config` are installed on the system, then this interface will try to use them to improve the search results. - -For a more complete description of the usage, please refer to the [find_packages](https://xmake.io/#/en/manual?id=find_packages) interface documentation. - -##### Homebrew Integration Support - -Since homebrew is generally installed directly into the system, users do not need to do any integration work, `lib.detect.find_package` has been natively seamlessly supported. - -##### Vcpkg Integration Support - -Currently xmake v2.2.2 version already supports vcpkg, users only need to install vcpkg, execute `$ vcpkg integrate install`, xmake will automatically detect the root path of vcpkg from the system, and then automatically adapt the bread. - -Of course, we can also manually specify the root path of vcpkg to support: - -```console -$ xmake f --vcpkg=f:\vcpkg -``` - -Or we can set it to the global configuration to avoid repeating the settings each time we switch configurations: - -```console -$ xmake g --vcpkg=f:\vcpkg -``` - -#### Remote dependency mode - -This has been initially supported after the 2.2.2 version, the usage is much simpler, just set the corresponding dependency package, for example: - -```lua -add_requires("tbox 1.6.*", "libpng ~1.16", "zlib") - -target("test") - set_kind("binary") - add_files("src/*.c") - add_packages("tbox", "libpng", "zlib") -``` - -The above `add_requires` is used to describe the dependencies required by the current project, and `add_packages` is used to apply dependencies to the test target. Only settings will automatically add links, linkdirs, includedirs, etc. - -Then directly compile: - -```console -$ xmake -``` - -xmake will remotely pull the relevant source package, then automatically compile and install, finally compile the project, and link the dependency package. The specific effect is shown in the following figure: - -<img src="/assets/img/index/package_manage.png" width="80%" /> - -For more information and progress on package dependency management see the related issues: [Remote package management](https://github.com/xmake-io/xmake/issues/69) - -##### Currently Supported Features - -* Semantic version support, for example: ">= 1.1.0 < 1.2", "~1.6", "1.2.x", "1.*" -* Provide multi-warehouse management support such as official package warehouse, self-built private warehouse, project built-in warehouse, etc. -* Cross-platform package compilation integration support (packages of different platforms and different architectures can be installed at the same time, fast switching use) -* Debug dependency package support, source code debugging - -##### Dependency Package Processing Mechanism - -Here we briefly introduce the processing mechanism of the entire dependency package: - -<div align="center"> -<img src="/assets/img/index/package_arch.png" width="80%" /> -</div> - -1. Priority check for the current system directory, whether there is a specified package under the third-party package management, if there is a matching package, then you do not need to download and install (of course you can also set the system package) -2. Retrieve the package matching the corresponding version, then download, compile, and install (Note: installed in a specific xmake directory, will not interfere with the system library environment) -3. Compile the project, and finally automatically link the enabled dependencies - -##### Semantic Version Settings - -Xmake's dependency package management fully supports semantic version selection, for example: "~1.6.1". For a detailed description of the semantic version, see: [https://semver.org/](https://semver.org/) - -Some semantic versions are written: - -```lua -add_requires("tbox 1.6.*", "pcre 1.3.x", "libpng ^1.18") -add_requires("libpng ~1.16", "zlib 1.1.2 || >=1.2.11 <1.3.0") -``` - -The semantic version parser currently used by xmake is the [sv](https://github.com/uael/sv) library contributed by [uael](https://github.com/uael), which also has a description of the version. For detailed instructions, please refer to the following: [Version Description](https://github.com/uael/sv#versions) - -Of course, if we have no special requirements for the current version of the dependency package, then we can write directly: - -```lua -add_requires("tbox", "libpng", "zlib") -``` - -This will use the latest version of the package known, or the source code compiled by the master branch. If the current package has a git repo address, we can also specify a specific branch version: - -```lua -add_requires("tbox master") -add_requires("tbox dev") -``` - -##### Extra Package Information Settings - -###### Optional Package Settings - -If the specified dependency package is not supported by the current platform, or if the compilation and installation fails, then xmake will compile the error, which is reasonable for some projects that must rely on certain packages to work. -However, if some packages are optional dependencies, they can be set to optional packages even if they are not compiled properly. - -```lua -add_requires("tbox", {optional = true}) -``` - -###### Disable System Library - -With the default settings, xmake will first check to see if the system library exists (if no version is required). If the user does not want to use the system library and the library provided by the third-party package management, then you can set: - -```lua -add_requires("tbox", {system = false}) -``` - -###### Using the debug version of the package - -If we want to debug the dependencies at the same time, we can set them to use the debug version of the package (provided that this package supports debug compilation): - -```lua -add_requires("tbox", {debug = true}) -``` - -If the current package does not support debug compilation, you can submit the modified compilation rules in the repository to support the debug, for example: - -```lua -package("openssl") - on_install("linux", "macosx", function (package) - os.vrun("./config %s --prefix=\"%s\"", package:debug() and "--debug" or "", package:installdir()) - os.vrun("make -j4") - os.vrun("make install") - end) -``` - -###### Passing additional compilation information to the package - -Some packages have various compile options at compile time, and we can pass them in. Of course, the package itself supports: - -```lua -add_requires("tbox", {configs = {small=true}}) -``` - -Pass `--small=true` to the tbox package so that compiling the installed tbox package is enabled. - -##### Install third-party packages - -After version 2.2.5, xmake supports support for dependency libraries in third-party package managers, such as: conan, brew, vcpkg, etc. - -Add a homebrew dependency package: - -```lua -add_requires("brew::zlib", {alias = "zlib"}}) -add_requires("brew::pcre2/libpcre2-8", {alias = "pcre2"}}) - -target("test") - set_kind("binary") - add_files("src/*.c") - add_packages("pcre2", "zlib") -``` - -Add a dependency package for vcpkg: - -```lua -add_requires("vcpkg::zlib", "vcpkg::pcre2") - -target("test") - set_kind("binary") - add_files("src/*.c") - add_packages("vcpkg::zlib", "vcpkg::pcre2") -``` - -Add a conan dependency package: - -```lua -add_requires("CONAN::zlib/1.2.11@conan/stable", {alias = "zlib", debug = true}) -add_requires("CONAN::OpenSSL/1.0.2n@conan/stable", {alias = "openssl", - configs = {options = "OpenSSL:shared=True"}}) - -target("test") - set_kind("binary") - add_files("src/*.c") - add_packages("openssl", "zlib") -``` - -After executing xmake to compile: - -```console -ruki:test_package ruki$ xmake -checking for the architecture ... x86_64 -checking for the Xcode directory ... /Applications/Xcode.app -checking for the SDK version of Xcode ... 10.14 -note: try installing these packages (pass -y to skip confirm)? - -> CONAN::zlib/1.2.11@conan/stable (debug) - -> CONAN::OpenSSL/1.0.2n@conan/stable -please input: y (y/n) - - => installing CONAN::zlib/1.2.11@conan/stable .. ok - => installing CONAN::OpenSSL/1.0.2n@conan/stable .. ok - -[ 0%]: ccache compiling.release src/main.c -[100%]: linking.release test -``` - -##### Using self-built private package warehouse - -If the required package is not in the official repository [xmake-repo](https://github.com/xmake-io/xmake-repo), we can submit the contribution code to the repository for support. -But if some packages are only for personal or private projects, we can create a private repository repo. The repository organization structure can be found at: [xmake-repo](https://github.com/xmake-io/xmake-repo) - -For example, now we have a private repository repo:`git@github.com:myrepo/xmake-repo.git` - -We can add the repository with the following command: - -```console -$ xmake repo --add myrepo git@github.com:myrepo/xmake-repo.git -``` - -Starting with v2.2.3, support for adding repos for specified branches, for example: - -```console -$ xmake repo --add myrepo git@github.com:myrepo/xmake-repo.git dev -``` - -Or we write directly in xmake.lua: - -```lua -add_repositories("my-repo git@github.com:myrepo/xmake-repo.git") -``` - -If we just want to add one or two private packages, this time to build a git repo is too big, we can directly put the package repository into the project, for example: - -``` -projectdir - - myrepo - - packages - - t/tbox/xmake.lua - - z/zlib/xmake.lua - - src - - main.c - - xmake.lua -``` - -The above myrepo directory is your own private package repository, built into your own project, and then add this repository location in xmake.lua: - -```lua -add_repositories("my-repo myrepo") -``` - -This can be referred to [benchbox](https://github.com/tboox/benchbox) project, which has a built-in private repository. - -We can even build a package without directly building a package description into the project xmake.lua, which is useful for relying on one or two packages, for example: - -```lua -package("libjpeg") - - set_urls("http://www.ijg.org/files/jpegsrc.$(version).tar.gz") - - add_versions("v9c", "650250979303a649e21f87b5ccd02672af1ea6954b911342ea491f351ceb7122") - - on_install("windows", function (package) - os.mv("jconfig.vc", "jconfig.h") - os.vrun("nmake -f makefile.vc") - os.cp("*.h", package:installdir("include")) - os.cp("libjpeg.lib", package:installdir("lib")) - end) - - on_install("macosx", "linux", function (package) - import("package.tools.autoconf").install(package) - end) - -package_end() - -add_requires("libjpeg") - -target("test") - set_kind("binary") - add_files("src/*.c") - add_packages("libjpeg") -``` - -##### Package Management Command Use - -The package management command `$ xmake require` can be used to manually display the download, install, uninstall, retrieve, and view package information. - -###### Install the specified package - -```console -$ xmake require tbox -``` - -Install the specified version package: - -```console -$ xmake require tbox "~1.6" -``` - -Force a re-download of the installation and display detailed installation information: - -```console -$ xmake require -f -v tbox "1.5.x" -``` - -Pass additional setup information: - -```console -$ xmake require --extra="debug=true,config={small=true}" tbox -``` - -Install the debug package and pass the compilation configuration information of `small=true` to the package. - -###### Uninstalling the specified package - -```console -$ xmake require --uninstall tbox -``` - -This will completely uninstall the removal package file. - -###### View package details - -```console -$ xmake require --info tbox -``` - -###### Search for packages in the current warehouse - -```console -$ xmake require --search tbox -``` - -This is to support fuzzy search and lua pattern matching search: - -```console -$ xmake require --search pcr -``` - -Will also search for pcre, pcre2 and other packages. - -###### List the currently installed packages - -```console -$ xmake require --list -``` - -##### Warehouse Management Command Use - -As mentioned above, adding a private repository is available (supporting local path addition): - -```console -$ xmake repo --add myrepo git@github.com:myrepo/xmake-repo.git -``` - -We can also remove a repository that has already been installed: - -```console -$ xmake repo --remove myrepo -``` - -Or view all the added warehouses: - -```console -$ xmake repo --list -``` - -If the remote repository has updates, you can manually perform a warehouse update to get more and the latest packages: - -```console -$ xmake repo -u -``` - -##### Submit the package to the official warehouse - -If you need a package that is not supported by the current official repository, you can commit it to the official repository after local tuning: [xmake-repo](https://github.com/xmake-io/xmake-repo) - -For detailed contribution descriptions, see: [CONTRIBUTING.md](https://github.com/xmake-io/xmake-repo/blob/master/CONTRIBUTING.md) - -## FAQ - -#### How to get verbose command-line arguments info? - -Get the help info of the main command. - -```bash -$ xmake [-h|--help] -``` - -Get the help info of the configuration command. - -```bash -$ xmake f [-h|--help] -``` - -Get the help info of the givent action or plugin command. - -```bash -$ xmake [action|plugin] [-h|--help] -``` - -For example: - -```bash -$ xmake run --help -``` - -#### How to suppress all output info? - -```bash -$ xmake [-q|--quiet] -``` - -#### How to do if xmake fails? - -Please attempt to clean configuration and rebuild it first. - -```bash -$ xmake f -c -$ xmake -``` - -If it fails again, please add `-v` or `--verbose` options to get more verbose info. - -For exmaple: - -```hash -$ xmake [-v|--verbose] -``` - -And add `--backtrace` to get the verbose backtrace info, then you can submit these infos to [issues](https://github.com/xmake-io/xmake/issues). - -```bash -$ xmake -v --backtrace -``` - -#### How to see verbose compiling warnings? - -```bash -$ xmake [-w|--warning] -``` - -#### How to scan source code and generate xmake.lua automaticlly - -You only need run the following command: - -```bash -$ xmake -``` - -xmake will scan all source code in current directory and build it automaticlly. - -And we can run it directly. - -```bash -$ xmake run -``` - -If we only want to generate xmake.lua file, we can run: - -```bash -$ xmake f -y -``` - -If you want to known more information please see [Scan source codes and build project without makefile](https://tboox.org/2017/01/07/build-without-makefile/) - -## Backers - -Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/xmake#backer)] - -<a href="https://opencollective.com/xmake#backers" target="_blank"><img src="https://opencollective.com/xmake/backers.svg?width=890"></a> - -## Sponsors - -Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/xmake#sponsor)] - -<a href="https://opencollective.com/xmake/sponsor/0/website" target="_blank"><img src="https://opencollective.com/xmake/sponsor/0/avatar.svg"></a> -<a href="https://opencollective.com/xmake/sponsor/1/website" target="_blank"><img src="https://opencollective.com/xmake/sponsor/1/avatar.svg"></a> -<a href="https://opencollective.com/xmake/sponsor/2/website" target="_blank"><img src="https://opencollective.com/xmake/sponsor/2/avatar.svg"></a> -<a href="https://opencollective.com/xmake/sponsor/3/website" target="_blank"><img src="https://opencollective.com/xmake/sponsor/3/avatar.svg"></a> -<a href="https://opencollective.com/xmake/sponsor/4/website" target="_blank"><img src="https://opencollective.com/xmake/sponsor/4/avatar.svg"></a> -<a href="https://opencollective.com/xmake/sponsor/5/website" target="_blank"><img src="https://opencollective.com/xmake/sponsor/5/avatar.svg"></a> -<a href="https://opencollective.com/xmake/sponsor/6/website" target="_blank"><img src="https://opencollective.com/xmake/sponsor/6/avatar.svg"></a> -<a href="https://opencollective.com/xmake/sponsor/7/website" target="_blank"><img src="https://opencollective.com/xmake/sponsor/7/avatar.svg"></a> -<a href="https://opencollective.com/xmake/sponsor/8/website" target="_blank"><img src="https://opencollective.com/xmake/sponsor/8/avatar.svg"></a> -<a href="https://opencollective.com/xmake/sponsor/9/website" target="_blank"><img src="https://opencollective.com/xmake/sponsor/9/avatar.svg"></a> - - diff --git a/old/zh/README.md b/old/zh/README.md deleted file mode 100644 index 4d08bda5..00000000 --- a/old/zh/README.md +++ /dev/null @@ -1,1888 +0,0 @@ - -<p> -<div align="center"> - <a href="https://xmake.io/cn"> - <img width="200" heigth="200" src="https://tboox.org/static/img/xmake/logo256c.png"> - </a> - - <h1>xmake</h1> - - <div> - <a href="https://travis-ci.org/xmake-io/xmake"> - <img src="https://img.shields.io/travis/xmake-io/xmake/master.svg?style=flat-square" alt="travis-ci" /> - </a> - <a href="https://ci.appveyor.com/project/waruqi/xmake/branch/master"> - <img src="https://img.shields.io/appveyor/ci/waruqi/xmake/master.svg?style=flat-square" alt="appveyor-ci" /> - </a> - <a href="https://aur.archlinux.org/packages/xmake"> - <img src="https://img.shields.io/aur/votes/xmake.svg?style=flat-square" alt="AUR votes" /> - </a> - <a href="https://github.com/xmake-io/xmake/releases"> - <img src="https://img.shields.io/github/release/xmake-io/xmake.svg?style=flat-square" alt="Github All Releases" /> - </a> - </div> - <div> - <a href="https://github.com/xmake-io/xmake/blob/master/LICENSE.md"> - <img src="https://img.shields.io/github/license/xmake-io/xmake.svg?colorB=f48041&style=flat-square" alt="license" /> - </a> - <a href="https://www.reddit.com/r/tboox/"> - <img src="https://img.shields.io/badge/chat-on%20reddit-ff3f34.svg?style=flat-square" alt="Reddit" /> - </a> - <a href="https://gitter.im/tboox/tboox?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge"> - <img src="https://img.shields.io/gitter/room/tboox/tboox.svg?style=flat-square&colorB=96c312" alt="Gitter" /> - </a> - <a href="https://t.me/tbooxorg"> - <img src="https://img.shields.io/badge/chat-on%20telegram-blue.svg?style=flat-square" alt="Telegram" /> - </a> - <a href="https://jq.qq.com/?_wv=1027&k=5hpwWFv"> - <img src="https://img.shields.io/badge/chat-on%20QQ-ff69b4.svg?style=flat-square" alt="QQ" /> - </a> - <a href="https://xmake.io/pages/donation.html#donate"> - <img src="https://img.shields.io/badge/donate-us-orange.svg?style=flat-square" alt="Donate" /> - </a> - </div> - - <p>一个基于Lua的轻量级跨平台自动构建工具</p> -</div> -</p> - -## 简介 - -XMake是一个基于Lua的轻量级跨平台自动构建工具,支持在各种主流平台上构建项目 - -xmake的目标是开发者更加关注于项目本身开发,简化项目的描述和构建,并且提供平台无关性,使得一次编写,随处构建 - -它跟cmake、automake、premake有点类似,但是机制不同,它默认不会去生成IDE相关的工程文件,采用直接编译,并且更加的方便易用 -采用lua的工程描述语法更简洁直观,支持在大部分常用平台上进行构建,以及交叉编译 - -并且xmake提供了创建、配置、编译、打包、安装、卸载、运行等一些actions,使得开发和构建更加的方便和流程化。 - -不仅如此,它还提供了许多更加高级的特性,例如插件扩展、脚本宏记录、批量打包、自动文档生成等等。。 - -## 安装 - -#### Master版本 - -##### 使用curl - -```bash -bash <(curl -fsSL https://raw.githubusercontent.com/tboox/xmake/master/scripts/get.sh) -``` - -##### 使用wget - -```bash -bash <(wget https://raw.githubusercontent.com/tboox/xmake/master/scripts/get.sh -O -) -``` - -##### 使用powershell - -```bash -Invoke-Expression (Invoke-Webrequest 'https://raw.githubusercontent.com/tboox/xmake/master/scripts/get.ps1' -UseBasicParsing).Content -``` - -#### Windows - -##### 使用安装包 - -1. 从 [Releases](https://github.com/xmake-io/xmake/releases) 上下载windows安装包 -2. 运行安装程序 xmake-[version].exe - -##### 使用scoop - -```bash -scoop install xmake -``` - -#### MacOS - -```bash -$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" -$ brew install xmake -``` - -或者: - -1. 从 [Releases](https://github.com/xmake-io/xmake/releases) 上下载pkg安装包 -2. 双击运行 - -或者安装master版本: - -```bash -# 使用homebrew安装master版本 -$ brew install xmake --HEAD - -# 或者直接调用shell下载安装 -$ bash <(curl -fsSL https://raw.githubusercontent.com/tboox/xmake/master/scripts/get.sh) -``` - -#### Linux - -在archlinux上安装: - -```bash -$ yaourt xmake -``` - -在ubuntu上安装: - -```bash -$ sudo add-apt-repository ppa:tboox/xmake -$ sudo apt-get update -$ sudo apt-get install xmake -``` - -或者手动添加包源: - -``` -deb http://ppa.launchpad.net/tboox/xmake/ubuntu yakkety main -deb-src http://ppa.launchpad.net/tboox/xmake/ubuntu yakkety main -``` - -然后执行: - -```bash -$ sudo apt-get update -$ sudo apt-get install xmake -``` - -或者下载deb包来安装: - -1. 从 [Releases](https://github.com/xmake-io/xmake/releases) 上下载deb安装包 -2. 运行: `dpkg -i xmake-xxxx.deb` - -在`redhat/centos`上安装: - -1. 从 [Releases](https://github.com/xmake-io/xmake/releases) 上下载rpm安装包 -2. 运行: `yum install xmake-xxx.rpm --nogpgcheck` - -#### 编译安装 - -通过脚本编译安装: - -```bash -$ git clone https://github.com/xmake-io/xmake.git -$ cd ./xmake -$ ./scripts/get.sh __local__ -``` - -仅仅安装和更新xmake的lua脚本: - -```bash -$ ./scripts/get.sh __local__ __install_only__ -``` - -卸载: - -```bash -$ ./scripts/get.sh __uninstall__ -``` - -通过make进行编译安装: - -```bash -$ make build; sudo make install -``` - -安装到其他指定目录: - -```bash -$ sudo make install prefix=/usr/local -``` - -卸载: - -```bash -$ sudo make uninstall -``` - -#### 更新升级 - -从v2.2.3版本开始,新增了`xmake update`命令,来快速进行自我更新和升级,默认是升级到最新版本,当然也可以指定升级或者回退到某个版本: - -```bash -$ xmake update 2.2.4 -``` - -我们也可以指定更新到master/dev分支版本: - -```bash -$ xmake update master -$ xmake update dev -``` - -最后,我们如果要卸载xmake,也是支持的:`xmake update --uninstall` - -## 快速开始 - -[](https://asciinema.org/a/133693) - -#### 创建工程 - -创建一个名叫`hello`的`c`控制台工程: - -```bash -$ xmake create -l c -P ./hello -``` - -执行完后,将会生成一个简单工程结构: - -``` -hello -├── src -│ └── main.c -└── xmake.lua -``` - -其中`xmake.lua`是工程描述文件,内容非常简单,告诉xmake添加`src`目录下的所有`.c`源文件: - -```lua -target("hello") - set_kind("binary") - add_files("src/*.c") -``` - -目前支持的语言如下: - -* c/c++ -* objc/c++ -* cuda -* asm -* swift -* dlang -* golang -* rust - -<p class="tip"> - 如果你想了解更多参数选项,请运行: `xmake create --help` -</p> - -#### 构建工程 - -```bash -$ xmake -``` - -#### 运行程序 - -```bash -$ xmake run hello -``` - -#### 调试程序 - -```bash -$ xmake run -d hello -``` - -xmake将会使用系统自带的调试器去加载程序运行,目前支持:lldb, gdb, windbg, vsjitdebugger, ollydbg 等各种调试器。 - -```bash -[lldb]$target create "build/hello" -Current executable set to 'build/hello' (x86_64). -[lldb]$b main -Breakpoint 1: where = hello`main, address = 0x0000000100000f50 -[lldb]$r -Process 7509 launched: '/private/tmp/hello/build/hello' (x86_64) -Process 7509 stopped -* thread #1: tid = 0x435a2, 0x0000000100000f50 hello`main, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1 - frame #0: 0x0000000100000f50 hello`main -hello`main: --> 0x100000f50 <+0>: pushq %rbp - 0x100000f51 <+1>: movq %rsp, %rbp - 0x100000f54 <+4>: leaq 0x2b(%rip), %rdi ; "hello world!" - 0x100000f5b <+11>: callq 0x100000f64 ; symbol stub for: puts -[lldb]$ -``` - -<p class="tip"> - 你也可以使用简写的命令行选项,例如: `xmake r` 或者 `xmake run` -</p> - -## 工程实例 - -#### 可执行程序 - -```lua -target("test") - set_kind("binary") - add_files("src/*c") -``` - -#### 静态库程序 - -```lua -target("library") - set_kind("static") - add_files("src/library/*.c") - -target("test") - set_kind("binary") - add_files("src/*c") - add_deps("library") -``` - -通过`add_deps`将一个静态库自动链接到test可执行程序。 - -#### 动态库程序 - -```lua -target("library") - set_kind("shared") - add_files("src/library/*.c") - -target("test") - set_kind("binary") - add_files("src/*c") - add_deps("library") -``` - -通过`add_deps`将一个动态库自动链接到test可执行程序。 - -#### Qt程序 - -创建一个空工程: - -```console -$ xmake create -l c++ -t console_qt test -$ xmake create -l c++ -t static_qt test -$ xmake create -l c++ -t shared_qt test -$ xmake create -l c++ -t quickapp_qt test -``` - -默认会自动探测Qt环境,当然也可以指定Qt SDK环境目录: - -```console -$ xmake f --qt=~/Qt/Qt5.9.1 -``` - -如果想要使用windows下mingw的Qt环境,可以切到mingw的平台配置,并且指定下mingw编译环境的sdk路径即可,例如: - -```console -$ xmake f -p mingw --sdk=C:\Qt\Qt5.10.1\Tools\mingw530_32 -``` - -上述指定的mingw sdk用的是Qt下Tools目录自带的环境,当然如果有其他第三方mingw编译环境,也可以手动指定, 具体可以参考:[mingw编译配置](#mingw)。 - -更多详情可以参考:[#160](https://github.com/xmake-io/xmake/issues/160) - -##### 静态库程序 - -```lua -target("qt_static_library") - add_rules("qt.static") - add_files("src/*.cpp") - add_frameworks("QtNetwork", "QtGui") -``` - -##### 动态库程序 - -```lua -target("qt_shared_library") - add_rules("qt.shared") - add_files("src/*.cpp") - add_frameworks("QtNetwork", "QtGui") -``` - -##### 控制台程序 - -```lua -target("qt_console") - add_rules("qt.console") - add_files("src/*.cpp") -``` - -##### Quick应用程序 - -```lua -target("qt_quickapp") - add_rules("qt.application") - add_files("src/*.cpp") - add_files("src/qml.qrc") - add_frameworks("QtQuick") -``` - -##### Widgets应用程序 - -```lua -target("qt_widgetapp") - add_rules("qt.application") - add_files("src/*.cpp") - add_files("src/mainwindow.ui") - add_files("src/mainwindow.h") -- 添加带有 Q_OBJECT 的meta头文件 - add_frameworks("QtWidgets") -``` - -##### Android应用程序 - -2.2.6之后版本,可以直接切到android平台编译Quick/Widgets应用程序,生成apk包,并且可通过`xmake install`命令安装到设备。 - -```console -$ xmake create -t quickapp_qt -l c++ appdemo -$ cd appdemo -$ xmake f -p android --ndk=~/Downloads/android-ndk-r19c/ --android_sdk=~/Library/Android/sdk/ -c -$ xmake -[ 0%]: compiling.qt.qrc src/qml.qrc -[ 50%]: ccache compiling.release src/main.cpp -[100%]: linking.release libappdemo.so -[100%]: generating.qt.app appdemo.apk -``` - -然后安装到设备: - -```console -$ xmake install -installing appdemo ... -installing build/android/armv7-a/release/appdemo.apk .. -Success -install ok!👌 -``` - -#### Cuda程序 - -创建一个空工程: - -```console -$ xmake create -P test -l cuda -$ cd test -$ xmake -``` - -```lua --- define target -target("cuda_console") - set_kind("binary") - add_files("src/*.cu") - -- generate SASS code for SM architecture of current host - add_cugencodes("native") - -- generate PTX code for the virtual architecture to guarantee compatibility - add_cugencodes("compute_30") -``` - -<p class="tip"> -从v2.2.7版本开始,默认构建会启用device-link,@see https://devblogs.nvidia.com/separate-compilation-linking-cuda-device-code/ -如果要显示禁用device-link,可以通过`add_values("cuda.devlink", false)` 来设置。 -</p> - -默认会自动探测cuda环境,当然也可以指定Cuda SDK环境目录: - -```console -$ xmake f --cuda=/usr/local/cuda-9.1/ -$ xmake -``` - -更多详情可以参考:[#158](https://github.com/xmake-io/xmake/issues/158) - -#### WDK驱动程序 - -默认会自动探测wdk所在环境,当然也可以指定wdk sdk环境目录: - -```console -$ xmake f --wdk="G:\Program Files\Windows Kits\10" -c -$ xmake -``` - -更多详情可以参考:[#159](https://github.com/xmake-io/xmake/issues/159) - -##### umdf驱动程序 - -```lua -target("echo") - add_rules("wdk.driver", "wdk.env.umdf") - add_files("driver/*.c") - add_files("driver/*.inx") - add_includedirs("exe") - -target("app") - add_rules("wdk.binary", "wdk.env.umdf") - add_files("exe/*.cpp") -``` - -##### kmdf驱动程序 - -```lua -target("nonpnp") - add_rules("wdk.driver", "wdk.env.kmdf") - add_values("wdk.tracewpp.flags", "-func:TraceEvents(LEVEL,FLAGS,MSG,...)", "-func:Hexdump((LEVEL,FLAGS,MSG,...))") - add_files("driver/*.c", {rule = "wdk.tracewpp"}) - add_files("driver/*.rc") - -target("app") - add_rules("wdk.binary", "wdk.env.kmdf") - add_files("exe/*.c") - add_files("exe/*.inf") -``` - -##### wdm驱动程序 - -```lua -target("kcs") - add_rules("wdk.driver", "wdk.env.wdm") - add_values("wdk.man.flags", "-prefix Kcs") - add_values("wdk.man.resource", "kcsCounters.rc") - add_values("wdk.man.header", "kcsCounters.h") - add_values("wdk.man.counter_header", "kcsCounters_counters.h") - add_files("*.c", "*.rc", "*.man") -``` - -```lua -target("msdsm") - add_rules("wdk.driver", "wdk.env.wdm") - add_values("wdk.tracewpp.flags", "-func:TracePrint((LEVEL,FLAGS,MSG,...))") - add_files("*.c", {rule = "wdk.tracewpp"}) - add_files("*.rc", "*.inf") - add_files("*.mof|msdsm.mof") - add_files("msdsm.mof", {values = {wdk_mof_header = "msdsmwmi.h"}}) -``` - -##### 生成驱动包 - -可以通过以下命令生成.cab驱动包: - -```console -$ xmake [p|package] -$ xmake [p|package] -o outputdir -``` - -输出的目录结构如下: - -``` - - drivers - - sampledsm - - debug/x86/sampledsm.cab - - release/x64/sampledsm.cab - - debug/x86/sampledsm.cab - - release/x64/sampledsm.cab -``` - -##### 驱动签名 - -默认编译禁用签名,可以通过`set_values("wdk.sign.mode", ...)`设置签名模式来启用签名。 - -###### 测试签名 - -测试签名一般本机调试时候用,可以使用xmake自带的test证书来进行签名,例如: - -```lua -target("msdsm") - add_rules("wdk.driver", "wdk.env.wdm") - set_values("wdk.sign.mode", "test") -``` - -不过这种情况下,需要用户手动在管理员模式下,执行一遍:`$xmake l utils.wdk.testcert install`,来生成和注册test证书到本机环境。 -这个只需要执行一次就行了,后续就可以正常编译和签名了。 - -当然也可以使用本机已有的有效证书去签名。 - -从sha1来选择合适的证书进行签名: - -```lua -target("msdsm") - add_rules("wdk.driver", "wdk.env.wdm") - set_values("wdk.sign.mode", "test") - set_values("wdk.sign.thumbprint", "032122545DCAA6167B1ADBE5F7FDF07AE2234AAA") -``` - -从store/company来选择合适的证书进行签名: - -```lua -target("msdsm") - add_rules("wdk.driver", "wdk.env.wdm") - set_values("wdk.sign.mode", "test") - set_values("wdk.sign.store", "PrivateCertStore") - set_values("wdk.sign.company", "tboox.org(test)") -``` - -###### 正式签名 - -通过指定对应的正式签名证书文件进行签名: - -```lua -target("msdsm") - add_rules("wdk.driver", "wdk.env.wdm") - set_values("wdk.sign.mode", "release") - set_values("wdk.sign.company", "xxxx") - set_values("wdk.sign.certfile", path.join(os.projectdir(), "xxxx.cer")) -``` - -##### 生成低版本驱动 - -如果想在wdk10环境编译生成win7, win8等低版本系统支持的驱动,可以通过设置`wdk.env.winver`来切换系统版本: - -```lua -set_values("wdk.env.winver", "win10") -set_values("wdk.env.winver", "win10_rs3") -set_values("wdk.env.winver", "win81") -set_values("wdk.env.winver", "win8") -set_values("wdk.env.winver", "win7") -set_values("wdk.env.winver", "win7_sp1") -set_values("wdk.env.winver", "win7_sp2") -set_values("wdk.env.winver", "win7_sp3") -``` - -我们也可以手动指定编译的目标程序支持的windows版本: - -```console -$ xmake f --wdk_winver=[win10_rs3|win8|win7|win7_sp1] -$ xmake -``` - -#### WinSDK程序 - -```lua -target("usbview") - add_rules("win.sdk.application") - - add_files("*.c", "*.rc") - add_files("xmlhelper.cpp", {rule = "win.sdk.dotnet"}) -``` - -更多详情可以参考:[#173](https://github.com/xmake-io/xmake/issues/173) - -## 编译配置 - -通过`xmake f|config`配置命令,设置构建前的相关配置信息,详细参数选项,请运行: `xmake f --help`。 - -<p class="tip"> - 你可以使用命令行缩写来简化输入,也可以使用全名,例如: <br> - `xmake f` 或者 `xmake config`.<br> - `xmake f -p linux` 或者 `xmake config --plat=linux`. -</p> - -#### 目标平台 - -##### 主机平台 - -```bash -$ xmake -``` - -<p class="tip"> - xmake将会自动探测当前主机平台,默认自动生成对应的目标程序。 -</p> - -##### Linux - -```bash -$ xmake f -p linux [-a i386|x86_64] -$ xmake -``` - -##### Android - -```bash -$ xmake f -p android --ndk=~/files/android-ndk-r10e/ [-a armv5te|armv6|armv7-a|armv8-a|arm64-v8a] -$ xmake -``` - -如果要手动指定ndk中具体某个工具链,而不是使用默认检测的配置,可以通过[--bin](#-bin)来设置,例如: - -```bash -$ xmake f -p android --ndk=~/files/android-ndk-r10e/ -a arm64-v8a --bin=~/files/android-ndk-r10e/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin -``` - -[--bin](#-bin)主要用于设置选择编译工具的具体bin目录,这个的使用跟[交叉编译](#交叉编译)中的[--bin](#-bin)的行为是一致的。 - -<p class="tip"> -如果手动设置了bin目录,没有通过检测,可以看下是否`--arch=`参数没有匹配对。 -</p> - -##### iPhoneOS - -```bash -$ xmake f -p iphoneos [-a armv7|armv7s|arm64|i386|x86_64] -$ xmake -``` - -##### Windows - -```bash -$ xmake f -p windows [-a x86|x64] -$ xmake -``` - -##### Mingw - -```bash -$ xmake f -p mingw --sdk=/usr/local/i386-mingw32-4.3.0/ [-a i386|x86_64] -$ xmake -``` - -##### Apple WatchOS - -```bash -$ xmake f -p watchos [-a i386|armv7k] -$ xmake -``` - -##### 交叉编译 - -linux平台的交叉编译: - -```bash -$ xmake f -p linux --sdk=/usr/local/arm-linux-gcc/ [--bin=/sdk/bin] [--cross=arm-linux-] -$ xmake -``` - -其他平台的交叉编译: - -```bash -$ xmake f -p cross --sdk=/usr/local/arm-xxx-gcc/ [--bin=/sdk/bin] [--cross=arm-linux-] -$ xmake -``` - -如果不关心实际的平台名,只想交叉编译,可以直接用上面的命令,如果需要通过`is_plat("myplat")`判断自己的平台逻辑,则: - -```bash -$ xmake f -p myplat --sdk=/usr/local/arm-xxx-gcc/ [--bin=/sdk/bin] [--cross=arm-linux-] -$ xmake -``` - -其中: - -| 参数名 | 描述 | -| ---------------------------- | -------------------------------- | -| [--sdk](#-sdk) | 设置交叉工具链的sdk根目录 | -| [--bin](#-bin) | 设置工具链bin目录 | -| [--cross](#-cross) | 设置交叉工具链工具前缀 | -| [--as](#-as) | 设置`asm`汇编器 | -| [--cc](#-cc) | 设置`c`编译器 | -| [--cxx](#-cxx) | 设置`c++`编译器 | -| [--mm](#-mm) | 设置`objc`编译器 | -| [--mxx](#-mxx) | 设置`objc++`编译器 | -| [--sc](#-sc) | 设置`swift`编译器 | -| [--gc](#-gc) | 设置`golang`编译器 | -| [--dc](#-dc) | 设置`dlang`编译器 | -| [--rc](#-rc) | 设置`rust`编译器 | -| [--cu](#-cu) | 设置`cuda`编译器 | -| [--ld](#-ld) | 设置`c/c++/objc/asm`链接器 | -| [--sh](#-sh) | 设置`c/c++/objc/asm`共享库链接器 | -| [--ar](#-ar) | 设置`c/c++/objc/asm`静态库归档器 | -| [--sc-ld](#-sc-ld) | 设置`swift`链接器 | -| [--sc-sh](#-sc-sh) | 设置`swift`共享库链接器 | -| [--gc-ld](#-gc-ld) | 设置`golang`链接器 | -| [--gc-ar](#-gc-ar) | 设置`golang`静态库归档器 | -| [--dc-ld](#-dc-ld) | 设置`dlang`链接器 | -| [--dc-sh](#-dc-sh) | 设置`dlang`共享库链接器 | -| [--dc-ar](#-dc-ar) | 设置`dlang`静态库归档器 | -| [--rc-ld](#-rc-ld) | 设置`rust`链接器 | -| [--rc-sh](#-rc-sh) | 设置`rust`共享库链接器 | -| [--rc-ar](#-rc-ar) | 设置`rust`静态库归档器 | -| [--cu-cxx](#-cu-cxx) | 设置`cuda` host编译器 | -| [--cu-ld](#-cu-ld) | 设置`cuda`链接器 | -| [--asflags](#-asflags) | 设置`asm`汇编编译选项 | -| [--cflags](#-cflags) | 设置`c`编译选项 | -| [--cxflags](#-cxflags) | 设置`c/c++`编译选项 | -| [--cxxflags](#-cxxflags) | 设置`c++`编译选项 | -| [--mflags](#-mflags) | 设置`objc`编译选项 | -| [--mxflags](#-mxflags) | 设置`objc/c++`编译选项 | -| [--mxxflags](#-mxxflags) | 设置`objc++`编译选项 | -| [--scflags](#-scflags) | 设置`swift`编译选项 | -| [--gcflags](#-gcflags) | 设置`golang`编译选项 | -| [--dcflags](#-dcflags) | 设置`dlang`编译选项 | -| [--rcflags](#-rcflags) | 设置`rust`编译选项 | -| [--cuflags](#-cuflags) | 设置`cuda`编译选项 | -| [--ldflags](#-ldflags) | 设置链接选项 | -| [--shflags](#-shflags) | 设置共享库链接选项 | -| [--arflags](#-arflags) | 设置静态库归档选项 | - -<p class="tip"> -如果你想要了解更多参数选项,请运行: `xmake f --help`。 -</p> - -###### --sdk - -- 设置交叉工具链的sdk根目录 - -大部分情况下,都不需要配置很复杂的toolchains前缀,例如:`arm-linux-` 什么的 - -只要这个工具链的sdk目录满足如下结构(大部分的交叉工具链都是这个结构): - -``` -/home/toolchains_sdkdir - - bin - - arm-linux-gcc - - arm-linux-ld - - ... - - lib - - libxxx.a - - include - - xxx.h -``` - -那么,使用xmake进行交叉编译的时候,只需要进行如下配置和编译: - -```bash -$ xmake f -p linux --sdk=/home/toolchains_sdkdir -$ xmake -``` - -这个时候,xmake会去自动探测,gcc等编译器的前缀名:`arm-linux-`,并且编译的时候,也会自动加上`链接库`和`头文件`的搜索选项,例如: - -``` --I/home/toolchains_sdkdir/include -L/home/toolchains_sdkdir/lib -``` - -这些都是xmake自动处理的,不需要手动配置他们。。 - -###### --bin - -- 设置工具链bin目录 - -对于不规则工具链目录结构,靠单纯地[--sdk](#-sdk)选项设置,没法完全检测通过的情况下,可以通过这个选项继续附加设置工具链的bin目录位置。 - -例如:一些特殊的交叉工具链的,编译器bin目录,并不在 `/home/toolchains_sdkdir/bin` 这个位置,而是独立到了 `/usr/opt/bin` - -```bash -$ xmake f -p linux --sdk=/home/toolchains_sdkdir --bin=/usr/opt/bin -$ xmake -``` - -<p class="tip"> -v2.2.1版本之前,这个参数名是`--toolchains`,比较有歧义,因此新版本中,统一改成`--bin=`来设置bin目录。 -</p> - -###### --cross - -- 设置交叉工具链工具前缀 - -像`aarch64-linux-android-`这种,通常如果你配置了[--sdk](#-sdk)或者[--bin](#-bin)的情况下,xmake会去自动检测的,不需要自己手动设置。 - -但是对于一些极特殊的工具链,一个目录下同时有多个cross前缀的工具bin混在一起的情况,你需要手动设置这个配置,来区分到底需要选用哪个bin。 - -例如,toolchains的bin目录下同时存在两个不同的编译器: - -``` -/opt/bin - - armv7-linux-gcc - - aarch64-linux-gcc -``` - -我们现在想要选用armv7的版本,则配置如下: - -```bash -$ xmake f -p linux --sdk=/usr/toolsdk --bin=/opt/bin --cross=armv7-linux- -``` - -###### --as - -- 设置`asm`汇编器 - -如果还要继续细分选择编译器,则继续追加相关编译器选项,例如: - -```bash -$ xmake f -p linux --sdk=/user/toolsdk --as=armv7-linux-as -``` - -如果存在`AS`环境变量的话,会优先使用当前环境变量中指定的值。 - -<p class="tip"> -如果指定的编译器名不是那些xmake内置可识别的名字(带有gcc, clang等字样),那么编译器工具检测就会失败。 -这个时候我们可以通过:`xmake f --as=gcc@/home/xxx/asmips.exe` 设置ccmips.exe编译器作为类gcc的使用方式来编译。 -也就是说,在指定编译器为`asmips.exe`的同时,告诉xmake,它跟gcc用法和参数选项基本相同。 -</p> - -###### --cc - -- 设置c编译器 - -如果还要继续细分选择编译器,则继续追加相关编译器选项,例如: - -```bash -$ xmake f -p linux --sdk=/user/toolsdk --cc=armv7-linux-clang -``` - -如果存在`CC`环境变量的话,会优先使用当前环境变量中指定的值。 - -<p class="tip"> -如果指定的编译器名不是那些xmake内置可识别的名字(带有gcc, clang等字样),那么编译器工具检测就会失败。 -这个时候我们可以通过:`xmake f --cc=gcc@/home/xxx/ccmips.exe` 设置ccmips.exe编译器作为类gcc的使用方式来编译。 -也就是说,在指定编译器为`ccmips.exe`的同时,告诉xmake,它跟gcc用法和参数选项基本相同。 -</p> - -###### --cxx - -- 设置`c++`编译器 - -如果还要继续细分选择编译器,则继续追加相关编译器选项,例如: - -```bash -$ xmake f -p linux --sdk=/user/toolsdk --cxx=armv7-linux-clang++ -``` - -如果存在`CXX`环境变量的话,会优先使用当前环境变量中指定的值。 - -<p class="tip"> -如果指定的编译器名不是那些xmake内置可识别的名字(带有gcc, clang等字样),那么编译器工具检测就会失败。 -这个时候我们可以通过:`xmake f --cxx=clang++@/home/xxx/c++mips.exe` 设置c++mips.exe编译器作为类clang++的使用方式来编译。 -也就是说,在指定编译器为`c++mips.exe`的同时,告诉xmake,它跟clang++用法和参数选项基本相同。 -</p> - -###### --ld - -- 设置`c/c++/objc/asm`链接器 - -如果还要继续细分选择链接器,则继续追加相关编译器选项,例如: - -```bash -$ xmake f -p linux --sdk=/user/toolsdk --ld=armv7-linux-clang++ -``` - -如果存在`LD`环境变量的话,会优先使用当前环境变量中指定的值。 - -<p class="tip"> -如果指定的编译器名不是那些xmake内置可识别的名字(带有gcc, clang等字样),那么链接器工具检测就会失败。 -这个时候我们可以通过:`xmake f --ld=g++@/home/xxx/c++mips.exe` 设置c++mips.exe链接器作为类g++的使用方式来编译。 -也就是说,在指定链接器为`c++mips.exe`的同时,告诉xmake,它跟g++用法和参数选项基本相同。 -</p> - -###### --sh - -- 设置`c/c++/objc/asm`共享库链接器 - -```bash -$ xmake f -p linux --sdk=/user/toolsdk --sh=armv7-linux-clang++ -``` - -如果存在`SH`环境变量的话,会优先使用当前环境变量中指定的值。 - -<p class="tip"> -如果指定的编译器名不是那些xmake内置可识别的名字(带有gcc, clang等字样),那么链接器工具检测就会失败。 -这个时候我们可以通过:`xmake f --sh=g++@/home/xxx/c++mips.exe` 设置c++mips.exe链接器作为类g++的使用方式来编译。 -也就是说,在指定链接器为`c++mips.exe`的同时,告诉xmake,它跟g++用法和参数选项基本相同。 -</p> - -###### --ar - -- 设置`c/c++/objc/asm`静态库归档器 - -```bash -$ xmake f -p linux --sdk=/user/toolsdk --ar=armv7-linux-ar -``` - -如果存在`AR`环境变量的话,会优先使用当前环境变量中指定的值。 - -<p class="tip"> -如果指定的编译器名不是那些xmake内置可识别的名字(带有ar等字样),那么链接器工具检测就会失败。 -这个时候我们可以通过:`xmake f --ar=ar@/home/xxx/armips.exe` 设置armips.exe链接器作为类ar的使用方式来编译。 -也就是说,在指定链接器为`armips.exe`的同时,告诉xmake,它跟ar用法和参数选项基本相同。 -</p> - -#### 全局配置 - -我们也可以将一些常用配置保存到全局配置中,来简化频繁地输入: - -例如: - -```bash -$ xmake g --ndk=~/files/android-ndk-r10e/ -``` - -现在,我们重新配置和编译`android`程序: - -```bash -$ xmake f -p android -$ xmake -``` - -以后,就不需要每次重复配置`--ndk=`参数了。 - -<p class="tip"> - 每个命令都有其简写,例如: `xmake g` 或者 `xmake global`.<br> -</p> - -#### 清除配置 - -有时候,配置出了问题编译不过,或者需要重新检测各种依赖库和接口,可以加上`-c`参数,清除缓存的配置,强制重新检测和配置 - -```bash -$ xmake f -c -$ xmake -``` - -或者: - -```bash -$ xmake f -p iphoneos -c -$ xmake -``` - -## 语法说明 - -xmake的工程描述文件xmake.lua虽然基于lua语法,但是为了使得更加方便简洁得编写项目构建逻辑,xmake对其进行了一层封装,使得编写xmake.lua不会像些makefile那样繁琐 - -基本上写个简单的工程构建描述,只需三行就能搞定,例如: - -```lua -target("test") - set_kind("binary") - add_files("src/*.c") -``` - -#### 作用域 - -xmake的描述语法是按作用域划分的,主要分为: - -- 外部作用域 -- 内部作用域 -- 接口作用域 - -那哪些属于外部,哪些又属于内部呢,看看下面的注释,就知道个大概了: - -```lua --- 外部作用域 -target("test") - - -- 外部作用域 - set_kind("binary") - add_files("src/*.c") - - on_run(function () - -- 内部作用域 - end) - - after_package(function () - -- 内部作用域 - end) - --- 外部作用域 -task("hello") - - -- 外部作用域 - on_run(function () - -- 内部作用域 - end) -``` - -简单的说,就是在自定义脚本`function () end`之内的都属于内部作用域,也就是脚本作用域,其他地方都是都属于于外部作用域。。 - -##### 外部作用域 - -对于大部分工程来说,并不需要很复杂的工程描述,也不需要自定义脚本支持,只需要简单的 `set_xxx` 或者 `add_xxx` 就能满足需求了 - -那么根据二八定律,80%的情况下,我们只需要这么写: - -```lua -target("test") - set_kind("static") - add_files("src/test/*.c") - -target("demo") - add_deps("test") - set_kind("binary") - add_links("test") - add_files("src/demo/*.c") -``` - -不需要复杂的api调用,也不需要各种繁琐的变量定义,以及 if 判断 和 for 循环,要的就是简洁可读,一眼看过去,就算不懂lua语法也没关系 - -就当做简单的描述语法,看上去有点像函数调用而已,会点编程的基本一看就知道怎么配置。 - -为了做到简洁、安全,在这个作用域内,很多lua 内置api是不开放出来的,尤其是跟写文件、修改操作环境相关的,仅仅提供一些基本的只读接口,和逻辑操作 - -目前外部作用域开放的lua内置api有: - -- table -- string -- pairs -- ipairs -- print -- os - -当然虽然内置lua api提供不多,但xmake还提供了很多扩展api,像描述api就不多说,详细可参考:[API手册](https://xmake.io/#/zh/manual) - -还有些辅助api,例如: - -dirs:扫描获取当前指定路径中的所有目录 -files:扫描获取当前指定路径中的所有文件 -format: 格式化字符串,string.format的简写版本 - -还有变量定义、逻辑操作也是可以使用的,毕竟是基于lua的,该有的基础语法,还是要有的,我们可以通过if来切换编译文件: - -```lua -target("test") - set_kind("static") - if is_plat("iphoneos") then - add_files("src/test/ios/*.c") - else - add_files("src/test/*.c") - end -``` - -需要注意的是,变量定义分全局变量和局部变量,局部变量只对当前xmake.lua有效,不影响子xmake.lua - -```lua --- 局部变量,只对当前xmake.lua有效 -local var1 = 0 - --- 全局变量,影响所有之后 includes() 包含的子 xmake.lua -var2 = 1 - -includes("src") -``` - -##### 内部作用域 - -也称插件、脚本作用域,提供更加复杂、灵活的脚本支持,一般用于编写一些自定义脚本、插件开发、自定义task任务、自定义模块等等 - -一般通过`function () end`包含,并且被传入到`on_xxx`, `before_xxx`和`after_xxx`接口内的,都属于自作用域。 - -例如: - -```lua --- 自定义脚本 -target("hello") - after_build(function () - -- 内部作用域 - end) - --- 自定义任务、插件 -task("hello") - on_run(function () - -- 内部作用域 - end) -``` - -在此作用域中,不仅可以使用大部分lua的api,还可以使用很多xmake提供的扩展模块,所有扩展模块,通过import来导入 - -具体可参考:[import模块导入文档](https://xmake.io/#/zh/manual?id=import) - -这里我们给个简单的例子,在编译完成后,对ios目标程序进行ldid签名: - -```lua -target("iosdemo") - set_kind("binary") - add_files("*.m") - after_build(function (target) - - -- 执行签名,如果失败,自动中断,给出高亮错误信息 - os.run("ldid -S$(projectdir)/entitlements.plist %s", target:targetfile()) - end) -``` - -需要注意的是,在内部作用域中,所有的调用都是启用异常捕获机制的,如果运行出错,会自动中断xmake,并给出错误提示信息 - -因此,脚本写起来,不需要繁琐的`if retval then`判断,脚本逻辑更加一目了然 - -##### 接口作用域 - -在外部作用域中的所有描述api设置,本身也是有作用域之分的,在不同地方调用,影响范围也不相同,例如: - -```lua --- 全局根作用域,影响所有target,包括includes() 中的子工程target设置 -add_defines("DEBUG") - --- 定义或者进入demo目标作用域(支持多次进入来追加设置) -target("demo") - set_kind("shared") - add_files("src/*.c") - -- 当前target作用域,仅仅影响当前target - add_defines("DEBUG2") - --- 选项设置,仅支持局部设置,不受全局api设置所影响 -option("test") - -- 当前选项的局部作用域 - set_default(false) - --- 其他target设置,-DDEBUG 也会被设置上 -target("demo2") - set_kind("binary") - add_files("src/*.c") - --- 重新进入demo目标作用域 -target("demo") - -- 追加宏定义,只对当前demo目标有效 - add_defines("DEBUG3") -``` - -通常情况下,进入另一个target/option域设置,会自动离开上个target/option域,但是有时候为了比较一些作用域污染情况,我们可以显示离开某个域,例如: - -```lua -option("test") - set_default(false) -option_end() - -target("demo") - set_kind("binary") - add_files("src/*.c") -target_end() -``` - -调用`option_end()`, `target_end()`即可显式的离开当前target/option域设置。 - -##### 作用域缩进 - -xmake.lua里面缩进,只是个编写规范,用于更加清楚的区分,当前的设置 是针对 那个作用域的,虽然就算不缩进,也一样ok,但是可读性上 并不是很好。。 - -例如: - -```lua -target("xxxx") - set_kind("binary") - add_files("*.c") -``` - -和 - -```lua -target("xxxx") -set_kind("binary") -add_files("*.c") -``` - -上述两种方式,效果上都是一样的,但是理解上,第一种更加直观,一看就知道`add_files`仅仅只是针对 target 设置的,并不是全局设置 - -因此,适当的进行缩进,有助于更好的维护xmake.lua - -最后附上,tbox的[xmake.lua](https://github.com/tboox/tbox/blob/master/src/tbox/xmake.lua)描述,仅供参考。。 - -#### 语法简化 - -xmake.lua的配置域语法,非常灵活,可以在相关域做各种复杂灵活的配置,但是对于许多精简的小块配置,这个时候就稍显冗余了: - -```lua -option("test1") - set_default(true) - set_showmenu(true) - set_description("test1 option") - -option("test2") - set_default(true) - set_showmeu(true) - -option("test3") - set_default("hello") -``` - -xmake 2.2.6以上版本,对于上面的这些小块option域设置,我们可以简化下成单行描述: - -```lua -option("test1", {default = true, showmenu = true, description = "test1 option"}) -option("test2", {default = true, showmenu = true}) -option("test3", {default = "hello"}) -``` - -除了option域,对于其他域也是支持这种简化写法的,例如: - -```lua -target("demo") - set_kind("binary") - add_files("src/*.c") -``` - -简化为: - -```lua -target("demo", {kind = "binary", files = "src/*.c"}) -``` - -当然,如果配置需求比较复杂的,还是原有的多行设置方式更加方便,这个就看自己的需求来评估到底使用哪种方式了。 - -## 依赖包管理 - -#### 本地内置模式 - -通过在项目中内置依赖包目录以及二进制包文件,可以方便的集成一些第三方的依赖库,这种方式比较简单直接,但是缺点也很明显,不方便管理。 - -以tbox工程为例,其依赖包如下: - -``` -- base.pkg -- zlib.pkg -- polarssl.pkg -- openssl.pkg -- mysql.pkg -- pcre.pkg -- ... -``` - -如果要让当前工程识别加载这些包,首先要指定包目录路径,例如: - -```lua -add_packagedirs("packages") -``` - -指定好后,就可以在target作用域中,通过[add_packages](https://xmake.io/#/zh/manual?id=targetadd_packages)接口,来添加集成包依赖了,例如: - -```lua -target("tbox") - add_packages("zlib", "polarssl", "pcre", "mysql") -``` - -那么如何去生成一个*.pkg的包呢,如果是基于xmake的工程,生成方式很简单,只需要: - -```console -$ cd tbox -$ xmake package -``` - -即可在build目录下生成一个tbox.pkg的跨平台包,给第三方项目使用,我也可以直接设置输出目录,编译生成到对方项目中去,例如: - -```console -$ cd tbox -$ xmake package -o ../test/packages -``` - -这样,test工程就可以通过[add_packages](https://xmake.io/#/zh/manual?id=targetadd_packages)和[add_packagedirs](https://xmake.io/#/zh/manual?id=add_packagedirs)去配置和使用tbox.pkg包了。 - -关于内置包的详细描述,还可以参考下相关文章,这里面有详细介绍:[依赖包的添加和自动检测机制](https://tboox.org/cn/2016/08/06/add-package-and-autocheck/) - -#### 系统查找模式 - -如果觉得上述内置包的管理方式非常不方便,可以通过xmake提供的内置接口`find_packages`。 - -目前此接口支持以下一些包管理支持: - -* vcpkg -* homebrew -* pkg-config - -并且通过系统和第三方包管理工具进行依赖包的安装,然后与xmake进行集成使用,例如我们查找一个openssl包: - -```lua -local packages = find_packages("openssl", "zlib") -``` - -返回的结果如下: - -```lua -{ - {links = {"ssl", "crypto"}, linkdirs = {"/usr/local/lib"}, includedirs = {"/usr/local/include"}}, - {links = {"z"}, linkdirs = {"/usr/local/lib"}, includedirs = {"/usr/local/include"}} -} -``` - -如果查找成功,则返回一个包含所有包信息的table,如果失败返回nil - -这里的返回结果可以直接作为`target:add`, `option:add`的参数传入,用于动态增加`target/option`的配置: - -```lua -option("zlib") - set_showmenu(true) - before_check(function (option) - option:add(find_packages("openssl", "zlib")) - end) -``` - -```lua -target("test") - on_load(function (target) - target:add(find_package("openssl", "zlib")) - end) -``` - -如果系统上装有`homebrew`, `pkg-config`等第三方工具,那么此接口会尝试使用它们去改进查找结果。 - -更完整的使用描述,请参考:[find_packages](https://xmake.io/#/zh/manual?id=find_packages)接口文档。 - -##### homebrew集成支持 - -由于homebrew一般都是把包直接装到的系统中去了,因此用户不需要做任何集成工作,`find_packages`就已经原生无缝支持。 - -##### vcpkg集成支持 - -目前xmake v2.2.2版本已经支持了vcpkg,用户只需要装完vcpkg后,执行`$ vcpkg integrate install`,xmake就能自动从系统中检测到vcpkg的根路径,然后自动适配里面包。 - -当然,我们也可以手动指定vcpkg的根路径来支持: - -```console -$ xmake f --vcpkg=f:\vcpkg -``` - -或者我们可以设置到全局配置中去,避免每次切换配置的时候,重复设置: - -```console -$ xmake g --vcpkg=f:\vcpkg -``` - -#### 远程依赖模式 - -这个在2.2.2版本后已经初步支持,用法上更加的简单,只需要设置对应的依赖包就行了,例如: - -```lua -add_requires("tbox 1.6.*", "libpng ~1.16", "zlib") - -target("test") - set_kind("binary") - add_files("src/*.c") - add_packages("tbox", "libpng", "zlib") -``` - -上面的`add_requires`用于描述当前项目需要的依赖包,而`add_packages`用于应用依赖包到test目标,只有设置这个才会自动追加links, linkdirs, includedirs等设置。 - -然后直接执行编译即可: - -```console -$ xmake -``` - -xmake会去远程拉取相关源码包,然后自动编译安装,最后编译项目,进行依赖包的链接,具体效果见下图: - -<img src="/assets/img/index/package_manage.png" width="80%" /> - -关于包依赖管理的更多相关信息和进展见相关issues:[Remote package management](https://github.com/xmake-io/xmake/issues/69) - -##### 目前支持的特性 - -* 语义版本支持,例如:">= 1.1.0 < 1.2", "~1.6", "1.2.x", "1.*" -* 提供官方包仓库、自建私有仓库、项目内置仓库等多仓库管理支持 -* 跨平台包编译集成支持(不同平台、不同架构的包可同时安装,快速切换使用) -* debug依赖包支持,实现源码调试 - -##### 依赖包处理机制 - -这里我们简单介绍下整个依赖包的处理机制: - -<img src="/assets/img/index/package_arch.png" width="80%" /> - -1. 优先检测当前系统目录、第三方包管理下有没有存在指定的包,如果有匹配的包,那么就不需要下载安装了 (当然也可以设置不使用系统包) -2. 检索匹配对应版本的包,然后下载、编译、安装(注:安装在特定xmake目录,不会干扰系统库环境) -3. 编译项目,最后自动链接启用的依赖包 - -##### 快速上手 - -新建一个依赖tbox库的空工程: - -```console -$ xmake create -t console_tbox test -$ cd test -``` - -执行编译即可,如果当前没有安装tbox库,则会自动下载安装后使用: - -```console -$ xmake -``` - -切换到iphoneos平台进行编译,将会重新安装iphoneos版本的tbox库进行链接使用: - -```console -$ xmake f -p iphoneos -$ xmake -``` - -切换到android平台arm64-v8a架构编译: - -```console -$ xmake f -p android [--ndk=~/android-ndk-r16b] -$ xmake -``` - -##### 语义版本设置 - -xmake的依赖包管理是完全支持语义版本选择的,例如:"~1.6.1",对于语义版本的具体描述见:[https://semver.org/](https://semver.org/) - -一些语义版本写法: - -```lua -add_requires("tbox 1.6.*", "pcre 1.3.x", "libpng ^1.18") -add_requires("libpng ~1.16", "zlib 1.1.2 || >=1.2.11 <1.3.0") -``` - -目前xmake使用的语义版本解析器是[uael](https://github.com/uael)贡献的[sv](https://github.com/uael/sv)库,里面也有对版本描述写法的详细说明,可以参考下:[版本描述说明](https://github.com/uael/sv#versions) - -当然,如果我们对当前的依赖包的版本没有特殊要求,那么可以直接这么写: - -```lua -add_requires("tbox", "libpng", "zlib") -``` - -这会使用已知的最新版本包,或者是master分支的源码编译的包,如果当前包有git repo地址,我们也能指定特定分支版本: - -```lua -add_requires("tbox master") -add_requires("tbox dev") -``` - -##### 额外的包信息设置 - -###### 可选包设置 - -如果指定的依赖包当前平台不支持,或者编译安装失败了,那么xmake会编译报错,这对于有些必须要依赖某些包才能工作的项目,这是合理的。 -但是如果有些包是可选的依赖,即使没有也可以正常编译使用的话,可以设置为可选包: - -```lua -add_requires("tbox", {optional = true}) -``` - -###### 禁用系统库 - -默认的设置,xmake会去优先检测系统库是否存在(如果没设置版本要求),如果用户完全不想使用系统库以及第三方包管理提供的库,那么可以设置: - -```lua -add_requires("tbox", {system = false}) -``` - -###### 使用调试版本的包 - -如果我们想同时源码调试依赖包,那么可以设置为使用debug版本的包(当然前提是这个包支持debug编译): - -```lua -add_requires("tbox", {debug = true}) -``` - -如果当前包还不支持debug编译,可在仓库中提交修改编译规则,对debug进行支持,例如: - -```lua -package("openssl") - on_install("linux", "macosx", function (package) - os.vrun("./config %s --prefix=\"%s\"", package:debug() and "--debug" or "", package:installdir()) - os.vrun("make -j4") - os.vrun("make install") - end) -``` - -###### 传递额外的编译信息到包 - -某些包在编译时候有各种编译选项,我们也可以传递进来,当然包本身得支持: - -```lua -add_requires("tbox", {configs = {small=true}}) -``` - -传递`--small=true`给tbox包,使得编译安装的tbox包是启用此选项的。 - -##### 第三方依赖包安装 - -2.2.5版本之后,xmake支持对对第三方包管理器里面的依赖库安装支持,例如:conan,brew, vcpkg等 - -添加homebrew的依赖包: - -```lua -add_requires("brew::zlib", {alias = "zlib"}}) -add_requires("brew::pcre2/libpcre2-8", {alias = "pcre2"}}) - -target("test") - set_kind("binary") - add_files("src/*.c") - add_packages("pcre2", "zlib") -``` - -添加vcpkg的依赖包: - -```lua -add_requires("vcpkg::zlib", "vcpkg::pcre2") - -target("test") - set_kind("binary") - add_files("src/*.c") - add_packages("vcpkg::zlib", "vcpkg::pcre2") -``` - -添加conan的依赖包: - -```lua -add_requires("CONAN::zlib/1.2.11@conan/stable", {alias = "zlib", debug = true}) -add_requires("CONAN::OpenSSL/1.0.2n@conan/stable", {alias = "openssl", - configs = {options = "OpenSSL:shared=True"}}) - -target("test") - set_kind("binary") - add_files("src/*.c") - add_packages("openssl", "zlib") -``` - -执行xmake进行编译后: - -```console -ruki:test_package ruki$ xmake -checking for the architecture ... x86_64 -checking for the Xcode directory ... /Applications/Xcode.app -checking for the SDK version of Xcode ... 10.14 -note: try installing these packages (pass -y to skip confirm)? - -> CONAN::zlib/1.2.11@conan/stable (debug) - -> CONAN::OpenSSL/1.0.2n@conan/stable -please input: y (y/n) - - => installing CONAN::zlib/1.2.11@conan/stable .. ok - => installing CONAN::OpenSSL/1.0.2n@conan/stable .. ok - -[ 0%]: ccache compiling.release src/main.c -[100%]: linking.release test -``` - -##### 使用自建私有包仓库 - -如果需要的包不在官方仓库[xmake-repo](https://github.com/xmake-io/xmake-repo)中,我们可以提交贡献代码到仓库进行支持。 -但如果有些包仅用于个人或者私有项目,我们可以建立一个私有仓库repo,仓库组织结构可参考:[xmake-repo](https://github.com/xmake-io/xmake-repo) - -比如,现在我们有一个一个私有仓库repo:`git@github.com:myrepo/xmake-repo.git` - -我们可以通过下面的命令进行仓库添加: - -```console -$ xmake repo --add myrepo git@github.com:myrepo/xmake-repo.git -``` - -或者我们直接写在xmake.lua中: - -```lua -add_repositories("my-repo git@github.com:myrepo/xmake-repo.git") -``` - -如果我们只是想添加一两个私有包,这个时候特定去建立一个git repo太小题大做了,我们可以直接把包仓库放置项目里面,例如: - -``` -projectdir - - myrepo - - packages - - t/tbox/xmake.lua - - z/zlib/xmake.lua - - src - - main.c - - xmake.lua -``` - -上面myrepo目录就是自己的私有包仓库,内置在自己的项目里面,然后在xmake.lua里面添加一下这个仓库位置: - -```lua -add_repositories("my-repo myrepo") -``` - -这个可以参考[benchbox](https://github.com/tboox/benchbox)项目,里面就内置了一个私有仓库。 - -我们甚至可以连仓库也不用建,直接定义包描述到项目xmake.lua中,这对依赖一两个包的情况还是很有用的,例如: - -```lua -package("libjpeg") - - set_urls("http://www.ijg.org/files/jpegsrc.$(version).tar.gz") - - add_versions("v9c", "650250979303a649e21f87b5ccd02672af1ea6954b911342ea491f351ceb7122") - - on_install("windows", function (package) - os.mv("jconfig.vc", "jconfig.h") - os.vrun("nmake -f makefile.vc") - os.cp("*.h", package:installdir("include")) - os.cp("libjpeg.lib", package:installdir("lib")) - end) - - on_install("macosx", "linux", function (package) - import("package.tools.autoconf").install(package) - end) - -package_end() - -add_requires("libjpeg") - -target("test") - set_kind("binary") - add_files("src/*.c") - add_packages("libjpeg") -``` - -##### 包管理命令使用 - -包管理命令`$ xmake require` 可用于手动显示的下载编译安装、卸载、检索、查看包信息。 - -###### 安装指定包 - -```console -$ xmake require tbox -``` - -安装指定版本包: - -```console -$ xmake require tbox "~1.6" -``` - -强制重新下载安装,并且显示详细安装信息: - -```console -$ xmake require -f -v tbox "1.5.x" -``` - -传递额外的设置信息: - -```console -$ xmake require --extra="debug=true,config={small=true}" tbox -``` - -安装debug包,并且传递`small=true`的编译配置信息到包中去。 - -###### 卸载指定包 - -```console -$ xmake require --uninstall tbox -``` - -这会完全卸载删除包文件。 - -###### 查看包详细信息 - -```console -$ xmake require --info tbox -``` - -###### 在当前仓库中搜索包 - -```console -$ xmake require --search tbox -``` - -这个是支持模糊搜素以及lua模式匹配搜索的: - -```console -$ xmake require --search pcr -``` - -会同时搜索到pcre, pcre2等包。 - -###### 列举当前已安装的包 - -```console -$ xmake require --list -``` - -##### 仓库管理命令使用 - -上文已经简单讲过,添加私有仓库可以用(支持本地路径添加): - -```console -$ xmake repo --add myrepo git@github.com:myrepo/xmake-repo.git -``` - -v2.2.3开始,支持添加指定分支的repo,例如: - -```console -$ xmake repo --add myrepo git@github.com:myrepo/xmake-repo.git dev -``` - -我们也可以移除已安装的某个仓库: - -```console -$ xmake repo --remove myrepo -``` - -或者查看所有已添加的仓库: - -```console -$ xmake repo --list -``` - -如果远程仓库有更新,可以手动执行仓库更新,来获取更多、最新的包: - -```console -$ xmake repo -u -``` - -##### 提交包到官方仓库 - -目前这个特性刚完成不久,目前官方仓库的包还不是很多,有些包也许还不支持部分平台,不过这并不是太大问题,后期迭代几个版本后,我会不断扩充完善包仓库。 - -如果你需要的包,当前的官方仓库还没有收录,可以提交issues或者自己可以在本地调通后,贡献提交到官方仓库:[xmake-repo](https://github.com/xmake-io/xmake-repo) - -详细的贡献说明,见:[CONTRIBUTING.md](https://github.com/xmake-io/xmake-repo/blob/master/CONTRIBUTING.md) - -## 问答 - -#### 怎样获取更多参数选项信息? - -获取主菜单的帮助信息,里面有所有action和plugin的列表描述。 - -```bash -$ xmake [-h|--help] -``` - -获取配置菜单的帮助信息,里面有所有配置选项的描述信息,以及支持平台、架构列表。 - -```bash -$ xmake f [-h|--help] -``` - -获取action和plugin命令菜单的帮助信息,里面有所有内置命令和插件任务的参数使用信息。 - -```bash -$ xmake [action|plugin] [-h|--help] -``` - -例如,获取`run`命令的参数信息: - -```bash -$ xmake run --help -``` - -#### 怎样实现静默构建,不输出任何信息? - -```bash -$ xmake [-q|--quiet] -``` - -#### 如果xmake运行失败了怎么办? - -可以先尝试清除下配置,重新构建下: - -```bash -$ xmake f -c -$ xmake -``` - -如果还是失败了,请加上 `-v` 或者 `--verbose` 选项重新执行xmake后,获取更加详细的输出信息 - -例如: - -```hash -$ xmake [-v|--verbose] -``` - -并且可以加上 `--backtrace` 选项获取出错时的xmake的调试栈信息, 然后你可以提交这些信息到[issues](https://github.com/xmake-io/xmake/issues). - -```bash -$ xmake -v --backtrace -``` - -#### 怎样看实时编译警告信息? - -为了避免刷屏,在构建时候,默认是不实时输出警告信息的,如果想要看的话可以加上`-w`选项启用编译警告输出就行了。 - -```bash -$ xmake [-w|--warning] -``` - -#### 怎样基于源码自动生成xmake.lua - -如果你想临时写一两个测试代码、或者手上有一些移植过来的零散源码想要快速编译运行,可以不用专门xmake.lua,直接运行: - -```bash -$ xmake -``` - -xmake会自动扫描分析当前的源码目录,识别程序结构和类型,生成一个xmake.lua,并且会尝试直接构建它。 - -如果编译成功,可以直接运行: - -```bash -$ xmake run -``` - -当然,如果仅仅只是想要生成xmake.lua,默认不去构建,可以执行: - -```bash -$ xmake f -y -``` - -更多相关介绍,请参考文章:[xmake新增智能代码扫描编译模式,无需手写任何make文件](https://tboox.org/cn/2017/01/07/build-without-makefile/) - -## 支持项目 - -xmake项目属于个人开源项目,它的发展需要您的帮助,如果您愿意支持xmake项目的开发,欢迎为其捐赠,支持它的发展。 🙏 [[支持此项目](https://opencollective.com/xmake#backer)] - -<a href="https://opencollective.com/xmake#backers" target="_blank"><img src="https://opencollective.com/xmake/backers.svg?width=890"></a> - -## 赞助项目 - -通过赞助支持此项目,您的logo和网站链接将显示在这里。[[赞助此项目](https://opencollective.com/xmake#sponsor)] - -<a href="https://opencollective.com/xmake/sponsor/0/website" target="_blank"><img src="https://opencollective.com/xmake/sponsor/0/avatar.svg"></a> -<a href="https://opencollective.com/xmake/sponsor/1/website" target="_blank"><img src="https://opencollective.com/xmake/sponsor/1/avatar.svg"></a> -<a href="https://opencollective.com/xmake/sponsor/2/website" target="_blank"><img src="https://opencollective.com/xmake/sponsor/2/avatar.svg"></a> -<a href="https://opencollective.com/xmake/sponsor/3/website" target="_blank"><img src="https://opencollective.com/xmake/sponsor/3/avatar.svg"></a> -<a href="https://opencollective.com/xmake/sponsor/4/website" target="_blank"><img src="https://opencollective.com/xmake/sponsor/4/avatar.svg"></a> -<a href="https://opencollective.com/xmake/sponsor/5/website" target="_blank"><img src="https://opencollective.com/xmake/sponsor/5/avatar.svg"></a> -<a href="https://opencollective.com/xmake/sponsor/6/website" target="_blank"><img src="https://opencollective.com/xmake/sponsor/6/avatar.svg"></a> -<a href="https://opencollective.com/xmake/sponsor/7/website" target="_blank"><img src="https://opencollective.com/xmake/sponsor/7/avatar.svg"></a> -<a href="https://opencollective.com/xmake/sponsor/8/website" target="_blank"><img src="https://opencollective.com/xmake/sponsor/8/avatar.svg"></a> -<a href="https://opencollective.com/xmake/sponsor/9/website" target="_blank"><img src="https://opencollective.com/xmake/sponsor/9/avatar.svg"></a> - - |
