diff --git a/CMakeLists.txt b/CMakeLists.txt index 07e7996..29a8107 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -340,6 +340,36 @@ 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(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 if(BUILD_TOOLS AND BUILD_DX11 AND WIN32) set(TOOL_EXES texassemble texconv texdiag) @@ -490,6 +520,12 @@ elseif(NOT (${DIRECTX_ARCH} MATCHES "^arm")) endforeach() 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") set(WarningsLib -Wall -Wpedantic -Wextra) @@ -514,10 +550,9 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang") foreach(t IN LISTS TOOL_EXES) target_compile_options(${t} PRIVATE ${WarningsEXE}) endforeach() -elseif(MINGW) +elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU") foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME}) target_compile_options(${t} PRIVATE -Wno-ignored-attributes) - target_link_options(${t} PRIVATE -municode) endforeach() elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC") foreach(t IN LISTS TOOL_EXES ITEMS ${PROJECT_NAME}) diff --git a/build/DirectXTex.pc.in b/build/DirectXTex.pc.in new file mode 100644 index 0000000..28c339c --- /dev/null +++ b/build/DirectXTex.pc.in @@ -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@ 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()