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
|
## 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).
|