Skip to content

Commit edf3ac9

Browse files
committed
CMakeLists.txt: Improve pkg-config generating on Windows
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.
1 parent 1dc7cca commit edf3ac9

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

CMakeLists.txt

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -939,23 +939,27 @@ endif()
939939

940940
# Create pkgconfig files.
941941
# We use the same files like ./configure, so we have to set its vars.
942-
set(prefix ${CMAKE_INSTALL_PREFIX})
943-
set(exec_prefix ${CMAKE_INSTALL_PREFIX})
944-
set(libdir ${CMAKE_INSTALL_FULL_LIBDIR})
945-
set(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR})
946-
if(NOT WIN32 OR CYGWIN OR MINGW)
947-
set(LIBS "-lz -lm")
948-
else()
949-
string(TOLOWER "${CMAKE_BUILD_TYPE}" config_lower)
950-
if (config_lower STREQUAL "debug")
951-
set(LIBS "${ZLIB_LIBRARY_DEBUG} ${M_LIBRARY}")
952-
else()
953-
set(LIBS "${ZLIB_LIBRARY_RELEASE} ${M_LIBRARY}")
942+
if(NOT "${CMAKE_BUILD_TYPE}" STREQUAL "")
943+
set(prefix ${CMAKE_INSTALL_PREFIX})
944+
set(exec_prefix ${CMAKE_INSTALL_PREFIX})
945+
set(libdir ${CMAKE_INSTALL_FULL_LIBDIR})
946+
set(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR})
947+
get_target_property(ZLIB_LIB ZLIB::ZLIB IMPORTED_LOCATION)
948+
if("${ZLIB_LIB}" STREQUAL "ZLIB_LIB-NOTFOUND")
949+
string(TOUPPER ${CMAKE_BUILD_TYPE} ZLIB_CFG)
950+
# Sadly, no IMPORTED_LOCATION_RELWITHDEBINFO property in ZLIB::ZLIB?
951+
if("${ZLIB_CFG}" STREQUAL "RELWITHDEBINFO" OR
952+
"${ZLIB_CFG}" STREQUAL "MINSIZEREL")
953+
get_target_property(ZLIB_LIB ZLIB::ZLIB IMPORTED_LOCATION_RELEASE)
954+
else()
955+
get_target_property(ZLIB_LIB ZLIB::ZLIB IMPORTED_LOCATION_${ZLIB_CFG})
956+
endif()
954957
endif()
958+
set(LIBS "${ZLIB_LIB} ${M_LIBRARY}")
959+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng.pc.in
960+
${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc @ONLY)
961+
create_symlink(libpng.pc FILE ${PNGLIB_NAME}.pc)
955962
endif()
956-
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/libpng.pc.in
957-
${CMAKE_CURRENT_BINARY_DIR}/${PNGLIB_NAME}.pc @ONLY)
958-
create_symlink(libpng.pc FILE ${PNGLIB_NAME}.pc)
959963

960964
# Set up links.
961965
if(PNG_SHARED)

0 commit comments

Comments
 (0)