Skip to content

Commit 9be7e21

Browse files
authored
Have CMake generate pkg-config file for library. (#432)
1 parent 52faed7 commit 9be7e21

File tree

5 files changed

+83
-2
lines changed

5 files changed

+83
-2
lines changed

CMakeLists.txt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,29 @@ install(FILES
324324
${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake
325325
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PACKAGE_NAME})
326326

327+
# Create pkg-config file
328+
include(build/JoinPaths.cmake)
329+
# from: https://github.com/jtojnar/cmake-snips#concatenating-paths-when-building-pkg-config-files
330+
join_paths(DIRECTXTK_INCLUDEDIR_FOR_PKG_CONFIG "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
331+
join_paths(DIRECTXTK_LIBDIR_FOR_PKG_CONFIG "\${prefix}" "${CMAKE_INSTALL_LIBDIR}")
332+
333+
set(DIRECTXTK_DEP_L "")
334+
if(directxmath_FOUND)
335+
list(APPEND DIRECTXTK_DEP_L "DirectXMath")
336+
endif()
337+
list(LENGTH DIRECTXTK_DEP_L DEP_L)
338+
if(DEP_L)
339+
string(REPLACE ";" ", " DIRECTXTK_DEP " ${DIRECTXTK_DEP_L}")
340+
endif()
341+
342+
configure_file(
343+
"${CMAKE_CURRENT_SOURCE_DIR}/build/DirectXTK.pc.in"
344+
"${CMAKE_CURRENT_BINARY_DIR}/DirectXTK.pc" @ONLY)
345+
346+
# Install the pkg-config file
347+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/DirectXTK.pc"
348+
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
349+
327350
#--- Command-line tools
328351
if(BUILD_TOOLS AND WIN32)
329352
set(TOOL_EXES xwbtool)

build/DirectXTK-GitHub-CMake-Dev17.yml

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,26 @@ schedules:
1212
include:
1313
- main
1414

15-
trigger: none
16-
pr: none
15+
trigger:
16+
branches:
17+
include:
18+
- main
19+
paths:
20+
include:
21+
- CMakeLists.txt
22+
- build/CompilerAndLinker.cmake
23+
- build/JoinPaths.cmake
24+
25+
pr:
26+
branches:
27+
include:
28+
- main
29+
paths:
30+
include:
31+
- CMakeLists.txt
32+
- build/CompilerAndLinker.cmake
33+
- build/JoinPaths.cmake
34+
drafts: false
1735

1836
resources:
1937
repositories:

build/DirectXTK-GitHub-CMake.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,19 @@ trigger:
1919
paths:
2020
include:
2121
- CMakeLists.txt
22+
- build/CompilerAndLinker.cmake
23+
- build/JoinPaths.cmake
24+
2225
pr:
2326
branches:
2427
include:
2528
- main
2629
paths:
2730
include:
2831
- CMakeLists.txt
32+
- build/CompilerAndLinker.cmake
33+
- build/JoinPaths.cmake
34+
drafts: false
2935

3036
resources:
3137
repositories:

build/DirectXTK.pc.in

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

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)