From ebb7aeb3ae49ccb49a642aaecb0d41483078b8bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Neal=20Gompa=20=28=E3=83=8B=E3=83=BC=E3=83=AB=E3=83=BB?= =?UTF-8?q?=E3=82=B4=E3=83=B3=E3=83=91=29?= Date: Sun, 9 Nov 2025 05:55:32 -0500 Subject: [PATCH] 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. --- CMakeLists.txt | 15 ++++++++++++--- cmake/config/inja.pc.in | 5 +++++ 2 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 cmake/config/inja.pc.in diff --git a/CMakeLists.txt b/CMakeLists.txt index f3872ae..8a7fc86 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,7 +5,10 @@ cmake_minimum_required(VERSION 3.5) # is included in another CMake project. cmake_policy(SET CMP0077 NEW) -project(inja LANGUAGES CXX VERSION 3.5.0) +project(inja + DESCRIPTION "Template engine for modern C++" + LANGUAGES CXX + VERSION 3.5.0) option(BUILD_TESTING "Build unit tests" ON) @@ -17,8 +20,9 @@ option(INJA_INSTALL "Generate install targets for inja" ON) option(INJA_INSTALL_SINGLE_HEADER "Install the single header instead" OFF) option(INJA_USE_EMBEDDED_JSON "Use the shipped json header if not available on the system" ON) +include(GNUInstallDirs) -set(INJA_INSTALL_INCLUDE_DIR "include") +set(INJA_INSTALL_INCLUDE_DIR ${CMAKE_INSTALL_INCLUDEDIR}) set(INJA_PACKAGE_USE_EMBEDDED_JSON OFF) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake) @@ -166,7 +170,7 @@ configure_file( if(INJA_INSTALL) - set(INJA_CONFIG_PATH "lib/cmake/inja") + set(INJA_CONFIG_PATH "${CMAKE_INSTALL_DATADIR}/cmake/inja") # install tree package config configure_package_config_file( @@ -176,6 +180,11 @@ if(INJA_INSTALL) NO_CHECK_REQUIRED_COMPONENTS_MACRO ) + configure_file(${PROJECT_SOURCE_DIR}/cmake/config/inja.pc.in ${CMAKE_BINARY_DIR}/inja.pc @ONLY) + install(FILES ${CMAKE_BINARY_DIR}/inja.pc + DESTINATION ${CMAKE_INSTALL_DATADIR}/pkgconfig + ) + if(INJA_INSTALL_SINGLE_HEADER) install( DIRECTORY single_include/inja diff --git a/cmake/config/inja.pc.in b/cmake/config/inja.pc.in new file mode 100644 index 0000000..627caf4 --- /dev/null +++ b/cmake/config/inja.pc.in @@ -0,0 +1,5 @@ +Name: inja +Description: @PROJECT_DESCRIPTION@ +URL: https://github.com/pantor/inja +Version: @PROJECT_VERSION@ +Requires: nlohmann_json