CMake -- CPack工具

CMake – CPack工具

简介

基于上一篇的 cmake与qmake转换,然后写了这一篇CMake打包工具。

官网介绍:Configure generators for binary installers and source packages

本篇主要介绍打包的为deb安装包。

支持打包格式

  • 7Z(7-Zip file format)
  • DEB (Debian packages)
  • External (CPack External packages)
  • IFW (Qt Installer Framework)
  • NSIS (Null Soft Installer)
  • NSIS64 (Null Soft Installer (64-bit))
  • NuGet (NuGet packages)
  • RPM (RPM packages)
  • STGZ (Self extracting Tar GZip compression
  • TBZ2 (Tar GZip compression)
  • TXZ (Tar XZ compression)
  • TZ (Tar Compress compression)
  • ZIP (ZIP file format)

语法介绍

demo

demo是直接粘贴在CMakeList.txt最后。

include (InstallRequiredSystemLibraries)

set(_VERSION_MAJOR 1)
set(_VERSION_MINOR 1)
set(_VERSION_PATCH 0)

set(CPACK_GENERATOR "DEB")

set(CPACK_PACKAGE_VERSION_MAJOR "${_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${_VERSION_PATCH}")

set(CPACK_PACKAGING_NAME "xxxx")
set(CPACK_SET_DESTDIR ON)
set(CPACK_INSTALL_PREFIX "/usr/local/xxxx")
set(CPACK_DEBIAN_PACKAGE_NAME "xxxx")
set(CPACK_PACKAGE_DESCRIPTION "xxxxx Package")
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "${CMAKE_HOST_SYSTEM_PROCESSOR}")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "freerdp (>= 2.2.0), spice-gtk (>=0.35), cJSON (), celt (>=0.5.1.3), paho.mqtt.c (>=1.3.1), spice-protocol (>=0.12.14), usbredir (>=0.8.0)"
set(CPACK_PACKAGE_DESCRIPTION "xxxxx")
set(CPACK_PACKAGE_CONTACT "xxxx")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "SiYuetian")
set(CPACK_PACKAGE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../output)

install_files(/depends FILES ${CMAKE_CURRENT_SOURCE_DIR}/../depends/)
install_files(/res FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/)
install_files(/lib FILES ./lib/)
install_files(. FILES ./RdpClient)
include(CPack)
#引入 InstallRequiredSystemLibraries 模块,支持cpack
include (InstallRequiredSystemLibraries)

#设置打包格式 deb
set(CPACK_GENERATOR "DEB")

#设置版本信息: 
##主版本信息
set(_VERSION_MAJOR 1)
##次版本信息
set(_VERSION_MINOR 1)
##补丁信息
set(_VERSION_PATCH 0)

##主版本信息
set(CPACK_PACKAGE_VERSION_MAJOR "${_VERSION_MAJOR}")
##次版本信息
set(CPACK_PACKAGE_VERSION_MINOR "${_VERSION_MINOR}")
##补丁信息
set(CPACK_PACKAGE_VERSION_PATCH "${_VERSION_PATCH}")

#设置生成包名
set(CPACK_PACKAGING_NAME "xxxx")
#开启包重定向
set(CPACK_SET_DESTDIR ON)
#设置安装位置
set(CPACK_INSTALL_PREFIX "/usr/local/xxxx")
#设置deb包名,包名格式 ${CPACK_DEBIAN_PACKAGE_NAME}.版本信息.平台信息.deb
set(CPACK_DEBIAN_PACKAGE_NAME "xxxx")
#设置包描述
set(CPACK_PACKAGE_DESCRIPTION "xxxxx Package")
#设置包安装平台信息
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "${CMAKE_HOST_SYSTEM_PROCESSOR}")
#设置依赖包信息
set(CPACK_DEBIAN_PACKAGE_DEPENDS "freerdp (>= 2.2.0), spice-gtk (>=0.35), cJSON (), celt (>=0.5.1.3), paho.mqtt.c (>=1.3.1), spice-protocol (>=0.12.14), usbredir (>=0.8.0)"
#设置联系人信息
set(CPACK_PACKAGE_CONTACT "xxxx")
#设置维护人信息
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "SiYuetian")
#设置包输出路径
set(CPACK_PACKAGE_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../output)

#设置安装文件
##设置依赖文件-${CPACK_INSTALL_PREFIX}/depends
install_files(/depends FILES ${CMAKE_CURRENT_SOURCE_DIR}/../depends/)
##设置资源文件-${CPACK_INSTALL_PREFIX}/res
install_files(/res FILES ${CMAKE_CURRENT_SOURCE_DIR}/res/)
##设置依赖库文件-${CPACK_INSTALL_PREFIX}/lib
install_files(/lib FILES ./lib/)
##设置可执行文件-${CPACK_INSTALL_PREFIX}/
install_files(. FILES ./RdpClient)
#引入CPack
include(CPack)

语法详解

install()

查看该博客: install详解

cmake官方解释:install()

install_files()

  • tall_files(<dir> extension file file ...)
    

    Create rules to install the listed files with the given extension into the given directory. Only files existing in the current source tree or its corresponding location in the binary tree may be listed. If a file specified already has an extension, that extension will be removed first. This is useful for providing lists of source files such as foo.cxx when you want the corresponding foo.h to be installed. A typical extension is .h

  • install_files(<dir> regexp)
    

    Any files in the current source directory that match the regular expression will be installed.

  • install_files(<dir> FILES file file ...)
    

    Any files listed after the FILES keyword will be installed explicitly from the names given. Full paths are allowed in this form.

install_targets()

  • install_targets(<dir> [RUNTIME_DIRECTORY dir] target target)
    

    Create rules to install the listed targets into the given directory. The directory <dir> is relative to the installation prefix, which is stored in the variable CMAKE_INSTALL_PREFIX. If RUNTIME_DIRECTORY is specified, then on systems with special runtime files (Windows DLL), the files will be copied to that directory.

install_programs()

  • install_programs(<dir> file1 file2 [file3 ...])
    install_programs(<dir> FILES file1 [file2 ...])
    

    Create rules to install the listed programs into the given directory. Use the FILES argument to guarantee that the file list version of the command will be used even when there is only one argument.

  • install_programs(<dir> regexp)
    

    In the second form any program in the current source directory that matches the regular expression will be installed.

注意:<dir>为默认路径,例如上文install_files(/lib FILES ./lib/),安装文件路径为 ${CPACK_INSTALL_PREFIX}/lib,重定向安装路径已经默认引入,<dir>默认等同于${CPACK_INSTALL_PREFIX}/<dir>,为重定向路径的相对路径.

生成

下边是一个简单的生成脚本.

#!/bin/bash
#

cd 'dirname $0'

mkdir -p build
cd build
cmake .. $1 #$1是CMake编译参数,可自由扩展
make -j`lscpu  -J|grep '"CPU(s):"'|awk 'BEGIN{FS="\""}{print$8}'`
mkdir -p lib
cp `ldd ./RdpClient | cut -d ">" -f 2 |grep lib|cut -d "(" -f 1|xargs` lib/
cpack --config CPackConfig.cmake --verbose
cd ..
rm -rf build
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值