环境说明
本文的编译在Ubuntu18.04上进行。
编译过程
首先下载代码,地址是https://gitlab.freedesktop.org/dbus/dbus/-/tree/master。这里以1.10版本为例,文件如下:
首先需要创建Makefile文件,这需要用到cmake。因为D-Bus是支持不同操作系统和平台的,所以为了“一次编写,到处可用”,它使用了cmake来定制编译流程。在Linux平台下,就需要先通过工具来生成真正可用的Makefile文件。
cmake执行过中可能会报错,原因是缺少某些工具,这里先进行安装(包括cmake本身):
sudo apt install gcc cmake g++ libexpat1-dev
cmake执行命令如下,需要在代码根目录下执行:
cmake ./cmake
第一个cmake是命令,第二个cmake是目录,该目录下有CMakeLists.txt。cmake还支持各类参数,包括cmake本身的参数,以及D-Bus支持的参数,后者在代码根目录下的README.cmake文件中有说明,比如:
When using the cmake build system the dbus-specific configuration flags that can be given
to the cmake program are these (use -D<key>=<value> on command line). The listed values
are the defaults (in a typical build - some are platform-specific).
// Choose the type of build, options are: None(CMAKE_CXX_FLAGS or
// CMAKE_C_FLAGS used) Debug Release RelWithDebInfo MinSizeRel.
CMAKE_BUILD_TYPE:STRING=Debug
// Include path for 3rdparty packages
CMAKE_INCLUDE_PATH:PATH=
// Library path for 3rdparty packages
CMAKE_LIBRARY_PATH:PATH=
// Install path prefix, prepended onto install directories.
CMAKE_INSTALL_PREFIX:PATH=C:/Program Files/dbus
// enable unit test code
DBUS_BUILD_TESTS:BOOL=ON
// The name of the dbus daemon executable
DBUS_DAEMON_NAME:STRING=dbus-daemon
如果要增加参数,其格式如下:
cmake -D DBUS_DAEMON_NAME:STRING=dbus-daemon ./cmake
cmake命令执行的结果:
之后就可以直接通过make来进行编译,结果如下:
生成的工具在bin目录下:
以上是D-Bus编译的基本内容。