1
0
mirror of https://github.com/microsoft/DirectXTex synced 2024-11-09 14:30:05 +00:00

Have CMake generate pkg-config file for library (#423)

This commit is contained in:
J. Peter Mugaas 2023-12-21 02:06:31 -05:00 committed by GitHub
parent a4e1c046d5
commit 3bf25e04b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 71 additions and 2 deletions

View File

@ -340,6 +340,36 @@ install(FILES
${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake ${CMAKE_CURRENT_BINARY_DIR}/${PACKAGE_NAME}-config-version.cmake
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PACKAGE_NAME}) 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(DIRECTXTEX_INCLUDEDIR_FOR_PKG_CONFIG "\${prefix}" "${CMAKE_INSTALL_INCLUDEDIR}")
join_paths(DIRECTXTEX_LIBDIR_FOR_PKG_CONFIG "\${prefix}" "${CMAKE_INSTALL_LIBDIR}")
set(DIRECTXTEX_DEP_L "")
if(ENABLE_OPENEXR_SUPPORT)
list(APPEND DIRECTXTEX_DEP_L "OpenEXR")
list(APPEND DIRECTXTEX_DEP_L "zlib")
endif()
if(directxmath_FOUND)
list(APPEND DIRECTXTEX_DEP_L "DirectXMath")
endif()
if(directx-headers_FOUND)
list(APPEND DIRECTXTEX_DEP_L "DirectX-Headers")
endif()
list(LENGTH DIRECTXTEX_DEP_L DEP_L)
if(DEP_L)
STRING(REPLACE ";" ", " DIRECTXTEX_DEP " ${DIRECTXTEX_DEP_L}")
endif()
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/build/DirectXTex.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/DirectXTex.pc" @ONLY)
# Install the pkg-config file
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/DirectXTex.pc"
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
#--- Command-line tools #--- Command-line tools
if(BUILD_TOOLS AND BUILD_DX11 AND WIN32) if(BUILD_TOOLS AND BUILD_DX11 AND WIN32)
set(TOOL_EXES texassemble texconv texdiag) set(TOOL_EXES texassemble texconv texdiag)
@ -490,6 +520,12 @@ elseif(NOT (${DIRECTX_ARCH} MATCHES "^arm"))
endforeach() endforeach()
endif() endif()
if(MINGW)
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
target_link_options(${t} PRIVATE -municode)
endforeach()
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(WarningsLib -Wall -Wpedantic -Wextra) set(WarningsLib -Wall -Wpedantic -Wextra)
@ -514,10 +550,9 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
foreach(t IN LISTS TOOL_EXES) foreach(t IN LISTS TOOL_EXES)
target_compile_options(${t} PRIVATE ${WarningsEXE}) target_compile_options(${t} PRIVATE ${WarningsEXE})
endforeach() endforeach()
elseif(MINGW) elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU")
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME}) foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})
target_compile_options(${t} PRIVATE -Wno-ignored-attributes) target_compile_options(${t} PRIVATE -Wno-ignored-attributes)
target_link_options(${t} PRIVATE -municode)
endforeach() endforeach()
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")
foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME}) foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME})

11
build/DirectXTex.pc.in Normal file
View File

@ -0,0 +1,11 @@
prefix=@CMAKE_INSTALL_PREFIX@
libdir=@DIRECTXTEX_LIBDIR_FOR_PKG_CONFIG@
includedir=@DIRECTXTEX_INCLUDEDIR_FOR_PKG_CONFIG@
Name: @PROJECT_NAME@
Description: @PROJECT_DESCRIPTION@
URL: @PROJECT_HOMEPAGE_URL@
Version: @PROJECT_VERSION@
Requires:@DIRECTXTEX_DEP@
Cflags: -I${includedir}
Libs: -l@PROJECT_NAME@

23
build/JoinPaths.cmake Normal file
View File

@ -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 Pythons 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()