A Lua-based cross-platform build utility. Which also works for other programming languages like: Rust, Go and others.
xmake is a binary building tool for C and C++ languages with configuration files created with the Lua programming language.
xmake is simple, fast, light and has several tools included that facilitate the installation of binaries and has been adopted very quickly by programmers.
It has support for architectures: x86 64 and 32-bit, arm64, cross-toolchains and others. And also support for several operating systems, such as:
It also supports the varied list of toolchains, such as:
And among others!, plus many additional features!
In several tests performed it performed faster than ninja and cmake .
It is very easy to install xmake and there are several ways. The simplest is accessing the xmake website: https://xmake.io and note that you can install without sudo permission with:
This way of installation is more interesting for you to inform in a README.md for the user to install quickly and easily to compile some project of yours that uses xmake
.
But this way, despite working very well, limits the use of some xmake parameters, for example parameter: install
.
So let’s install via Git for that we’ll need compile-time dependencies:
Now let’s clone the repository (in the upper right corner of the site there is a link):
Enter the directory and install the submodule for LuaJIT:
After finished let’s run:
At the end we will install:
Now let’s create the autocomplete for the xmake
command:
Now let’s clean the files:
~/.xmake/profile
also installs a binary in ~/.local/bin
, as we installed on the system we don’t need it and if you have this path in your $PATH
variable will cause some problems, so let’s remove it:To make sure the autocomplete runs too:
#1. Basic build from scratch
To get started, let’s look at the most basic way to use xmake
.
Let’s create a directory of an example project, enter it and create the file: main.cpp
:
With the following content:
Now let’s create the Lua xmake configuration file: nvim xmake.lua
and inside it we’ll fill it like this:
To compile:
Rotate:
Parameters auto-complete
Or just:
xmake run
If you want to install the binary just run the command:
Also autocomplete.
The binary will be copied to the default directory: /usr/local/bin
.
And then just run the binary:
To uninstall, just run:
#2. Basic AUTOMATIC Build
If you find it laborious to create the project files by hand, there is also an option for you to hand over all that work to xmake
. For that, let’s remove this [my-project] that was just an example and let’s recreate it dynamically
Exiting and removing:
And now let’s create the project dynamically:
If you do not enter the name, but have it inside your project’s name directory, a subdirectory of the same name will be automatically created.
Now let’s go into the directory and notice that everything is ready, if you want to open the files to see the content.
So let’s build:
And now instead of installing, let’s automatically generate a Makefile for our project:
We can also generate configuration files for other cross platform tools like ninja and cmake, for example by creating a CMakeLists.txt
:
We can run make clean
and then just make to build: make
. If we run xmake package
it will generate a package from our binary and from here we can also query the command history, for example, if we run xmake show
it will display our project data and then we can query the command history rounds:
#3. Compiling multiple files
Just create xmake.lua
and add the files:
Then just run:
xmake
andxmake run
mkdir windows && cd windows
Let’s use the example of this link: https://terminalroot.com.br/ncurses/#8-janelas . Thexmake.lua
will look like this:
Here:
./windows/
:xmake && xmake run
According to the Gtkmm series we made, I updated the repository and the README, that is, just go there, read the README and see the file: xmake.lua
:
The xmake.lua file from this repository corresponds to the Makefile
(which we created in the Gtkmm series videos):
If you need to install files like
.md
.desktop
Use, examples:
#5. Compiling for Rust
Via command line:
Running in a subshell:
#10. Getting more information from commands
The video is in Portuguese, but you can see the commands as they are universal!
It is a modern and very interesting and promising tool that is worth using.
For more information visit the website and explore the documentation.