Skip to content

Commit

Permalink
Have CMake generate pkg-config file for library (#118)
Browse files Browse the repository at this point in the history
L
  • Loading branch information
JPeterMugaas authored Dec 21, 2023
1 parent 041ac9b commit ee0c307
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
26 changes: 26 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,32 @@ install(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
COMPONENT library)

# Create pkg-config file
include(build/JoinPaths.cmake)
# from: https://github.com/jtojnar/cmake-snips#concatenating-paths-when-building-pkg-config-files
join_paths(DIRECTXMESH_INCLUDEDIR_FOR_PKG_CONFIG "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
join_paths(DIRECTXMESH_LIBDIR_FOR_PKG_CONFIG "\${prefix}" "${CMAKE_INSTALL_LIBDIR}")

set(DIRECTXMESH_DEP_L "")
if(directxmath_FOUND)
list(APPEND DIRECTXMESH_DEP_L "DirectXMath")
endif()
if(directx-headers_FOUND)
list(APPEND DIRECTXMESH_DEP_L "DirectX-Headers")
endif()
list(LENGTH DIRECTXMESH_DEP_L DEP_L)
if(DEP_L)
string(REPLACE ";" ", " DIRECTXMESH_DEP " ${DIRECTXMESH_DEP_L}")
endif()

configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/build/DirectXMesh.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/DirectXMesh.pc" @ONLY)

# Install the pkg-config file
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/DirectXMesh.pc"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)

install(TARGETS Utilities
EXPORT Utilities-targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand Down
11 changes: 11 additions & 0 deletions build/DirectXMesh.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
prefix=@CMAKE_INSTALL_PREFIX@
libdir=@DIRECTXMESH_LIBDIR_FOR_PKG_CONFIG@
includedir=@DIRECTXMESH_INCLUDEDIR_FOR_PKG_CONFIG@

Name: @PROJECT_NAME@
Description: @PROJECT_DESCRIPTION@
URL: @PROJECT_HOMEPAGE_URL@
Version: @PROJECT_VERSION@
Requires:@DIRECTXMESH_DEP@
Cflags: -I${includedir}
Libs: -l@PROJECT_NAME@
23 changes: 23 additions & 0 deletions build/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()

0 comments on commit ee0c307

Please sign in to comment.