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

Incompatible with FetchContent #476

Open
gregjohnson2017 opened this issue May 16, 2023 · 2 comments
Open

Incompatible with FetchContent #476

gregjohnson2017 opened this issue May 16, 2023 · 2 comments

Comments

@gregjohnson2017
Copy link

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.

error_output.txt

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.

@ctruta
Copy link
Member

ctruta commented Jun 21, 2023

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.

@jbowler
Copy link
Contributor

jbowler commented Dec 27, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants