title: Xmake v2.6.3 released, Support Vcpkg manifest mode tags: [xmake, lua, C/C++, Vcpkg] date: 2022-01-22 author: Ruki
This version mainly adds the following features:
The rest are mainly some scattered functional improvements and Bugs fixes. You can see the details of the update at the end of the following. Some major changes will be explained one by one below.
In the new version, Xmake adds vcpkg manifest mode support, through which we can support the version selection of vcpkg package, for example:
add_requires("vcpkg::zlib 1.2.11+10")
add_requires("vcpkg::fmt >=8.0.1", {configs = {baseline = "50fd3d9957195575849a49fa591e645f1d8e7156"}})
add_requires("vcpkg::libpng", {configs = {features = {"apng"}}})
target("test")
set_kind("binary")
add_files("src/*.cpp")
add_packages("vcpkg::zlib", "vcpkg::fmt", "vcpkg::libpng")
However, the version selection of vcpkg is still quite limited. It must be hard-coded to specify the baseline, and version semantic selection such as <=1.0, 1.x is not supported, but it is better than the previous version that cannot be selected.
CMake wrapper for Xrepo C and C++ package manager.
This allows using CMake to build your project, while using Xrepo to manage dependent packages. This project is partially inspired by cmake-conan.
Example use cases for this project:
Xrepo official repository: xmake-repo
xrepo.cmake provides xrepo_package function to manage packages.
xrepo_package(
"foo 1.2.3"
[CONFIGS feature1=true,feature2=false]
[MODE debug|release]
[OUTPUT verbose|diagnosis|quiet]
[DIRECTORY_SCOPE]
)
Some of the function arguments correspond directly to Xrepo command options.
After calling xrepo_package(foo), there are two ways to use foo package:
find_package(foo) if package provides cmake modules to find it
find_package documentation for more detailsIf the package does not provide cmake modules, foo_INCLUDE_DIR and
foo_LINK_DIR variables will be set to the package include and library paths.
Use these variables to setup include and library paths in your CMake code.
If DIRECTORY_SCOPE is specified, xrepo_package will run following code
(so that user only need to specify lib name in target_link_libraries)
include_directories(foo_INCLUDE_DIR)
link_directories(foo_LINK_DIR)
Here's an example CMakeLists.txt that uses gflags package version 2.2.2
managed by Xrepo.
cmake_minimum_required(VERSION 3.13.0)
project(foo)
# Download xrepo.cmake if not exists in build directory.
if(NOT EXISTS "${CMAKE_BINARY_DIR}/xrepo.cmake")
message(STATUS "Downloading xrepo.cmake from https://github.com/xmake-io/xrepo-cmake/")
# mirror https://cdn.jsdelivr.net/gh/xmake-io/xrepo-cmake@main/xrepo.cmake
file(DOWNLOAD "https://raw.githubusercontent.com/xmake-io/xrepo-cmake/main/xrepo.cmake"
"${CMAKE_BINARY_DIR}/xrepo.cmake"
TLS_VERIFY ON)
endif()
# Include xrepo.cmake so we can use xrepo_package function.
include(${CMAKE_BINARY_DIR}/xrepo.cmake)
# Call `xrepo_package` function to use gflags 2.2.2 with specific configs.
xrepo_package("gflags 2.2.2" CONFIGS "shared=true,mt=true")
# `xrepo_package` sets `gflags_DIR` variable in parent scope because gflags
# provides cmake modules. So we can now call `find_package` to find gflags
# package.
find_package(gflags CONFIG COMPONENTS shared)
In addition to installing packages from officially maintained repository, Xrepo can also install packages from third-party package managers such as vcpkg/conan/conda/pacman/homebrew/apt/dub/cargo.
For the use of the command line, we can refer to the documentation: Xrepo command usage
We can also use it directly in cmake to install packages from third-party repositories, just add the repository name as a namespace. e.g. vcpkg::zlib, conan::pcre2
xrepo_package("conan::gflags/2.2.2")
xrepo_package("conda::gflags 2.2.2")
xrepo_package("vcpkg::gflags")
xrepo_package("brew::gflags")
We can use this rule to generate python library modules with pybind11, which will adjust the module name of the python library.
add_rules("mode.release", "mode.debug")
add_requires("pybind11")
target("example")
add_rules("python.library")
add_files("src/*.cpp")
add_packages("pybind11")
set_languages("c++11")
with soabi:
add_rules("mode.release", "mode.debug")
add_requires("pybind11")
target("example")
add_rules("python.library", {soabi = true})
add_files("src/*.cpp")
add_packages("pybind11")
set_languages("c++11")
Through this interface, the specified file can be removed from the list of header files added by the add_headerfiles interface, for example:
target("test")
add_headerfiles("src/*.h")
remove_headerfiles("src/test.h")
In the above example, all header files except test.h can be added from the src directory, of course, this can also be achieved by add_headerfiles("src/*.h|test.h") to achieve the same purpose , but this way is more flexible.
After xmake config is executed, this script is executed before Build, which is usually used for configuration work before compilation. It differs from on_load in that on_load is executed as soon as the target is loaded, and the execution timing is earlier.
If some configuration cannot be configured prematurely in on_load, it can be configured in on_config.
In addition, its execution time is earlier than before_build, and the approximate execution flow is as follows:
on_load -> after_load -> on_config -> before_build -> on_build -> after_build
Xmake provides some built-in mirror configurations that can be used directly, such as github's mirror acceleration:
$ xmake g --proxy_pac=github_mirror.lua
We don't have to write pac.lua ourselves, we can use it directly to speed up the download of github sources.
python.library rule to build pybind modulesremove_files, remove_headerfiles and mark del_files as deprecatedxmake g --proxy_pac=github_mirror.lua