diff --git a/CMakeLists.txt b/CMakeLists.txt index 0dab56839..35fae01c7 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -575,6 +575,8 @@ if(WITH_ASCEND) ) endif() +include(${PROJECT_SOURCE_DIR}/cmake/config_cpack.cmake) + ############################### Building: FastDeploy Python Wheel ############################# if(BUILD_FASTDEPLOY_PYTHON) add_definitions(-DBUILD_FASTDEPLOY_PYTHON) diff --git a/cmake/config_cpack.cmake b/cmake/config_cpack.cmake new file mode 100644 index 000000000..e91edd4ed --- /dev/null +++ b/cmake/config_cpack.cmake @@ -0,0 +1,38 @@ +if(NOT UNIX) + return() +endif() + +set(PACKAGE_SYS_VERSION "linux") +if(CMAKE_HOST_SYSTEM_PROCESSOR MATCHES "aarch64") + set(PACKAGE_SYS_VERSION "${PACKAGE_SYS_VERSION}-aarch64") +else() + set(PACKAGE_SYS_VERSION "${PACKAGE_SYS_VERSION}-x64") +endif() +if(WITH_GPU) + set(PACKAGE_SYS_VERSION "${PACKAGE_SYS_VERSION}-gpu") +endif() + +# set(CPACK_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION ON) +set(CPACK_VERBATIM_VARIABLES TRUE) +set(CPACK_GENERATOR DEB RPM) +set(CPACK_THREADS 0) +set(CPACK_PACKAGE_CONTACT "fastdeploy@baidu.com") +set(CPACK_PACKAGING_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") +set(CPACK_PACKAGE_VERSION "${FASTDEPLOY_VERSION}") +set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PACKAGE_SYS_VERSION}-${FASTDEPLOY_VERSION}") +set(CPACK_PACKAGE_NAME "${PROJECT_NAME}") + +set(CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION TRUE) +configure_file(cpack/debian_postinst.in cpack/postinst @ONLY) +configure_file(cpack/debian_prerm.in cpack/prerm @ONLY) +set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA + "${CMAKE_CURRENT_BINARY_DIR}/cpack/postinst" + "${CMAKE_CURRENT_BINARY_DIR}/cpack/prerm") + +set(CPACK_RPM_PACKAGE_AUTOREQ FALSE) +configure_file(cpack/rpm_postinst.in cpack/rpm_postinst @ONLY) +configure_file(cpack/rpm_postrm.in cpack/rpm_postrm @ONLY) +set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/cpack/rpm_postinst") +set(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_BINARY_DIR}/cpack/rpm_postrm") + +include(CPack) diff --git a/cpack/debian_postinst.in b/cpack/debian_postinst.in new file mode 100644 index 000000000..2af6fa99a --- /dev/null +++ b/cpack/debian_postinst.in @@ -0,0 +1,42 @@ +#!/bin/bash + +case "$1" in + configure) + PLATFORM=`uname` + FASTDEPLOY_LIBRARY_PATH=@CMAKE_INSTALL_PREFIX@ + + echo "=============== Information ======================" + echo "FastDeploy Library Path: $FASTDEPLOY_LIBRARY_PATH" + echo "Platform: $PLATFORM" + echo "==================================================" + + # Find all the .so files' path + ALL_SO_FILES=`find $FASTDEPLOY_LIBRARY_PATH -name "*.so*"` + for SO_FILE in $ALL_SO_FILES;do + LIBS_DIRECOTRIES[${#LIBS_DIRECOTRIES[@]}]=${SO_FILE%/*} + done + + # Remove the dumplicate directories + LIBS_DIRECOTRIES=($(awk -v RS=' ' '!a[$1]++' <<< ${LIBS_DIRECOTRIES[@]})) + + IMPORT_PATH="" + for LIB_DIR in ${LIBS_DIRECOTRIES[@]};do + echo "Found Library Directory: $LIB_DIR" + echo ${LIB_DIR} >> @CMAKE_INSTALL_PREFIX@/@CPACK_PACKAGE_NAME@.conf + done + + if [ ! -d /etc/ld.so.conf.d ]; then + mkdir -p /etc/ld.so.conf.d + fi + ln -sf @CMAKE_INSTALL_PREFIX@/@CPACK_PACKAGE_NAME@.conf /etc/ld.so.conf.d + + ldconfig + + echo "FastDeploy is successfully installed and configured." + echo "Now please get started with FastDeploy examples at $FASTDEPLOY_LIBRARY_PATH/examples." + echo "And don't forget to set FASTDEPLOY_INSTALL_DIR=$FASTDEPLOY_LIBRARY_PATH in cmake when building examples." + ;; + *) + echo "postinst called with unknown argument \`$1'" >&2 + exit 1 +esac diff --git a/cpack/debian_prerm.in b/cpack/debian_prerm.in new file mode 100644 index 000000000..8295fc410 --- /dev/null +++ b/cpack/debian_prerm.in @@ -0,0 +1,12 @@ +#!/bin/bash + +case "$1" in + remove|deconfigure) + rm -f /etc/ld.so.conf.d/@CPACK_PACKAGE_NAME@.conf + rm @CMAKE_INSTALL_PREFIX@/@CPACK_PACKAGE_NAME@.conf + rm -rf @CMAKE_INSTALL_PREFIX@/third_libs/install/tensorrt/lib/ + + ldconfig + echo "FastDeploy is going to be uninstalled." + ;; +esac diff --git a/cpack/rpm_postinst.in b/cpack/rpm_postinst.in new file mode 100644 index 000000000..0b1c10f3e --- /dev/null +++ b/cpack/rpm_postinst.in @@ -0,0 +1,35 @@ +#!/bin/bash + +PLATFORM=`uname` +FASTDEPLOY_LIBRARY_PATH=@CMAKE_INSTALL_PREFIX@ + +echo "=============== Information ======================" +echo "FastDeploy Library Path: $FASTDEPLOY_LIBRARY_PATH" +echo "Platform: $PLATFORM" +echo "==================================================" + +# Find all the .so files' path +ALL_SO_FILES=`find $FASTDEPLOY_LIBRARY_PATH -name "*.so*"` +for SO_FILE in $ALL_SO_FILES;do + LIBS_DIRECOTRIES[${#LIBS_DIRECOTRIES[@]}]=${SO_FILE%/*} +done + +# Remove the dumplicate directories +LIBS_DIRECOTRIES=($(awk -v RS=' ' '!a[$1]++' <<< ${LIBS_DIRECOTRIES[@]})) + +IMPORT_PATH="" +for LIB_DIR in ${LIBS_DIRECOTRIES[@]};do + echo "Found Library Directory: $LIB_DIR" + echo ${LIB_DIR} >> @CMAKE_INSTALL_PREFIX@/@CPACK_PACKAGE_NAME@.conf +done + +if [ ! -d /etc/ld.so.conf.d ]; then + mkdir -p /etc/ld.so.conf.d +fi +ln -sf @CMAKE_INSTALL_PREFIX@/@CPACK_PACKAGE_NAME@.conf /etc/ld.so.conf.d + +ldconfig + +echo "FastDeploy is successfully installed and configured." +echo "Now please get started with FastDeploy examples at $FASTDEPLOY_LIBRARY_PATH/examples." +echo "And don't forget to set FASTDEPLOY_INSTALL_DIR=$FASTDEPLOY_LIBRARY_PATH in cmake when building examples." diff --git a/cpack/rpm_postrm.in b/cpack/rpm_postrm.in new file mode 100644 index 000000000..53f969805 --- /dev/null +++ b/cpack/rpm_postrm.in @@ -0,0 +1,8 @@ +#!/bin/bash + +rm -f /etc/ld.so.conf.d/@CPACK_PACKAGE_NAME@.conf +rm @CMAKE_INSTALL_PREFIX@/@CPACK_PACKAGE_NAME@.conf +rm -rf @CMAKE_INSTALL_PREFIX@/third_libs/install/tensorrt/lib/ + +ldconfig +echo "FastDeploy has been uninstalled." diff --git a/docs/cn/faq/build_fastdeploy_package.md b/docs/cn/faq/build_fastdeploy_package.md new file mode 100644 index 000000000..527ee8bdf --- /dev/null +++ b/docs/cn/faq/build_fastdeploy_package.md @@ -0,0 +1,39 @@ +中文 | [English](../../en/faq/build_fastdeploy_package.md) + +# 编译FastDeploy C++安装包 + +FastDeploy提供了Debian安装包和RPM安装包的打包工具,用于生成FastDeploy C++ SDK的安装包。相比于Tar压缩包,安装包具有以下优势: +- 安装时,自动运行脚本来配置lib路径,不需要用户手动设置LD_LIBRARY_PATH等环境变量 +- 自动管理依赖库关系和版本,自动安装依赖项 + +## Debian安装包 + +Debian安装包适用于Debian系列的Linux发行版,例如Ubuntu + +``` +# 设置编译选项,运行cmake和make +cmake .. -DENABLE_PADDLE_BACKEND=ON -DENABLE_VISION=ON -DCMAKE_INSTALL_PREFIX=/opt/paddlepaddle/fastdeploy +make -j + +# 运行cpack,生成.deb安装包 +cpack -G DEB + +# 安装.deb +dpkg -i xxx.deb +``` + +## RPM安装包 + +RPM安装包适用于RedHat系列的Linux发行版,例如CentOS + +``` +# 设置编译选项,运行cmake和make +cmake .. -DENABLE_PADDLE_BACKEND=ON -DENABLE_VISION=ON -DCMAKE_INSTALL_PREFIX=/opt/paddlepaddle/fastdeploy +make -j + +# 运行cpack,生成.rpm安装包 +cpack -G RPM + +# 安装.rpm +rpm -i xxx.rpm +``` diff --git a/docs/en/faq/build_fastdeploy_package.md b/docs/en/faq/build_fastdeploy_package.md new file mode 100644 index 000000000..63d0c6072 --- /dev/null +++ b/docs/en/faq/build_fastdeploy_package.md @@ -0,0 +1,39 @@ +English | [中文](../../cn/faq/build_fastdeploy_package.md) + +# Build FastDeploy C++ SDK Installation Package + +FastDeploy provides packaging tools for Debian installation packages and RPM installation packages, which are used to generate installation packages for FastDeploy C++ SDK. Compared with the Tar compression package, the installation package has the following advantages: +- During installation, the script is automatically run to configure the lib path, so that users don't need to manually set environment variables such as LD_LIBRARY_PATH +- Automatically manage dependencies and versions, and automatically install dependencies + +## Debian Package + +Debian Package is for Linux distributions of the Debian family, such as Ubuntu + +``` +# Setup build options, run cmake and make +cmake .. -DENABLE_PADDLE_BACKEND=ON -DENABLE_VISION=ON -DCMAKE_INSTALL_PREFIX=/opt/paddlepaddle/fastdeploy +make -j + +# Run cpack to generate a .deb package +cpack -G DEB + +# Install .deb package +dpkg -i xxx.deb +``` + +## RPM Package + +RPM Package is for Linux distributions of the RedHat family, such as CentOS + +``` +# Setup build options, run cmake and make +cmake .. -DENABLE_PADDLE_BACKEND=ON -DENABLE_VISION=ON -DCMAKE_INSTALL_PREFIX=/opt/paddlepaddle/fastdeploy +make -j + +# Run cpack to generate a .rpm package +cpack -G RPM + +# Install .rpm package +rpm -i xxx.rpm +```