diff options
| author | ruki <waruqi@gmail.com> | 2019-06-22 00:51:03 +0800 |
|---|---|---|
| committer | ruki <waruqi@gmail.com> | 2019-06-21 23:06:22 +0800 |
| commit | eb349bcce1c18b3823194c62c532c1ca96503a4f (patch) | |
| tree | 0b6ee9c8aefbb2ea9a9a690d337950de439a9192 /guide/project_examples.md | |
| parent | fbe5b23eeca6c2a15958e655e79de2368f00220d (diff) | |
| download | xmake-docs-eb349bcce1c18b3823194c62c532c1ca96503a4f.tar.gz xmake-docs-eb349bcce1c18b3823194c62c532c1ca96503a4f.zip | |
add guide and plugin
Diffstat (limited to 'guide/project_examples.md')
| -rw-r--r-- | guide/project_examples.md | 333 |
1 files changed, 333 insertions, 0 deletions
diff --git a/guide/project_examples.md b/guide/project_examples.md new file mode 100644 index 00000000..385d5a5c --- /dev/null +++ b/guide/project_examples.md @@ -0,0 +1,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). + |
