CPack打包外部库
时间: 2023-07-02 22:12:12 浏览: 224
要使用CPack打包外部库,需要按照以下步骤操作:
1.在CMakeLists.txt文件中定义要打包的目标,包括库文件和头文件。例如:
```
add_library(mylib SHARED mylib.cpp)
target_include_directories(mylib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
```
2.在CMakeLists.txt文件中添加CPack相关设置。例如:
```
set(CPACK_GENERATOR "ZIP")
set(CPACK_PACKAGE_NAME "mylib")
set(CPACK_PACKAGE_VERSION "1.0.0")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "My library")
set(CPACK_PACKAGE_VENDOR "My Company")
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-src")
set(CPACK_SOURCE_GENERATOR "ZIP")
set(CPACK_SOURCE_IGNORE_FILES
"/build/"
"/.git/"
"/.idea/"
"/tmp/"
"/dist/"
)
include(CPack)
```
其中,`CPACK_GENERATOR`设置打包格式,`CPACK_PACKAGE_NAME`设置包名,`CPACK_PACKAGE_VERSION`设置版本号,`CPACK_PACKAGE_DESCRIPTION_SUMMARY`设置简介,`CPACK_PACKAGE_VENDOR`设置厂商,`CPACK_PACKAGE_FILE_NAME`设置生成包的文件名,`CPACK_SOURCE_PACKAGE_FILE_NAME`设置源代码包的文件名,`CPACK_RESOURCE_FILE_LICENSE`设置许可证文件路径,`CPACK_SOURCE_IGNORE_FILES`设置忽略的文件。
3.使用`cpack`命令生成打包文件。例如:
```
$ mkdir build
$ cd build
$ cmake ..
$ make
$ cpack --config CPackConfig.cmake
```
生成的打包文件会在build目录下生成。
阅读全文