Skip to content

Commit 3d199f0

Browse files
authored
add pkg-config support. (#174)
1 parent a55148f commit 3d199f0

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,20 @@ install(FILES
6868
${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake
6969
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PACKAGE_NAME})
7070

71+
# Create pkg-config file
72+
include(build/JoinPaths.cmake)
73+
# from: https://github.com/jtojnar/cmake-snips#concatenating-paths-when-building-pkg-config-files
74+
join_paths(DIRECTXMATH_INCLUDEDIR_FOR_PKG_CONFIG "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
75+
join_paths(DIRECTXMATH_LIBDIR_FOR_PKG_CONFIG "\${prefix}" "${CMAKE_INSTALL_LIBDIR}")
76+
77+
configure_file(
78+
"${CMAKE_CURRENT_SOURCE_DIR}/build/DirectXMath.pc.in"
79+
"${CMAKE_CURRENT_BINARY_DIR}/DirectXMath.pc" @ONLY)
80+
81+
# Install the pkg-config file
82+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/DirectXMath.pc"
83+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
84+
7185
#--- Test suite
7286
if (DEFINED VCPKG_TARGET_ARCHITECTURE)
7387
set(DXMATH_ARCHITECTURE ${VCPKG_TARGET_ARCHITECTURE})

build/DirectXMath.pc.in

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
prefix=@CMAKE_INSTALL_PREFIX@
2+
libdir=@DIRECTXMATH_LIBDIR_FOR_PKG_CONFIG@
3+
includedir=@DIRECTXMATH_INCLUDEDIR_FOR_PKG_CONFIG@
4+
5+
Name: @PROJECT_NAME@
6+
Description: @PROJECT_DESCRIPTION@
7+
URL: @PROJECT_HOMEPAGE_URL@
8+
Version: @PROJECT_VERSION@
9+
Cflags: -I${includedir}
10+
Libs:

build/JoinPaths.cmake

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# This module provides function for joining paths
2+
# known from most languages
3+
#
4+
# SPDX-License-Identifier: (MIT OR CC0-1.0)
5+
# Copyright 2020 Jan Tojnar
6+
# https://github.com/jtojnar/cmake-snips
7+
#
8+
# Modelled after Python’s os.path.join
9+
# https://docs.python.org/3.7/library/os.path.html#os.path.join
10+
# Windows not supported
11+
function(join_paths joined_path first_path_segment)
12+
set(temp_path "${first_path_segment}")
13+
foreach(current_segment IN LISTS ARGN)
14+
if(NOT ("${current_segment}" STREQUAL ""))
15+
if(IS_ABSOLUTE "${current_segment}")
16+
set(temp_path "${current_segment}")
17+
else()
18+
set(temp_path "${temp_path}/${current_segment}")
19+
endif()
20+
endif()
21+
endforeach()
22+
set(${joined_path} "${temp_path}" PARENT_SCOPE)
23+
endfunction()

0 commit comments

Comments
 (0)