From 37ec9b00c88f49ae4d8a001954f235257c66b9c3 Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Fri, 21 Aug 2026 01:37:51 +0000 Subject: [PATCH 1/3] Change CMake generated pkgconfig to match meson. In vcpkg we want to make sure that CMake and pkg-config customers get an experience that works, including transitively. In reviewing https://github.com/microsoft/vcpkg/pull/52891 we discovered that the transitive libjpeg-turbo -> libspng .pc link is broken. In trying to fix that I ran into a transitive problem here. https://github.com/randy408/libspng/blob/adc94393dbeddf9e027d1b2dfff7c1bab975224e/CMakeLists.txt#L103-L107 installs `libspng.pc` and `libspng_static.pc`, but https://github.com/randy408/libspng/blob/adc94393dbeddf9e027d1b2dfff7c1bab975224e/meson.build#L82-L87 installs `spng.pc`. This seems to be the one `libjpeg-turbo` is looking to be compatible with. https://packages.debian.org/sid/amd64/libspng-dev/filelist Looks like Debian is using the meson build, given that they install `/usr/lib/x86_64-linux-gnu/pkgconfig/spng.pc`. Also, meson detects whether the .pc should link with `libm` by probing for existence of the library: https://github.com/randy408/libspng/blob/adc94393dbeddf9e027d1b2dfff7c1bab975224e/meson.build#L42 while CMake just assumes "Windows gets no libm, everyone else does". This change changes everything to match meson. The problems discussed here and some of the suggested outcomes are from GPT 5.6 Sol. --- CMakeLists.txt | 10 ++++++---- cmake/{libspng.pc.in => spng.pc.in} | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) rename cmake/{libspng.pc.in => spng.pc.in} (92%) diff --git a/CMakeLists.txt b/CMakeLists.txt index da1917e..486ba26 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,10 +17,13 @@ option(BUILD_EXAMPLES "Build examples" ON) include(GNUInstallDirs) include(CMakePackageConfigHelpers) -if(NOT CMAKE_HOST_WIN32) +find_library(MATH_LIBRARY_PATH m) +if(MATH_LIBRARY_PATH) set(MATH_LIBRARY "m") + set(LIBS "-lm") else() set(MATH_LIBRARY "") + set(LIBS "") endif() if(NOT ENABLE_OPT) @@ -98,11 +101,10 @@ if(NOT CMAKE_HOST_WIN32 OR CYGWIN OR MINGW) set(exec_prefix ${CMAKE_INSTALL_PREFIX}) set(libdir ${CMAKE_INSTALL_FULL_LIBDIR}) set(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR}) - set(LIBS "-lm") foreach(libname ${spng_TARGETS}) - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/libspng.pc.in ${CMAKE_CURRENT_BINARY_DIR}/cmake/lib${libname}.pc @ONLY) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/spng.pc.in ${CMAKE_CURRENT_BINARY_DIR}/cmake/${libname}.pc @ONLY) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/lib${libname}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/${libname}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) endforeach() endif() diff --git a/cmake/libspng.pc.in b/cmake/spng.pc.in similarity index 92% rename from cmake/libspng.pc.in rename to cmake/spng.pc.in index 71e0e47..1904c09 100644 --- a/cmake/libspng.pc.in +++ b/cmake/spng.pc.in @@ -3,7 +3,7 @@ exec_prefix=@exec_prefix@ libdir=@libdir@ includedir=@includedir@/ -Name: lib@libname@ +Name: @libname@ Description: PNG decoding and encoding library Version: @SPNG_VERSION@ Requires: zlib From 041d508c4eca900fde55b97491df724380692002 Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Fri, 21 Aug 2026 01:44:11 +0000 Subject: [PATCH 2/3] Also install pkg-config on Windows. --- CMakeLists.txt | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 486ba26..2b25abe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,15 +96,13 @@ install( DESTINATION ${config_install_dir} ) -if(NOT CMAKE_HOST_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(prefix ${CMAKE_INSTALL_PREFIX}) +set(exec_prefix ${CMAKE_INSTALL_PREFIX}) +set(libdir ${CMAKE_INSTALL_FULL_LIBDIR}) +set(includedir ${CMAKE_INSTALL_FULL_INCLUDEDIR}) - foreach(libname ${spng_TARGETS}) - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/spng.pc.in ${CMAKE_CURRENT_BINARY_DIR}/cmake/${libname}.pc @ONLY) +foreach(libname ${spng_TARGETS}) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/spng.pc.in ${CMAKE_CURRENT_BINARY_DIR}/cmake/${libname}.pc @ONLY) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/${libname}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) - endforeach() -endif() + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/cmake/${libname}.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) +endforeach() From 27db5d8f337dbcb7aa2d352991966d1cb517d988 Mon Sep 17 00:00:00 2001 From: Billy Robert O'Neal III Date: Fri, 21 Aug 2026 12:57:49 -0700 Subject: [PATCH 3/3] Search CMAKE_C_IMPLICIT_LINK_DIRECTORIES for libm as suggested by @dg0yt --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b25abe..d385e46 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,7 @@ option(BUILD_EXAMPLES "Build examples" ON) include(GNUInstallDirs) include(CMakePackageConfigHelpers) -find_library(MATH_LIBRARY_PATH m) +find_library(MATH_LIBRARY_PATH NAMES m PATHS ${CMAKE_C_IMPLICIT_LINK_DIRECTORIES}) if(MATH_LIBRARY_PATH) set(MATH_LIBRARY "m") set(LIBS "-lm")