Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake: Generate pkg-config files for all Windows builds #396

Open
wants to merge 3 commits into
base: libpng16
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 37 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -939,23 +939,27 @@ 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.
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(prefix ${CMAKE_INSTALL_PREFIX})
set(exec_prefix ${CMAKE_INSTALL_PREFIX})
set(libdir ${CMAKE_INSTALL_FULL_LIBDIR})
set(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR})
get_target_property(ZLIB_LIB ZLIB::ZLIB IMPORTED_LOCATION)
if("${ZLIB_LIB}" STREQUAL "ZLIB_LIB-NOTFOUND")
if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "")
string(TOUPPER ${CMAKE_BUILD_TYPE} ZLIB_CFG)
# Sadly, no IMPORTED_LOCATION_RELWITHDEBINFO property in ZLIB::ZLIB?
if("${ZLIB_CFG}" STREQUAL "RELWITHDEBINFO" OR
"${ZLIB_CFG}" STREQUAL "MINSIZEREL")
get_target_property(ZLIB_LIB ZLIB::ZLIB IMPORTED_LOCATION_RELEASE)
else()
get_target_property(ZLIB_LIB ZLIB::ZLIB IMPORTED_LOCATION_${ZLIB_CFG})
endif()
endif()
endif()
set(LIBS "${ZLIB_LIB} ${M_LIBRARY}")
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)
Expand All @@ -965,6 +969,19 @@ if(PNG_SHARED)
CLEAN_DIRECT_OUTPUT 1)
endif()

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.private: zlib" "Requires.private:" png_pc_out ${png_pc_out})
file(WRITE ${pc_file} ${png_pc_out})
endforeach()
endif()

# Install.
if(NOT SKIP_INSTALL_LIBRARIES AND NOT SKIP_INSTALL_ALL)
install(TARGETS ${PNG_LIB_TARGETS}
Expand Down Expand Up @@ -1025,13 +1042,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