From de7730929ed7dcd9c839d670201633021029efbb Mon Sep 17 00:00:00 2001 From: "J. Peter Mugaas" Date: Wed, 20 Dec 2023 15:52:59 -0500 Subject: [PATCH] Have CMake generate pkg-config file for library (#133) --- CMakeLists.txt | 29 +++++++++++++++++++++++++++++ build/JoinPaths.cmake | 23 +++++++++++++++++++++++ build/UVAtlas.pc.in | 11 +++++++++++ 3 files changed, 63 insertions(+) create mode 100644 build/JoinPaths.cmake create mode 100644 build/UVAtlas.pc.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 0c0bb0e..50b7d7c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -237,6 +237,35 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PACKAGE_NAME}) +# Create pkg-config file +include(build/JoinPaths.cmake) +# from: https://github.com/jtojnar/cmake-snips#concatenating-paths-when-building-pkg-config-files +join_paths(UVATLAS_INCLUDEDIR_FOR_PKG_CONFIG "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}") +join_paths(UVATLAS_LIBDIR_FOR_PKG_CONFIG "\${prefix}" "${CMAKE_INSTALL_LIBDIR}") + +set(UVATLAS_DEP_L "") +if(ENABLE_USE_EIGEN) + list(APPEND UVATLAS_DEP_L "eigen3") +endif() +if(directxmath_FOUND) + list(APPEND UVATLAS_DEP_L "DirectXMath") +endif() +if(directx-headers_FOUND) + list(APPEND UVATLAS_DEP_L "DirectX-Headers") +endif() +list(LENGTH UVATLAS_DEP_L DEP_L) +if(DEP_L) + string(REPLACE ";" ", " UVATLAS_DEP " ${UVATLAS_DEP_L}") +endif() + +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/build/UVAtlas.pc.in" + "${CMAKE_CURRENT_BINARY_DIR}/UVAtlas.pc" @ONLY) + +# Install the pkg-config file +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/UVAtlas.pc" + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) + #--- Command-line tool if(BUILD_TOOLS AND WIN32) set(TOOL_EXES uvatlastool) diff --git a/build/JoinPaths.cmake b/build/JoinPaths.cmake new file mode 100644 index 0000000..c68d91b --- /dev/null +++ b/build/JoinPaths.cmake @@ -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() diff --git a/build/UVAtlas.pc.in b/build/UVAtlas.pc.in new file mode 100644 index 0000000..b51d010 --- /dev/null +++ b/build/UVAtlas.pc.in @@ -0,0 +1,11 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +libdir=@UVATLAS_LIBDIR_FOR_PKG_CONFIG@ +includedir=@UVATLAS_INCLUDEDIR_FOR_PKG_CONFIG@ + +Name: @PROJECT_NAME@ +Description: @PROJECT_DESCRIPTION@ +URL: @PROJECT_HOMEPAGE_URL@ +Version: @PROJECT_VERSION@ +Requires:@UVATLAS_DEP@ +Cflags: -I${includedir} +Libs: -l@PROJECT_NAME@