cmake文件应安装在哪里?我目前有安装目标
cmake_minimum_required(VERSION 2.8.10)
project(projectname)
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
add_library(projectnameINTERFACE)
target_include_directories(projectnameINTERFACE
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/projectname>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/>
)
configure_package_config_file(projectnameConfig.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/projectnameConfig.cmake INSTALL_DESTINATION ${CMAKE_INSTALL_PREFIX})
install(TARGETS projectnameEXPORT projectname-targets)
install(EXPORT projectname-targets FILE projectnameTargets.cmake DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/projectnameConfig.cmake DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/cmake)
install(DIRECTORY ./ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/projectname FILES_MATCHING PATTERN "*.h" PATTERN ".git" EXCLUDE)
路径${CMAKE_INSTALL_PREFIX}/share/projectname/cmake
是否正确?
对于Windows构建,应与CMAKE_INSTALL_PREFIX=C:/libs/project
一起安装。当使用CMAKE_INSTALL_PREFIX=/usr
或/usr/local
在Linux上安装它时,我不确定cmake文件是否应该安装在/usr/share/cmake
或类似文件夹中。
最后,它应该以合理的方式使用两种方法(/usr
和path/to/libdir
)。
答案 0 :(得分:2)
根据官方的cmake文档,有几种可能性可以安装这些cmake文件。为了使用find_package()
命令查找库,该位置很重要。取决于平台,可能的位置是:
<prefix>/ (Windows)
<prefix>/(cmake|CMake)/ (Windows)
<prefix>/<name>*/ (Windows)
<prefix>/<name>*/(cmake|CMake)/ (Windows)
<prefix>/(lib/<arch>|lib*|share)/cmake/<name>*/ (Unix)
<prefix>/(lib/<arch>|lib*|share)/<name>*/ (Unix)
<prefix>/(lib/<arch>|lib*|share)/<name>*/(cmake|CMake)/ (Unix)
<prefix>/<name>*/(lib/<arch>|lib*|share)/cmake/<name>*/ (Windows/Unix)
<prefix>/<name>*/(lib/<arch>|lib*|share)/<name>*/ (Windows/Unix)
<prefix>/<name>*/(lib/<arch>|lib*|share)/<name>*/(cmake|CMake)/ (Windows/Unix)
<prefix>/<name>.framework/Resources/ (macOS)
<prefix>/<name>.framework/Resources/CMake/ (macOS)
<prefix>/<name>.framework/Versions/*/Resources/ (macOS)
<prefix>/<name>.framework/Versions/*/Resources/CMake/ (macOS)
<prefix>/<name>.app/Contents/Resources/ (macOS)
<prefix>/<name>.app/Contents/Resources/CMake/ (macOS)
前缀由CMAKE_INSTALL_PREFIX
变量定义,在Windows中默认为C:/Program Files/${PROJECT_NAME}
,在Unix中默认为/usr/local
。
在我的Arch Linux系统上,大多数库都使用<prefix>/lib*/cmake/<name>*/
(Unix风格)位置。对于Windows个人,我更希望使用<prefix>/cmake
位置。
有关更多详细信息,我建议您阅读CMake版本的官方文档(有关v3.14,请参见下面参考中的链接)。
参考: