xmake provides some project templates, you can easily create an empty project.
Create a c++ console project:
xmake create -l c++ -t 1 demo
or xmake create --language=c++ --template=1 demo
Create a c static library project:
xmake create -l c -t 5 demo
or xmake create --language=c --template=5 demo
Create a c shared library project:
xmake create -t 3 demo
or xmake create --template=3 demo
The default language is C language and -t/--template
argument is used to get specific types of templates.
Only supports three templates which are console, static library and shared library.
We will add some application templates in the future.
We need note that the template’s ID is variable.
Typically, you only need to execute the following command for compiling project.
xmake
xmake will probe your host environment and target platform automaticly.
The default mode is release and xmake will compile all targets.
You can compile only one given target which name is ‘test’ for executing the following command.
xmake test
If you want to complie the debug program, you need configure it for switching to the debug mode and compile it.
xmake config --mode=debug
xmake
We provide shorthand for each command, for example:
xmake f -m debug
xmake
Please run xmake --help
to get more info about it.
A simplest xmake.lua
-- define a target with named 'demo'
target("demo")
-- set the target kind, .e.g 'binary' is a console program
-- - static: a static library
-- - shared: a shared library
set_kind("binary")
-- add all c source files in the directory: src
add_files("src/*.c")
And we run the following command for building it.
xmake
Next, we write another xmake.lua for switching ‘debug’ or ‘release’ mode.
-- is debug now?
if is_mode("debug") then
-- enable debug symbols for debugger
set_symbols("debug")
-- disable optimization
set_optimize("none")
end
-- is release now?
if is_mode("release") then
-- set visibility as hidden
set_symbols("hidden")
-- enable optimization for fastest mode
set_optimize("fastest")
-- strip all symbols
set_strip("all")
end
-- define a target
target("test")
-- set the program kind as a static library
set_kind("static")
-- add all c++ files recursively
add_files("src/**.cpp")
We configure this project with the debug mode now.
xmake f -m debug
#xmake config --mode=debug
And we build it.
xmake
--sdk=xxx
xmake config --xxx=[y|n|yes|no|true|false]