Skip to content

Commit ebb7aeb

Browse files
authored
cmake: Use GNUInstallDirs for install paths and install pc file (#317)
This ensures that the correct include and library directories are used regardless of operating system target by leveraging the built-in GNUInstallDirs logic for determining the right directory paths. This also fixes the path for the CMake config module files to use the right location for header-only libraries. A pc(5) file for pkgconfig is now also created and installed.
1 parent 7d1b460 commit ebb7aeb

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

CMakeLists.txt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ cmake_minimum_required(VERSION 3.5)
55
# is included in another CMake project.
66
cmake_policy(SET CMP0077 NEW)
77

8-
project(inja LANGUAGES CXX VERSION 3.5.0)
8+
project(inja
9+
DESCRIPTION "Template engine for modern C++"
10+
LANGUAGES CXX
11+
VERSION 3.5.0)
912

1013

1114
option(BUILD_TESTING "Build unit tests" ON)
@@ -17,8 +20,9 @@ option(INJA_INSTALL "Generate install targets for inja" ON)
1720
option(INJA_INSTALL_SINGLE_HEADER "Install the single header instead" OFF)
1821
option(INJA_USE_EMBEDDED_JSON "Use the shipped json header if not available on the system" ON)
1922

23+
include(GNUInstallDirs)
2024

21-
set(INJA_INSTALL_INCLUDE_DIR "include")
25+
set(INJA_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR})
2226
set(INJA_PACKAGE_USE_EMBEDDED_JSON OFF)
2327
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)
2428

@@ -166,7 +170,7 @@ configure_file(
166170

167171

168172
if(INJA_INSTALL)
169-
set(INJA_CONFIG_PATH "lib/cmake/inja")
173+
set(INJA_CONFIG_PATH "${CMAKE_INSTALL_DATADIR}/cmake/inja")
170174

171175
# install tree package config
172176
configure_package_config_file(
@@ -176,6 +180,11 @@ if(INJA_INSTALL)
176180
NO_CHECK_REQUIRED_COMPONENTS_MACRO
177181
)
178182

183+
configure_file(${PROJECT_SOURCE_DIR}/cmake/config/inja.pc.in ${CMAKE_BINARY_DIR}/inja.pc @ONLY)
184+
install(FILES ${CMAKE_BINARY_DIR}/inja.pc
185+
DESTINATION ${CMAKE_INSTALL_DATADIR}/pkgconfig
186+
)
187+
179188
if(INJA_INSTALL_SINGLE_HEADER)
180189
install(
181190
DIRECTORY single_include/inja

cmake/config/inja.pc.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Name: inja
2+
Description: @PROJECT_DESCRIPTION@
3+
URL: https://github.com/pantor/inja
4+
Version: @PROJECT_VERSION@
5+
Requires: nlohmann_json

0 commit comments

Comments
 (0)