Not understanding why CMakeLists.txt is not finding my dependency.

Looks like you are missing linking to SDL2::SDL2 target. So instead of:

target_link_libraries(RedButtonApp ${SDL2_MIXER_LIBRARIES})

there should be:

target_link_libraries(RedButtonApp
    PRIVATE
        SDL2::SDL2
        #SDL2::SDL2main
        ${SDL2_MIXER_LIBRARIES} # is this one needed?
)

or whichever other targets you have in the /path/to/homebrew/Cellar/sdl2/2.30.6/lib/cmake/SDL2/sdl2-config.cmake in your system.

I would also recommend to use find_package() with CONFIG, since this SDL version/package seems to provide a CMake config.

1 Like