Skip to content

Commit

Permalink
CMakeLists.txt: Improve pkg-config generating on Windows
Browse files Browse the repository at this point in the history
Use the target properties of ZLIB::ZLIB to get the library names for the
pkg-config files that we generate, and unify things with other builds.
We need to use the IMPORT_LOCATION[_$<CONFIG>] for ZLib since it does not
define IMPORT_IMPLIB[_$<CONFIG>] even on Windows DLL builds, and assume
that the $<CONFIG> we use above is RELEASE for both MinSizeRel and
RelWithDebInfo builds.

Sadly, this pkg-config generating will not work currently with the Visual
Studio project generators, since CMAKE_BUILD_TYPE is usually not defined in
such builds.
  • Loading branch information
fanc999-1 committed Feb 8, 2023
1 parent 1dc7cca commit 11fcfbd
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -939,23 +939,26 @@ endif()

# Create pkgconfig files.
# We use the same files like ./configure, so we have to set its vars.
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(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}")
if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "")
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")
# Sadly, no IMPORTED_LOCATION_RELWITHDEBINFO property in ZLIB::ZLIB?
if("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo" OR
"${CMAKE_BUILD_TYPE}" 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()
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)
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)
Expand Down

0 comments on commit 11fcfbd

Please sign in to comment.