1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
|
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
```
|