问题描述
cmake文件应安装在哪里?我目前有安装目标
Where should cmake files be installed? I currently have for the install targets
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
或类似的文件夹.
For Windows builds, it should be installed with CMAKE_INSTALL_PREFIX=C:/libs/project
. When installing it in Linux with CMAKE_INSTALL_PREFIX=/usr
or /usr/local
, I am not sure if the cmake files should be installed in /usr/share/cmake
or a similar folder.
最后,它应该以合理的方式使用两种方法(/usr
和 path/to/libdir
).
In the end, it should work with both methods (/usr
and path/to/libdir
) in a reasonable way.
推荐答案
根据官方的cmake文档,有几种可能性可以安装这些cmake文件.为了使用 find_package()
命令查找库,该位置很重要.取决于平台,可能的位置是:
According to the official cmake documentation there are several possibilities where these cmake files should be installed. The location is important in order to find the library using the find_package()
command. Depending on the platform possible locations are:
<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}
,在/usr/local .
The prefix is defined by the
CMAKE_INSTALL_PREFIX
variable which defaults to C:/Program Files/${PROJECT_NAME}
on Windows and /usr/local
on Unix.
在我的Arch Linux系统上,大多数库都使用
< prefix>/lib */cmake/< name> */
(Unix风格)位置.对于Windows个人,我更喜欢< prefix>/cmake
位置.
On my Arch Linux system most libraries are using the
<prefix>/lib*/cmake/<name>*/
(Unix style) location. For windows personally I would prefer the <prefix>/cmake
location.
有关更多详细信息,建议您阅读CMake版本的官方文档(有关v3.14,请参见下面参考中的链接).
For more detailed information I would recommend you to read the official documentation for your CMake version (for v3.14 see the links in the references below).
参考:
https://cmake.org/cmake/help/v3.14/variable/CMAKE_INSTALL_PREFIX.html
https://cmake.org/cmake/help/v3.14/command/find_package.html?highlight=find_package#id5
这篇关于cmake文件应安装在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!