CMake: Fix pkg-config section "Libs" for multi-config CMake generators

This commit is contained in:
Sebastian Pipping 2021-06-23 19:56:29 +02:00
parent 663e529eed
commit 1d4bb74c34
4 changed files with 39 additions and 12 deletions

View File

@ -423,24 +423,37 @@ expat_install(FILES lib/expat.h lib/expat_external.h DESTINATION ${CMAKE_INSTALL
# pkg-config file
#
if(EXPAT_BUILD_PKGCONFIG)
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix "\${prefix}")
set(_EXPAT_LIBRARY_NAME "expat${CMAKE_${_EXPAT_BUILD_TYPE_UPPER}_POSTFIX}")
if(CMAKE_INSTALL_LIBDIR MATCHES "^/")
set(libdir "${CMAKE_INSTALL_LIBDIR}")
set(_expat_pkgconfig_libdir "${CMAKE_INSTALL_LIBDIR}")
else()
set(libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
set(_expat_pkgconfig_libdir "\${exec_prefix}/${CMAKE_INSTALL_LIBDIR}")
endif()
if(CMAKE_INSTALL_INCLUDEDIR MATCHES "^/")
set(includedir "${CMAKE_INSTALL_INCLUDEDIR}")
set(_expat_pkgconfig_includedir "${CMAKE_INSTALL_INCLUDEDIR}")
else()
set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
set(_expat_pkgconfig_includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
endif()
configure_file(expat.pc.in ${CMAKE_CURRENT_BINARY_DIR}/expat.pc @ONLY)
expat_install(FILES ${CMAKE_CURRENT_BINARY_DIR}/expat.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
set_target_properties(expat PROPERTIES
pkgconfig_prefix "${CMAKE_INSTALL_PREFIX}"
pkgconfig_exec_prefix "\${prefix}"
pkgconfig_libdir "${_expat_pkgconfig_libdir}"
pkgconfig_includedir "${_expat_pkgconfig_includedir}"
pkgconfig_version "${PACKAGE_VERSION}")
foreach(_build_type ${CMAKE_BUILD_TYPE} Debug Release RelWithDebInfo MinSizeRel)
string(TOLOWER "${_build_type}" _build_type_lower)
string(TOUPPER "${_build_type}" _build_type_upper)
set_property(TARGET expat PROPERTY "pkgconfig_${_build_type_lower}_name" "expat${CMAKE_${_build_type_upper}_POSTFIX}")
endforeach()
file(GENERATE
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/expat.pc
INPUT ${PROJECT_SOURCE_DIR}/expat.pc.cmake
TARGET expat)
expat_install(FILES ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>/expat.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
endif()
#

View File

@ -7,10 +7,12 @@ Release 2.4.2 xxx xxx xx xxxx
#497 Autotools: Include files with release archives:
- buildconf.sh
- fuzz/*.c
#495 CMake: MinGW: Fix pkg-config section "Libs" for non-release
build types (e.g. -DCMAKE_BUILD_TYPE=Debug)
#495 CMake: MinGW: Fix pkg-config section "Libs" for
- non-release build types (e.g. -DCMAKE_BUILD_TYPE=Debug)
- multi-config CMake generators (e.g. Ninja Multi-Config)
Special thanks to:
Joergen Ibsen
Kai Pastor
Release 2.4.1 Sun May 23 2021

View File

@ -75,6 +75,7 @@ _EXTRA_DIST_CMAKE = \
CMakeLists.txt \
CMake.README \
ConfigureChecks.cmake \
expat.pc.cmake \
expat_config.h.cmake
_EXTRA_DIST_WINDOWS = \

11
expat/expat.pc.cmake Normal file
View File

@ -0,0 +1,11 @@
prefix=$<TARGET_PROPERTY:pkgconfig_prefix>
exec_prefix=$<TARGET_PROPERTY:pkgconfig_exec_prefix>
libdir=$<TARGET_PROPERTY:pkgconfig_libdir>
includedir=$<TARGET_PROPERTY:pkgconfig_includedir>
Name: $<TARGET_PROPERTY:pkgconfig_$<LOWER_CASE:$<CONFIG>>_name>
Version: $<TARGET_PROPERTY:pkgconfig_version>
Description: expat XML parser
URL: https://libexpat.github.io/
Libs: -L${libdir} -l$<TARGET_PROPERTY:pkgconfig_$<LOWER_CASE:$<CONFIG>>_name>
Cflags: -I${includedir}