Problem understanding CMake and SDL

I’m trying to get the emulator hatari (Hatari · GitHub) to cross compile with SDL2’s own CMake script instead of the projects own.
find_package(SDL2 REQUIRED) does not fail, but soon I see this:

CMake Error at src/CMakeLists.txt:15 (add_library):
  Target "Floppy" links to target "SDL2::SDL2" but the target was not found.
  Perhaps a find_package() call is missing for an IMPORTED target, or an
  ALIAS target is missing?


CMake Error at src/CMakeLists.txt:145 (add_executable):
  Target "hatari" links to target "SDL2::SDL2" but the target was not found.
  Perhaps a find_package() call is missing for an IMPORTED target, or an
  ALIAS target is missing?


CMake Error at src/CMakeLists.txt:145 (add_executable):
  Target "hatari" links to target "SDL2::SDL2" but the target was not found.
  Perhaps a find_package() call is missing for an IMPORTED target, or an
  ALIAS target is missing?


CMake Error at src/CMakeLists.txt:145 (add_executable):
  Target "hatari" links to target "SDL2::SDL2" but the target was not found.
  Perhaps a find_package() call is missing for an IMPORTED target, or an
  ALIAS target is missing?


CMake Error at src/CMakeLists.txt:145 (add_executable):
  Target "hatari" links to target "SDL2::SDL2" but the target was not found.
  Perhaps a find_package() call is missing for an IMPORTED target, or an
  ALIAS target is missing?


CMake Error at src/CMakeLists.txt:145 (add_executable):
  Target "hatari" links to target "SDL2::SDL2" but the target was not found.
  Perhaps a find_package() call is missing for an IMPORTED target, or an
  ALIAS target is missing?


CMake Error at src/CMakeLists.txt:145 (add_executable):
  Target "hatari" links to target "SDL2::SDL2" but the target was not found.
  Perhaps a find_package() call is missing for an IMPORTED target, or an
  ALIAS target is missing?


CMake Error at src/debug/CMakeLists.txt:10 (add_library):
  Target "Debug" links to target "SDL2::SDL2" but the target was not found.
  Perhaps a find_package() call is missing for an IMPORTED target, or an
  ALIAS target is missing?


CMake Error at src/falcon/CMakeLists.txt:6 (add_library):
  Target "Falcon" links to target "SDL2::SDL2" but the target was not found.
  Perhaps a find_package() call is missing for an IMPORTED target, or an
  ALIAS target is missing?


CMake Error at src/gui-sdl/CMakeLists.txt:8 (add_library):
  Target "GuiSdl" links to target "SDL2::SDL2" but the target was not found.
  Perhaps a find_package() call is missing for an IMPORTED target, or an
  ALIAS target is missing?


CMake Error at src/cpu/CMakeLists.txt:89 (add_library):
  Target "UaeCpu" links to target "SDL2::SDL2" but the target was not found.
  Perhaps a find_package() call is missing for an IMPORTED target, or an
  ALIAS target is missing?


CMake Error at tools/hmsa/CMakeLists.txt:12 (add_executable):
  Target "hmsa" links to target "SDL2::SDL2" but the target was not found.
  Perhaps a find_package() call is missing for an IMPORTED target, or an
  ALIAS target is missing?

Before hatari deleted their own FindSDL cmake script, it compiled without problems. So the question is if something is wrong with the CMake files in hatari, or in SDL2. Is there anyone here who can shed some light?

Hi! Since you mentioned cross-compiling, what is your build environment, toolchain, and SDL2 version?

Great question!

The cross compiler is a self compiled multilib capable x86_64-w64-mingw32-gcc (which means that it can compile for both win32 and win64) - SDL v2.24.0. Build environment is Linux (Ubuntu)

CMake finds SDL2 as shown here:

Libraries summary :
-------------------

  - sdl :       using SDL2 v2.24.0
  - readline :  found, enables history/completion in the debugger
  - zlib :      found, allows to use zip/gz files directly
  - png :       found, allows to compress screenshot/avi files using png
  - portmidi :  not found, install it for MIDI support on Windows / OSX
  - capsimage : v5 found, allow to use .IPF, .RAW and .CTR disk images
  - python Gtk: found, python-ui can be used
  - capstone :  not found, install it to use extend disassembly options
  - LFS :       Large File Support is available (size of off_t = 8),
                AVI recording and HD image files can be bigger than 2 GB

  Note: times() function is missing (sys/times.h is not available)
        ==> using inaccurate SDL_GetTicks() instead

-- Configuring done

The error comes afterwards

Your project has Cirrus, Gitlab and Travis pipeline yaml files. Which of them is giving this issue? I could not find a link in the readme.

None of them. This is my own extremely simple script. Log files are here: Index of /~hatari/latest/windows

Okay, the problem goes away if I compile SDL with CMake instead of using autotools. It seems like the cmake files installed with autotools are not the same as the ones installed when using CMake.