Skip to content

Commit

Permalink
CMake: Generate pkg-config files for all Windows builds
Browse files Browse the repository at this point in the history
The Meson build system makes use of pkg-config files or CMake to find most of
the dependencies via its "built-in" dependency search system.  As libpng is a
very widely used package, this makes the CMake build system generate pkg-config
files for libpng even for non-Cygwin/non-MinGW Windows builds, so that Meson
could locate libpng via pkg-config as well even on Visual Studio builds, for
instance.

We also do the following on native, non-MinGW Windows builds:

*  Replace -lpngXX with libpngXX.lib, for the libpng library that we link to
*  Use the correct ZLib library .lib name for `libs.private`.
*  Replace `Requires: zlib` with `Requires:`, since we already say in
   `libs.private` that we are linking to ZLib
  • Loading branch information
fanc999-1 committed Sep 30, 2021
1 parent a37d483 commit 7c09136
Showing 1 changed file with 30 additions and 26 deletions.
56 changes: 30 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -871,31 +871,35 @@ endif()

# Create pkgconfig files.
# We use the same files like ./configure, so we have to set its vars.
# Only do this on Windows for Cygwin - the files don't make much sense
# outside of a UNIX look-alike.
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix ${CMAKE_INSTALL_PREFIX})
set(libdir ${CMAKE_INSTALL_FULL_LIBDIR})
set(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR})
if(NOT WIN32 OR CYGWIN OR MINGW)
set(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix ${CMAKE_INSTALL_PREFIX})
set(libdir ${CMAKE_INSTALL_FULL_LIBDIR})
set(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR})
set(LIBS "-lz -lm")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng.pc.in
${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc
@ONLY)
create_symlink(libpng.pc FILE ${PNGLIB_NAME}.pc)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng-config.in
${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
@ONLY)
create_symlink(libpng-config FILE ${PNGLIB_NAME}-config)
set(LIBS "-lz -lm")
else()
STRING (TOLOWER "${CMAKE_BUILD_TYPE}" config_lower)
if (config_lower STREQUAL "debug")
set(LIBS "${ZLIB_LIBRARY_DEBUG} ${M_LIBRARY}")
else()
set(LIBS "${ZLIB_LIBRARY_RELEASE} ${M_LIBRARY}")
endif()
endif()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng.pc.in
${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc @ONLY)
create_symlink(libpng.pc FILE ${PNGLIB_NAME}.pc)

# Set up links.
if(PNG_SHARED)
set_target_properties(png PROPERTIES
VERSION 16.${PNGLIB_RELEASE}.git
# VERSION 16.${PNGLIB_RELEASE}.0
SOVERSION 16
CLEAN_DIRECT_OUTPUT 1)
if(NOT WIN32 OR CYGWIN OR MINGW)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng-config.in
pc_file${PNGLIB_NAME}-config @ONLY)
create_symlink(libpng-config FILE ${PNGLIB_NAME}-config)
else()
foreach (pc_file ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc)
FILE(READ ${pc_file} png_pc_orig)
STRING(REPLACE "-lpng${PNGLIB_MAJOR}${PNGLIB_MINOR}" "libpng${PNGLIB_MAJOR}${PNGLIB_MINOR}.lib" png_pc_out ${png_pc_orig})
STRING(REPLACE "Requires: zlib" "Requires:" png_pc_out ${png_pc_out})
FILE(WRITE ${pc_file} ${png_pc_out})
endforeach()
endif()

# Install.
Expand Down Expand Up @@ -958,13 +962,13 @@ if(NOT SKIP_INSTALL_FILES AND NOT SKIP_INSTALL_ALL)
install(FILES png.5
DESTINATION ${CMAKE_INSTALL_MANDIR}/man5)
# Install the pkg-config files.
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
if(NOT CMAKE_HOST_WIN32 OR CYGWIN OR MINGW)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libpng.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libpng-config
DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc
DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}-config
DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()
Expand Down

0 comments on commit 7c09136

Please sign in to comment.