xmake is a lightweight cross-platform build tool based on Lua. It uses xmake.lua to maintain project builds. Compared with makefile/CMakeLists.txt, the configuration syntax is more Concise and intuitive, it is very friendly to novices, and you can get started quickly in a short time, allowing users to focus more on actual project development.
In version 2.5.4, we added support for Apt and Portage package managers. On Ubuntu/Gentoo, we can also use add_requires
to quickly integrate the packages they provide.
And we have also improved the support for the Vcpkg package manager, and added support for the installation of arm/arm64 architecture packages.
In addition, we have also enhanced the xrepo env shell
environment. You can load a shell environment with a specific package configuration by configuring a series of add_requires
package configurations in xmake.lua
.
Now we support the use of apt to integrate dependent packages, and will also automatically find packages that have been installed on the ubuntu system.
add_requires("apt::zlib1g-dev", {alias = "zlib"})
target("test")
set_kind("binary")
add_files("src/*.c")
add_packages("zlib")
We also support the use of Portage to integrate dependency packages, and will automatically find packages already installed on the Gentoo system.
add_requires("portage::libhandy", {alias = "libhandy"})
target("test")
set_kind("binary")
add_files("src/*.c")
add_packages("libhandy")
XMake is a modern C/C++ build system based on Lua.
Its grammar is concise and easy to use, friendly to novices, even if you don’t know Lua at all, you can get started quickly, and it is completely free of any dependencies, lightweight, and cross-platform.
At the same time, it is also a self-satisfied build system with a powerful package management system and a fast build engine.
Compared with Ninja/Scons/Make as Build backend
, CMake/Meson as Project Generator
, and XMake not only provides Build backend
and Project Generator
at the same time, it also provides a built-in package manager.
xmake = Build backend + Project Generator + Package Manager
Therefore, you only need to install an XMake installation package that is less than 3M, and you don’t need to install other tools. You don’t even need to install make, and you don’t need to install heavyweight runtime environments such as Python and Java. You can quickly start your C/C++ development journey.
Maybe someone will say that the compiler always needs to be installed. This is not necessary, because XMake’s package management also supports automatically to pull remote compilation toolchains, such as llvm, Mingw, Android NDK or cross-compilation toolchain.
Whenever discussing XMake with others in the Reddit community, everyone will always use the following picture to complain.
Although I was a little helpless and numb by the complaints, I still want to explain that the original intention of XMake was not to split the C/C++ ecology. On the contrary, XMake reuses the existing ecology as much as possible.
At the same time, it also allows users to have the same good experience as other languages when developing C/C++ projects, such as Rust/Cargo, Nodejs/Npm, Dlang/Dub, instead of looking for the third package everywhere, and studying how to transplant and compile. toss.
Therefore, if you don’t know XMake, please don’t draw conclusions too early, you can try it first, or take a moment to read the detailed introduction below.
People often ask me what is special about XMake and what are the advantages compared to existing build tools such as CMake and Meson. Why should I use XMake instead of CMake?
Let me talk about the features and advantages first, XMake has the following points:
xmake is a lightweight cross-platform build tool based on Lua. It uses xmake.lua to maintain project builds. Compared with makefile/CMakeLists.txt, the configuration syntax is more Concise and intuitive, it is very friendly to novices, and you can get started quickly in a short time, allowing users to focus more on actual project development.
In version 2.5.3, we have been able to build linux and android bpf programs.
Although bpf has certain requirements for the compilation toolchain, such as the newer llvm/clang and android ndk toolchains, xmake can automatically pull a specific version of llvm/ndk for compilation, and it can also automatically pull libbpf dependencies. Library.
In addition, in the new version we have added support for the integration of C/C++ packages from Conda.
xmake is a lightweight cross-platform build tool based on Lua. It uses xmake.lua to maintain project builds. Compared with makefile/CMakeLists.txt, the configuration syntax is more Concise and intuitive, it is very friendly to novices, and you can get started quickly in a short time, allowing users to focus more on actual project development.
In version 2.5.2, we added a heavyweight new feature: Pull remote cross-compilation toolchain automatically
.
Those who have done cross-compilation and have experience in C/C++ project migration should know that it is very troublesome to toss various cross-compilation toolchains and transplant and compile projects. You need to download the corresponding toolchain yourself.
And it is easy to make mistakes in configuring the toolchain and the compilation environment to cause compilation failure.
Now, xmake can already support the automatic download of the toolchain required by the project, and then use the corresponding toolchain to directly compile the project.
The user does not need to care about how to configure the toolchain. In any case, just execute the xmake
command to complete the compilation.
Even for the integration of C/C++ dependent packages, you can automatically switch to the corresponding toolchain to compile, install, and integrate. Everything is fully automated and does not require users to worry about it.
In addition to the cross-compilation toolchain, we can also automatically pull toolchains, such as specific versions of llvm, llvm-mingw, zig and other toolchains to participate in the compilation of C/C++/Zig projects.
Even cmake does not support the automatic pull of the toolchain. At most, it can only cooperate with third-party package management such as vcpkg/conan to integrate C/C++ dependent packages. In addition, even for C/C++ dependent packages, xmake has its own native The built-in package management tool has no dependencies at all.
luarocks is a package management tool of lua, which provides the installation and integration of various lua modules.
When users install lua modules, it will use the built-in build system to build lua module with c/c++ codes.
However, it’s build system only provides simple configuration. For complex c/c++ modules, it is a little bit powerless, and it cannot be flexibly switch the toolchain.
Although it also provides other back-ends (make, cmake), but make/makefile is also not flexible enough, and cmake requires users to install the cmake program in advance, otherwise the installation of the lua module will be interrupted.
Here, I have implemented a luarocks plugin luarocks-build-xmake based on xmake to build lua c/c++ modules to achieve more flexible and convenient lua module maintenance.
Compared with the builtin build system of luarocks, it provides a more powerful build configuration and supports c/c++ dependency management. Compared with cmake, it does not require users to manually install xmake. This plugin will automatically install xmake and directly compile lua modules. In terms of users, no additional operations are required.
We can build c/c++ modules if the project contain xmake.lua
├── src
│ ├── test.c
│ └── test.h
└── xmake.lua
We need to use add_rules("luarocks.module")
to add build rules for luarocks modules.
add_rules("mode.debug", "mode.release")
target("example1.hello")
add_rules("luarocks.module")
add_files("src/test.c")
package = "example1"
version = "1.0-1"
source = {
url = "git://github.com/xmake-io/luarocks-build-xmake",
tag = "example1"
}
dependencies = {
"lua >= 5.1",
"luarocks-build-xmake"
}
build = {
type = "xmake",
copy_directories = {}
}