当前位置:网站首页>Proficient in xmake
Proficient in xmake
2022-06-11 19:34:00 【fqbqrr】
01
Download the release
can xmake update To automatically update .
02 Create and compile projects xmake create establish Languages The empty project .
The default is C++, Generate
add_rules("mode.debug", "mode.release")
// Optional , Two build modes
target("test")
// Sub engineering modules
set_kind("binary")
//exe
add_files("src/*.cpp")
The default with Release Pattern , Switch mode :
$ xmake f -m debug
$ xmake
//f Indicates configuration .
xmake --help There are more abbreviations .xmake create --help, Yes Various types of works . Such as c++( Default ),-l Setup language . Yes go/rust/dlang/....
use -t To specify the Template type .
Such as , be based on C Static library
xmake create -l c -t static test
be based on qt:
xmake create -l c++ -t qt.quickapp test
...
A focus on c/c++ Language .
Operation target
$ xmake run
use add_runenvs To set up The goal is Of environment variable .
target("test")
set_kind("binary")
add_files("src/*.c")
add_runenvs("PATH", "/tmp/bin", "xxx/bin")
add_runenvs("LD_LIBRARY_PATH", "/tmp/lib", "xxx/lib")
// Support multiple values .
on_run Run scripts automatically ,xmake run -d Debugging program .
Common settings
target("demo", {
kind = "binary", files = "src/*.c"})
One line compilation src All of the following c file . Generate demo. For the above Streamlining How to write it . This is more recommended :
target("demo")
set_kind("binary")
add_files("src/*.c")
set_kind(), Set up binary,static,shared, by static state / dynamic / Binary system . Jiahong (add_defines()) Equivalent to -DXXX.is_plat() Judge the platform .
Multiple The goal is , It's alone .
Global settings , Put it on the outside .
-- Global settings
add_defines("TEST")
// Jiahong
if is_arch("arm64", "armv7") then
add_defines("ARM")
end
You can use target_end() End of the mandatory target Subdomain , Switch back to the local area .
from add_cflags( only c), add_cxflags(c/c++), add_cxxflags(c++) To set compilation options . By the user Judge Compiling platform . Such as
add_cflags("-g", "-O2", "-DDEBUG")
if is_plat("windows") then
add_cflags("/MT")
end
With gcc Defined as standard , When incompatible , Automatically transformation , When there is no matching value , Ignore .
Disable flag .
add_cflags("-g", "-O2", {
force = true})
// mandatory , To force parameters to be passed in .
xmake -v View compilation details .
Add Library Directory
target("test")
set_kind("binary")
add_includedirs("/usr/local/include")
add_links("pthread")
add_linkdirs("/usr/local/lib")
// Header Directory , Library name , The library catalog .
add_syslinks() For the system link library .add_links() It is not a system .
target("test")
set_kind("binary")
add_links("A", "B")
add_syslinks("pthread")
Into the -lA -lB -lpthread such . System Put the final .
Set language standards :set_languages("c99", "c++11").
Built in optimization
Compile optimized configuration :none,fast,faster,fastest,smallest,aggressive
set_optimize("fastest")
xmake Internal mapping . So it is very convenient and cross platform .
Different compilation modes , We need to judge :
if is_mode("debug") then
set_symbols("debug")
set_optimize("none")
end
if is_mode("release") then
set_symbols("hidden")
set_strip("all")
if is_plat("iphoneos", "android") then
set_optimize("smallest")
else
set_optimize("fastest")
end
end
too troublesome , So use Built in rules To simplify setup .
add_rules("mode.release", "mode.debug")
Customizable :
add_rules("mode.release", "mode.debug")
if is_mode("release") then
set_optimize("fastest")
end
Switch to debug mode :
xmake f -m debug; xmake
Add source file
add_files()
Add various source files :C/Cpp/d/.....obj, .a/.lib It's fine too , Such as .
add_files("src/test_*.c")
add_files("src/xxx/**.cpp")
add_files("src/asm/*.S", "src/objc/**/hello.m")
* Single stage ,** Multi level directory . It can also filter .
add_files("src/**.c|impl/*.c")
// barring impl Below directory .
add_files("src/*.cpp|test.cpp|hello.cpp|xx_*.cpp")
// The following are all exclusions
Finer control
target("test")
add_defines("TEST1")
add_files("src/*.c")
add_files("test/*.c", "test2/test2.c", {
defines = "TEST2", languages = "c99", includedirs = ".", cflags = "-O0"})
stay add_files Last parameter , Incoming configuration surface , To control the specified file Compilation options .
target("test")
-- ...
add_files("src/test/*.md", {
rule = "markdown"})
// Add a rule to the specified file .
mandatory :
add_files("src/*.c", {
force = {
cxflags = "-DTEST", mflags = "-framework xxx"}})
Also delete the file :
target("test")
add_files("src/*.c")
del_files("src/test.c")
// And | The effect is the same .
such :
target("test")
add_files("src/**.c")
del_files("src/test*.c")
del_files("src/subdir/*.c|xxx.c")
//xxx.c, Under double negation , Express reservation .
if is_plat("iphoneos") then
add_files("xxx.m")
end
Android platform ndk Catalog :
xmake f -p android --ndk=~/downloads/android-ndk-r19c $ xmake
// Pass in
-p android Switch to Android . Compiling Android native . Support binary,static,sharedxmake f/config Only for the current project .
Set the global usage :
$ xmake g --ndk=~/xxx/android-ndk-r19c
//ANDROID_NDK_HOME=
$ xmake f -p android --ndk=xxx --ndk_sdkver=16
//api edition
$ xmake f -p android --ndk=xxx -a arm64-v8a
// Change the structure
The architecture has :armv7-a,arm64-v8a,armv5te,mips,mips64,i386,x86_64
use is_plat("android") To judge Android .
target("test")
set_kind("shared")
add_files("src/*.c")
if is_plat("android") then
add_defines("ANDROID")
add_syslinks("log")
end
Development qt
$ xmake f --qt=/home/xxx/qtsdk
// Manual configuration
$ xmake g --qt=/home/xxx/qtsdk
// Make the whole situation
$ xmake create -t qt.quickapp test
//qt Fast
Generate
target("test")
add_rules("qt.quickapp")
// Use this built-in rule , add ` link / sign / Contains the directory ` etc.
add_headerfiles("src/*.h")
add_files("src/*.cpp")
add_files("src/qml.qrc")
//
$ xmake run
// function
stay qt.quickapp In the maintenance *.qrc The rules .
$ xmake create -t qt.widgetapp test
// Create project . Generate
target("qt_widgetapp")
add_rules("qt.widgetapp")
add_files("src/*.cpp")
add_files("src/mainwindow.ui")
add_files("src/mainwindow.h")
-- Add with `Q_OBJECT` Of `meta` The header file
// Static version
$ xmake create -t qt.widgetapp_static test
-- become add_rules("qt.widgetapp_static")
also :
-qt.console:c++
-qt.quickapp:c++
-qt.quickapp_static:c++
-qt.shared:c++
-qt.static:c++
-qt.widgetapp:c++
-qt.widgetapp_static:c++
Also set --android_sdk Location .
$ xmake install
// install qtapk To equipment
use -m/--mode= To switch modes . When loading targets , Judge
xmake f --mode=xxx
Set up , use is_mode() To judge .debug Then disable Optimize Enable Symbol , and release Enable Optimize , Ban Symbol .
Customizable :
if is_mode("release") then
set_symbols("debug")
end
// Or add additional compilation flags :
if is_mode("release") then
add_cflags("-fomit-frame-pointer")
end
User configuration takes precedence . Users can also Fully customized :
-- If the current compilation mode is debug
if is_mode("debug") then
-- add to DEBUG Compile macro
add_defines("DEBUG")
-- Enable debug symbols
set_symbols("debug")
-- Disable optimization
set_optimize("none")
end
-- If it is release perhaps profile Pattern
if is_mode("release", "profile") then
-- If it is release Pattern
if is_mode("release") then
-- Hidden symbols
set_symbols("hidden")
-- strip All symbols
set_strip("all")
-- Ignore frame pointer
add_cxflags("-fomit-frame-pointer")
add_mxflags("-fomit-frame-pointer")
-- If it is profile Pattern
else
-- Enable debug symbols
set_symbols("debug")
end
-- Add extensions
add_vectorexts("sse2", "sse3", "ssse3", "mmx")
end
Inside :
add_rules("mode.debug")
//==
if is_mode("debug") then
set_symbols("debug")
set_optimize("none")
end
// and
add_rules("mode.release")
//==
if is_mode("release") then
set_symbols("hidden")
set_optimize("fastest")
set_strip("all")
end
// Used to check memory
add_rules("mode.check")
//==
if is_mode("check") then
set_symbols("debug")
set_optimize("none")
add_cxflags("-fsanitize=address", "-ftrapv")
add_mxflags("-fsanitize=address", "-ftrapv")
add_ldflags("-fsanitize=address")
end
//
add_rules("mode.profile")
//==
// Used to analyze performance
if is_mode("profile") then
set_symbols("debug")
add_cxflags("-pg")
add_ldflags("-pg")
end
// Analysis coverage
add_rules("mode.coverage")
//===
if is_mode("coverage") then
add_cxflags("--coverage")
add_mxflags("--coverage")
add_ldflags("--coverage")
end
$(mode) As a variable , Enable according to different modes :
target("test")
set_kind("binary")
add_files("src/*.c")
add_links("xxx_$(mode)")
// Add link library
target("test")
set_kind("binary")
add_files("src/*.c")
add_linkdirs("lib/$(mode)")
// Search path
add_links("xxx")
use get_config("mode") obtain Pattern Value .
Customize , It works :
on_load(function (target)
if is_mode("release") then
print(get_config("mode"), "$(mode)")
end
end)
边栏推荐
- Longest strictly increasing subsequence
- 【Bug解决】UnpicklingError: A load persistent id instruction was encountered, but no persistent_load.
- YOLOv3 Pytorch代码及原理分析(一):跑通代码
- MySQL federated index and BTREE
- 【图像去噪】基于马尔可夫随机场实现图像去噪附matlab代码
- What is the workflow of dry goods MapReduce?
- 构建Web应用程序
- 干货!基于序列超图神经网络的信息扩散预测
- 【求助】請問如何讓微信公眾號文章在外部瀏覽器中打開後還能顯示下方的精選留言?
- SISO decoder for repetition (supplementary Chapter 4)
猜你喜欢

Yolov3 pytoch code and principle analysis (II): network structure and loss calculation

MOS transistor 24n50 parameters of asemi, 24n50 package, 24n50 size

构建Web应用程序

Unsupervised image classification code analysis notes of scan:learning to classify images without (1): simclr

Find the maximum 3 same digits in the string

Introduction to go language (V) -- branch statement

Tensorflow---TFRecord文件的创建与读取
![[Multisim Simulation] using operational amplifier to generate sawtooth wave](/img/98/27086746dc552ada25fd36a82cb52b.png)
[Multisim Simulation] using operational amplifier to generate sawtooth wave

SLAM APP

计算926的9260次方里的字符串里有多少个926
随机推荐
Multimodal learning toolkit paddlemm based on propeller
【图像分割】基于马尔可夫随机场实现图像分割附matlab代码
Hanging memory recursive dynamic programming (with example explanation POJ 1163)
Introduction to ieda bottom menu
【Bug解决】UnpicklingError: A load persistent id instruction was encountered, but no persistent_load.
556. 下一个更大元素 III-(31. 下一个排列)-两次遍历
Usage of duck beak wire stripper
[Multisim Simulation] using operational amplifier to generate sawtooth wave
图床:PicGo+腾讯云+typora
pstack和dmesg
【Laravel系列7.5】事件系统
On Workflow selection
Expandable type of system
7-3 combinatorial problems (*)
【 aide 】 comment puis - je faire en sorte que les messages sélectionnés ci - dessous puissent être affichés après l'ouverture de l'article Wechat public number dans un navigateur externe?
[laravel series 7.5] event system
Experiment report of basic mechanical experiment (II) of School of distance and continuing education, Dalian University of technology [standard answer]
Judge whether it is a balanced binary tree
Anaconda installation, jupyter notebook default startup path modification and nbextensions plug-in installation
What is the workflow of dry goods MapReduce?