cmake 添加 INSTALL

创建日期: 2025-01-17 11:05 | 作者: 风波 | 浏览次数: 16 | 分类: CMake

官方文档:https://cmake.org/cmake/help/latest/command/install.html 参考文档:https://stackoverflow.com/questions/10487256/cmake-how-to-properly-copy-static-librarys-header-file-into-usr-include

例子

project(myproject)

add_library(mylib some.c another.c)
set_target_properties(mylib PROPERTIES PUBLIC_HEADER "some.h;another.h")
INSTALL(TARGETS mylib 
        LIBRARY DESTINATION some/libpath
        PUBLIC_HEADER DESTINATION some/includepath
)

官网语法

install(TARGETS <target>... [...])
install(IMPORTED_RUNTIME_ARTIFACTS <target>... [...])
install({FILES | PROGRAMS} <file>... [...])
install(DIRECTORY <dir>... [...])
install(SCRIPT <file> [...])
install(CODE <code> [...])
install(EXPORT <export-name> [...])
install(PACKAGE_INFO <package-name> [...])
install(RUNTIME_DEPENDENCY_SET <set-name> [...])

The following table shows the target types with their associated variables and built-in defaults that apply when no destination is given:

Target Type GNUInstallDirs Variable Built-In Default
RUNTIME ${CMAKE_INSTALL_BINDIR} bin
LIBRARY ${CMAKE_INSTALL_LIBDIR} lib
ARCHIVE ${CMAKE_INSTALL_LIBDIR} lib
PRIVATE_HEADER ${CMAKE_INSTALL_INCLUDEDIR} include
PUBLIC_HEADER ${CMAKE_INSTALL_INCLUDEDIR} include
FILE_SET (type HEADERS) ${CMAKE_INSTALL_INCLUDEDIR} include

Each <artifact-kind> <artifact-option>... group applies to Output Artifacts of the specified artifact kind:

16 浏览
0 评论