libpng
libpng copied to clipboard
Incompatible with FetchContent
Using libpng with FetchContent does not work because header files are missing. I am using Windows 10 and I don't have libpng installed elsewhere. I ran cmake . --preset=default -B build
and then cmake --build build --verbose
.
Minimal reproducible example:
main.c
#include <png.h>
int main() { return 0; }
CMakePresets.json
{
"version": 6,
"configurePresets": [
{
"name": "default",
"displayName": "Default Config",
"description": "Default build using Unix Makefiles generator",
"generator": "Unix Makefiles"
}
],
"buildPresets": [
{
"name": "default",
"configurePreset": "default"
}
]
}
CMakeLists.txt
cmake_minimum_required(VERSION 3.25)
project(png-usage)
include(FetchContent)
FetchContent_Declare(
libpng
GIT_REPOSITORY "https://github.com/glennrp/libpng.git"
GIT_TAG "e519af8")
set(PNG_TESTS OFF)
FetchContent_MakeAvailable(libpng)
add_executable(usage main.c)
target_link_libraries(usage png_static)
Snippet from error output:
[ 35%] Building C object CMakeFiles/usage.dir/main.c.obj
C:/Users/Greg/scoop/apps/msys2/current/mingw64/bin/cc.exe -MD -MT CMakeFiles/usage.dir/main.c.obj -MF CMakeFiles/usage.dir/main.c.obj.d -o CMakeFiles/usage.dir/main.c.obj -c C:/Users/Greg/code/cmake-problem-example/main.c
C:/Users/Greg/code/cmake-problem-example/main.c:1:10: fatal error: png.h: No such file or directory
1 | #include <png.h>
| ^~~~~~~
compilation terminated.
The include file is not being included automatically through the target. I think that it is related to this line and this line because it is private by default.
Thank you for the report. I want to release libpng-1.6.40 right now, but I will take a closer look at this issue after that.
Using libpng with FetchContent does not work because header files are missing. I am using Windows 10 and I don't have libpng installed elsewhere.
Does FetchContent work correctly in cross-build environments?