Reputation: 4236
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)
Is the path ${CMAKE_INSTALL_PREFIX}/share/projectname/cmake
correct?
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.
In the end, it should work with both methods (/usr
and path/to/libdir
) in a reasonable way.
Upvotes: 2
Views: 3880
Reputation: 56
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)
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.
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.
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).
References:
Upvotes: 4