Skip to content

Commit

Permalink
Use CMAKE_INSTALL_LIBDIR (#819)
Browse files Browse the repository at this point in the history
We always use "lib" for library directory but Debian/Ubuntu use
"lib/x86_64-linux-gnu" and RHEL use "lib64" on 64bit.

CMake provides CMAKE_INSTALL_LIBDIR that abstracts system library
directory. We can use it by including GNUInstallDirs.
See also: https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html
  • Loading branch information
kou authored Feb 26, 2024
1 parent a523fc6 commit 094699b
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -593,10 +593,11 @@ endif()
# Installation (https://github.com/forexample/package-example)

# Layout. This works for all platforms:
# * <prefix>/lib/cmake/<PROJECT-NAME>
# * <prefix>/lib/
# * <prefix>/<CMAKE_INSTALL_LIBDIR>/cmake/<PROJECT-NAME>
# * <prefix>/<CMAKE_INSTALL_LIBDIR>/
# * <prefix>/include/
set(config_install_dir "lib/cmake/${PROJECT_NAME}")
include(GNUInstallDirs)
set(config_install_dir "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}")
set(include_install_dir "include")

set(generated_dir "${CMAKE_CURRENT_BINARY_DIR}/generated")
Expand Down Expand Up @@ -632,7 +633,7 @@ configure_package_config_file(
)

# Targets:
# * <prefix>/lib/libh3.so
# * <prefix>/<CMAKE_INSTALL_LIBDIR>/libh3.so
# * header location after install: <prefix>/include/h3/h3api.h
# * headers can be included by C++ code `#include <h3/h3api.h>`
# Installing the library and filters system-wide.
Expand All @@ -647,8 +648,8 @@ install(
TARGETS h3
EXPORT "${TARGETS_EXPORT_NAME}"
COMPONENT libh3
LIBRARY DESTINATION "lib"
ARCHIVE DESTINATION "lib"
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "bin"
INCLUDES DESTINATION "${include_install_dir}"
)
Expand All @@ -663,16 +664,16 @@ install(
)

# Config
# * <prefix>/lib/cmake/h3/h3Config.cmake
# * <prefix>/lib/cmake/h3/h3ConfigVersion.cmake
# * <prefix>/<CMAKE_INSTALL_LIBDIR>/cmake/h3/h3Config.cmake
# * <prefix>/<CMAKE_INSTALL_LIBDIR>/cmake/h3/h3ConfigVersion.cmake
install(
FILES "${project_config}" "${version_config}"
DESTINATION "${config_install_dir}"
COMPONENT libh3-dev
)

# Config
# * <prefix>/lib/cmake/h3/h3Targets.cmake
# * <prefix>/<CMAKE_INSTALL_LIBDIR>/cmake/h3/h3Targets.cmake
install(
EXPORT "${TARGETS_EXPORT_NAME}"
NAMESPACE "${namespace}"
Expand Down

0 comments on commit 094699b

Please sign in to comment.