Skip to content

Commit

Permalink
build: add pkg-config file
Browse files Browse the repository at this point in the history
GLM used to ship a pkg-config file since version 0.9.8.0, added in
commit 0e018a5, but it was removed
together with the install target in commit
5f352ec. While the install target was
re-added in commit 631faff, the .pc
file has been left behind.

This patch re-adds it, and, compared to the old one, this pkg-config
file also accounts for the cases where GLM is installed in an include
directory that is not a subdirectory of the install prefix (i.e. it does
the right thing™ when CMAKE_INSTALL_INCLUDEDIR is an absolute path).

To read why the JoinPaths module is needed, take a look at
<https://github.com/jtojnar/cmake-snips#concatenating-paths-when-building-pkg-config-files>
  • Loading branch information
Tachi107 committed Sep 3, 2022
1 parent 5e15b4f commit 775a8e2
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ CMakeFiles
cmake_install.cmake
install_manifest.txt
*.cmake
!glmConfig.cmake
!glmConfig-version.cmake
!/cmake/JoinPaths.cmake
# ^ May need to add future .cmake files as exceptions

# Test logs
Expand Down
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ if(${CMAKE_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR})
write_basic_package_version_file("glmConfigVersion.cmake" COMPATIBILITY AnyNewerVersion)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/glmConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_DATADIR}/cmake/glm)

include(cmake/JoinPaths.cmake) # can be replaced by cmake_path(APPEND) in CMake 3.20
join_paths(PKGCONFIG_INCLUDEDIR "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
configure_file("cmake/glm.pc.in" "glm.pc" @ONLY)
install(
FILES "${CMAKE_CURRENT_BINARY_DIR}/glm.pc"
DESTINATION "${CMAKE_INSTALL_DATADIR}/pkgconfig"
)

include(CTest)
if(BUILD_TESTING)
add_subdirectory(test)
Expand Down
23 changes: 23 additions & 0 deletions cmake/JoinPaths.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# This module provides function for joining paths
# known from most languages
#
# SPDX-License-Identifier: (MIT OR CC0-1.0)
# Copyright 2020 Jan Tojnar
# https://github.com/jtojnar/cmake-snips
#
# Modelled after Python’s os.path.join
# https://docs.python.org/3.7/library/os.path.html#os.path.join
# Windows not supported
function(join_paths joined_path first_path_segment)
set(temp_path "${first_path_segment}")
foreach(current_segment IN LISTS ARGN)
if(NOT ("${current_segment}" STREQUAL ""))
if(IS_ABSOLUTE "${current_segment}")
set(temp_path "${current_segment}")
else()
set(temp_path "${temp_path}/${current_segment}")
endif()
endif()
endforeach()
set(${joined_path} "${temp_path}" PARENT_SCOPE)
endfunction()
8 changes: 8 additions & 0 deletions cmake/glm.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
prefix=@CMAKE_INSTALL_PREFIX@
includedir=@PKGCONFIG_INCLUDEDIR@

Name: GLM
Description: OpenGL Mathematics
URL: https://glm.g-truc.net
Version: @GLM_VERSION@
Cflags: -I${includedir}

0 comments on commit 775a8e2

Please sign in to comment.