There are not many new features in this version. It mainly supports c++ 20 modules experimentally. Currently it supports the clang/msvc compiler. In addition, it improves a lot of user experience and improves some stability.
In addition, this version adds socket.io support and scheduling support for coroutine io to prepare for remote compilation of the next version and subsequent distributed compilation.
c++ modules have been officially included in the c++20 draft, and msvc and clang have been basically implemented on modules-ts Support, as c++20’s footsteps are getting closer and closer to us, xmake has also begun to support c++modules in advance.
At present xmake has fully supported the implementation of the modules-ts of msvc/clang. For gcc, since its cxx-modules branch is still under development, it has not officially entered the master. I have read the changelog inside, and the related flags are still in the process. Constantly changing, I feel that it has not stabilized, so I have not supported it yet.
For more information about xmake’s progress on c++modules: https://github.com/xmake-io/xmake/pull/569
I will not talk about the introduction of c++modules. This is mainly about how to build a c++modules project under xmake. Let’s look at a simple example:
target("hello")
set_kind("binary")
add_files("src/*.cpp", "src/*.mpp")
The above is a description of the xmake.lua that supports building c++modules files, where hello.mpp
is the module file:
#include <cstdio>
export module hello;
using namespace std;
export namespace hello {
void say(const char* str) {
printf("%s\n", str);
}
}
Main.cpp is the main program that uses the hello module:
import hello;
int main() {
hello::say("hello module!");
return 0;
}
Next we execute xmake to build this program:
ruki:hello ruki$ xmake
[0%]: ccache compiling.release src/hello.mpp
[50%]: ccache compiling.release src/main.cpp
[100%]: linking.release hello
build ok!
xmake is a lightweight and modern c/c++ project building tool based on Lua. It’s main features are: easy to use syntax, easy to use project maintenance, and a consistent build experience across platforms.
This article mainly explains in detail how to compile libraries and executable programs that can run under android through xmake.
First of all, we need to prepare the ndk toolchain necessary for compiling the android native library. If you haven’t, you can download and decompress it from the official websit: Android NDK
If you want to get better backward compatibility, you can choose the r16 version, because this is the last version that supports armeabi. If there is no special requirement, you can download the latest version directly.
We only need to pass the decompressed ndk directory path to xmake to complete the configuration, and we can compile directly, for example:
$ xmake f -p android --ndk=~/downloads/android-ndk-r19c
$ xmake
Among them, -p android
is used to switch to the android platform, because if you do not specify a platform, the target program of the current host platform will be compiled by default.
Generally, if there is no special requirement, the above configuration can complete the compilation of the android native program. Currently, xmake has built-in support for the generation of three types of target files: binary, static, and shared, which correspond to executable programs and .a static libraries. .so dynamic library.
Xmake is a lightweight and modern C/C++ project build tool based on Lua. Its main features are: easy to use syntax, easy to use project maintenance, and a consistent build experience across platforms.
This article mainly explains in detail how to write some commonly used basic xmake.lua description configurations to achieve some simple C/C++ project build management. For most small projects, these configurations are completely sufficient. In the later advanced tutorials in this series, I will explain in detail how to use some advanced features to configure the project more flexibly and customized.
One line of description compiles all c source files in the src directory, and then generates an executable file named demo.
target("demo", {kind = "binary", files = "src/*.c"})
The above is a condensed version. Generally, we recommend the following expansion method:
target("demo")
set_kind("binary")
add_files("src/*.c")
The two are completely equivalent. If the configuration is short, it can be completely reduced to one line, and splitting into multiple lines is more convenient and flexible.
If there is no special purpose, we will use the second paragraph.
There are three main types of object files generated by common C/C++ projects: executable programs, static libraries, and dynamic libraries.
We can set it through set_kind()
configuration, corresponding to: binary, static, shared
For example, if we want to compile the dynamic library, we just need to modify the kind:
target("demo")
set_kind("shared")
add_files("src/*.c")
The compilation macro settings are used by most c/c++ projects. Generally, if we set compilation flags to be passed to gcc/clang, we need to configure: -DXXX
In xmake, the add_defines()
built-in interface is provided for configuration:
target("demo")
set_kind("shared")
add_files("src/*.c")
add_defines("XXX")
Xmake is a lightweight modern C/C++ project build tool based on Lua. Its main features are: easy to use syntax, more readable project maintenance, and a consistent build experience across platforms.
This article mainly explains in detail how to load and run the compiled target program, and how to debug.
xmake also provides a run command to directly run the generated executable file for quick and easy testing, for example:
$ xmake run
hello xmake!
We can also add environment variables to set the default running target program through the add_runenvs
interface in xmake.lua.
Therefore, for PATH, it is very convenient to append values through this interface, and this interface supports multi-value setting, so it is usually used to set multi-value env with path sep. .
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")
For more description of this interface, you can see the documentation: add_runenvs interface documentation
Xmake is a lightweight modern C/C++ project build tool based on Lua. Its main features are: easy to use syntax, more readable project maintenance, and a consistent build experience across platforms.
This article focuses on how to create a xmake-based project and compilation operations.
Xmake provides the xmake create
command, which makes it easy to quickly create empty projects in various languages such as c/c++, swift, objc, such as:
$ xmake create test
create test ...
[+]: xmake.lua
[+]: src/main.cpp
[+]: .gitignore
create ok!
By default, a c++ hello world project is created, and a xmake.lua is generated in the root directory to describe the project’s build rules.
add_rules("mode.debug", "mode.release")
target("test")
set_kind("binary")
add_files("src/*.cpp")