SDL_image icon indicating copy to clipboard operation
SDL_image copied to clipboard

SDL_image cmake doesn't use includes from SDL3_DIR

Open maia-s opened this issue 9 months ago • 7 comments

I'm on macos and have SDL3 version 3.2.4 installed via brew. SDL_image 3.2.2 requires SDL 3.2.6, so configuring SDL_image without setting anything else fails at cmake configuration time, as expected.

If I build and do a temporary local install of SDL 3.2.6 and pass its cmake configuration dir to SDL_image via the SDL3_DIR cmake variable, cmake configuration succeeds, but then compilation fails later on:

make: warning: jobserver unavailable: using -j1.  Add `+' to parent make rule.
  /Users/maia/Dev/sdl3-sys/sdl3-image-src/SDL_image/src/IMG_bmp.c:429:38: error: use of undeclared identifier 'SDL_PROP_SURFACE_HOTSPOT_X_NUMBER'
    429 |         SDL_SetNumberProperty(props, SDL_PROP_SURFACE_HOTSPOT_X_NUMBER, nHotX);
        |                                      ^
  /Users/maia/Dev/sdl3-sys/sdl3-image-src/SDL_image/src/IMG_bmp.c:430:38: error: use of undeclared identifier 'SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER'
    430 |         SDL_SetNumberProperty(props, SDL_PROP_SURFACE_HOTSPOT_Y_NUMBER, nHotY);
        |                                      ^
  2 errors generated.
  make[2]: *** [CMakeFiles/SDL3_image-shared.dir/src/IMG_bmp.c.o] Error 1
  make[1]: *** [CMakeFiles/SDL3_image-shared.dir/all] Error 2
  make: *** [all] Error 2

It appears SDL_image is using the headers from the brew install instead of the headers set via SDL3_DIR.

maia-s avatar Mar 02 '25 13:03 maia-s

Does this error also happen if you build SDL3_image with vendored dependencies? This tests a hypothesis that the include directories of the file format libraries pull in the wrong SDL3 headers.

madebr avatar Mar 02 '25 18:03 madebr

It still happens if I only enable SDLIMAGE_VENDORED, but if I set SDLIMAGE_VENDORED to ON and also set SDLIMAGE_WEBP to OFF, it builds. This is really weird. It still fails if I only disable webp and don't enable vendored.

maia-s avatar Mar 02 '25 20:03 maia-s

+1, Also experiencing this when adding to my project.

rdrsss avatar Mar 17 '25 13:03 rdrsss

https://github.com/libsdl-org/SDL_image/blob/4fc74106d68dcc04b7aaa1e7359732b9a6787068/CMakeLists.txt#L990-L997

Does removing line 991 and 994 change the behavior?

madebr avatar Mar 17 '25 13:03 madebr

@madebr for me no, the error remains.

rdrsss avatar Mar 17 '25 15:03 rdrsss

@madebr I was able to fix this for myself. I realized i was on SDL 3.2.4 not 3.2.8. In the prior version SDL_PROP_SURFACE_HOTSPOT_X_NUMBER was not included as part of SDL_surface.h in the regular path but only in the macos framework path, so it wasn't resolving to the right header. Updating this has since fixed the issue. Thank you for your help.

rdrsss avatar Mar 17 '25 22:03 rdrsss

This isn't fixed. My issue isn't related to the framework. I did have an old SDL3 framework installed too, but that wasn't the issue.

Homebrew has since updated sdl3 to 3.2.8, but if I replace the headers in the brew install with 3.2.4 headers this still fails in the same way even though I pass an SDL3 3.2.8 install with 3.2.8 headers via SDL3_DIR to SDL_Image's cmake. Ie it picks up brew's headers in favor of the ones explicitly passed via SDL3_DIR.

maia-s avatar Mar 20 '25 16:03 maia-s

--- deleted ---

I realised my problem didn't match this Issue

Aditya-Tolikar avatar Oct 21 '25 19:10 Aditya-Tolikar

@maia-s Can you still reproduce this issue? Make sure SDL_image uses a new SDL feature, not available in SDL3 of brew.

madebr avatar Oct 24 '25 21:10 madebr

Yes. This is easy to reproduce now that SDL_image in main requires an unreleased version of SDL.

  1. Install sdl3 in homebrew. Currently this installs SDL 3.2.24.
  2. Compile SDL3 3.3.2 from source and install it locally somewhere
  3. (optional) For SDL_image, first try to run cmake without setting SDL3_DIR. It should exit with an error.
❯ cmake ../../sdl3-image-src/SDL_image
-- The C compiler identification is AppleClang 17.0.0.17000319
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Configuring SDL3_image 3.3.0
CMake Error at CMakeLists.txt:242 (find_package):
  Could not find a configuration file for package "SDL3" that is compatible
  with requested version "3.3.0".

  The following configuration files were considered but not accepted:

    /opt/homebrew/lib/cmake/SDL3/SDL3Config.cmake, version: 3.2.24
    /Library/Frameworks/share/cmake/SDL3/SDL3Config.cmake, version: 3.2.10



-- Configuring incomplete, errors occurred!
  1. Now run cmake while setting SDL3_DIR to the cmake dir installed in step 2. It should succeed, indicating that SDL3_DIR was used successfully by the cmake script
❯ cmake ../../sdl3-image-src/SDL_image -DSDL3_DIR=/Users/maia/Dev/scratch/SDL3.3/lib/cmake/SDL3
-- Configuring SDL3_image 3.3.0
-- Detecting Target CPU Architecture
-- Detecting Target CPU Architecture - ARM64
-- Performing Test LINKER_SUPPORTS_VERSION_SCRIPT
-- Performing Test LINKER_SUPPORTS_VERSION_SCRIPT - Failed
-- Performing Test HAVE_WNO_ERROR_DEPRECATED_DECLARATIONS
-- Performing Test HAVE_WNO_ERROR_DEPRECATED_DECLARATIONS - Success
-- The OBJC compiler identification is AppleClang 17.0.0.17000319
-- Detecting OBJC compiler ABI info
-- Detecting OBJC compiler ABI info - done
-- Check for working OBJC compiler: /usr/bin/clang - skipped
-- SDL3_image: Using system libavif
-- Dynamic libavif: libavif.16.dylib
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- SDL3_image: Using system libwebp
-- Dynamic libwebpdemux: libwebpdemux.2.dylib
-- Dynamic libwebpmux: libwebpmux.3.dylib
-- Dynamic libwebp: libwebp.7.dylib
-- SDL3_image backends:
-- - enabled:  stb imageio avif ani bmp gif jpg lbm pcx png pnm qoi svg tga tif webp xcf xpm xv
-- - disabled: wic jxl
-- Configuring done (0.7s)
-- Generating done (0.0s)
-- Build files have been written to: /Users/maia/Dev/public/sdl3-sys-rs/target/build-sdl-image
  1. Now compile. It fails with an error that syms from SDL 3.3 aren't declared.
❯ ninja
[3/34] Building C object CMakeFiles/SDL3_image-shared.dir/src/IMG_png.c.o
FAILED: [code=1] CMakeFiles/SDL3_image-shared.dir/src/IMG_png.c.o
/usr/bin/cc -DBUILD_SDL -DDLL_EXPORT -DLOAD_ANI -DLOAD_AVIF -DLOAD_AVIF_DYNAMIC=\"libavif.16.dylib\" -DLOAD_BMP -DLOAD_GIF -DLOAD_JPG -DLOAD_LBM -DLOAD_PCX -DLOAD_PNG -DLOAD_PNM -DLOAD_QOI -DLOAD_SVG -DLOAD_TGA -DLOAD_WEBP -DLOAD_WEBPDEMUX_DYNAMIC=\"libwebpdemux.2.dylib\" -DLOAD_WEBPMUX_DYNAMIC=\"libwebpmux.3.dylib\" -DLOAD_WEBP_DYNAMIC=\"libwebp.7.dylib\" -DLOAD_XCF -DLOAD_XPM -DLOAD_XV -DSAVE_ANI=1 -DSAVE_AVIF=1 -DSAVE_BMP=1 -DSAVE_GIF=1 -DSAVE_JPG=1 -DSAVE_PNG=1 -DSAVE_TGA=1 -DSAVE_WEBP=1 -DSDL_BUILD_MAJOR_VERSION=3 -DSDL_BUILD_MICRO_VERSION=0 -DSDL_BUILD_MINOR_VERSION=3 -DUSE_STBIMAGE -I/Users/maia/Dev/public/sdl3-sys-rs/sdl3-image-src/SDL_image/include -I/opt/homebrew/include -I/opt/homebrew/include/webp -I/Users/maia/Dev/scratch/SDL3.3/include -O2 -g -DNDEBUG -arch arm64 -fPIC -fvisibility=hidden -Wall -Wextra -Wno-error=deprecated-declarations -MD -MT CMakeFiles/SDL3_image-shared.dir/src/IMG_png.c.o -MF CMakeFiles/SDL3_image-shared.dir/src/IMG_png.c.o.d -o CMakeFiles/SDL3_image-shared.dir/src/IMG_png.c.o -c /Users/maia/Dev/public/sdl3-sys-rs/sdl3-image-src/SDL_image/src/IMG_png.c
/Users/maia/Dev/public/sdl3-sys-rs/sdl3-image-src/SDL_image/src/IMG_png.c:64:12: error: call to undeclared function 'SDL_LoadPNG_IO'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
   64 |     return SDL_LoadPNG_IO(src, false);
      |            ^
(...)

Note the order of the include dirs passed to the compiler: -I/Users/maia/Dev/public/sdl3-sys-rs/sdl3-image-src/SDL_image/include -I/opt/homebrew/include -I/opt/homebrew/include/webp -I/Users/maia/Dev/scratch/SDL3.3/include

(This issue also affects SDL_mixer)

maia-s avatar Oct 25 '25 13:10 maia-s

Thanks, does the following patch fix this issue?

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -303,7 +303,7 @@ target_compile_definitions(${sdl3_image_target_name} PRIVATE
     SDL_BUILD_MINOR_VERSION=${MINOR_VERSION}
     SDL_BUILD_MICRO_VERSION=${MICRO_VERSION}
 )
-target_link_libraries(${sdl3_image_target_name} PUBLIC SDL3::Headers)
+target_include_directories(${sdl3_image_target_name} PUBLIC $<TARGET_PROPERTY:SDL3::Headers,INTERFACE_INCLUDE_DIRECTORIES>)
 if(SDLIMAGE_BUILD_SHARED_LIBS)
     target_link_libraries(${sdl3_image_target_name} PRIVATE SDL3::SDL3-shared)
 endif()

madebr avatar Oct 25 '25 19:10 madebr

Yes, that fixes it!

maia-s avatar Oct 26 '25 14:10 maia-s

Thanks for checking!

I pushed this fix to all main and release branches of all SDL satellite projects.

madebr avatar Oct 26 '25 19:10 madebr

Thanks for checking!

I pushed this fix to all main and release branches of all SDL satellite projects.

Thanks!

slouken avatar Oct 26 '25 20:10 slouken