1+ # This file is abysmal. I can't stand working with these 3rd party libraries because, for me at
2+ # least, nothing ever works as advertised. If you know what you are doing and you want to build
3+ # this, what's here can be a guide to get you going. I built this on macOS (not this file) and
4+ # WIN32. After I modified it for macOS the WIN32 broke so I modified it for WIN32 and now the
5+ # APPLE is broken. Probably an easy fix if you knwo what you are doing which I cleary don't when
6+ # it comes to SDL
7+
18cmake_minimum_required (VERSION 3.16)
29
310# Set project name
@@ -7,10 +14,18 @@ project(mmm LANGUAGES C)
714set (CMAKE_CXX_STANDARD 11)
815set (CMAKE_CXX_STANDARD_REQUIRED True )
916
10- # Find SDL2, SDL2_image, and SDL2_mixer
11- find_package (SDL2 REQUIRED)
12- find_package (SDL2_image REQUIRED)
13- find_package (SDL2_mixer REQUIRED)
17+ # Find SDL2, SDL2_image, and SDL2_mixer using pkg-config for macOS
18+ if (APPLE )
19+ find_package (PkgConfig REQUIRED)
20+ pkg_check_modules(SDL2 REQUIRED sdl2)
21+ pkg_check_modules(SDL2_image REQUIRED sdl2_image)
22+ pkg_check_modules(SDL2_mixer REQUIRED sdl2_mixer)
23+ else ()
24+ # Find SDL2, SDL2_image, and SDL2_mixer for other platforms
25+ find_package (SDL2 REQUIRED)
26+ find_package (SDL2_image REQUIRED)
27+ find_package (SDL2_mixer REQUIRED)
28+ endif ()
1429
1530# Add the executable
1631add_executable (${PROJECT_NAME}
@@ -33,9 +48,10 @@ target_link_libraries(${PROJECT_NAME}
3348 ${SDL2_IMAGE_LIBRARIES}
3449)
3550
36- # I need this on Windows. Why this is such a struggle eludes me
37- if (WIN32 )
38- # Fallback for Windows if SDL2_IMAGE_LIBRARIES is not found
51+ # Link libraries depending on platform
52+ if (APPLE )
53+ target_link_libraries (${PROJECT_NAME} ${SDL2_LIBRARIES} ${SDL2_image_LIBRARIES} ${SDL2_mixer_LIBRARIES} )
54+ elseif (WIN32 )
3955 target_link_libraries (${PROJECT_NAME}
4056 "C:/Users/swessels/develop/github/external/vcpkg/installed/x64-windows/lib/SDL2.lib"
4157 "C:/Users/swessels/develop/github/external/vcpkg/installed/x64-windows/lib/SDL2_image.lib"
@@ -53,5 +69,7 @@ if (WIN32)
5369 $<TARGET_FILE_DIR:${PROJECT_NAME} >
5470 )
5571 endforeach ()
56-
72+ else ()
73+ # Link libraries for non-Apple, non-Windows platforms (Linux, etc.)
74+ target_link_libraries (${PROJECT_NAME} ${SDL2_LIBRARIES} ${SDL2_image_LIBRARIES} ${SDL2_mixer_LIBRARIES} )
5775endif ()
0 commit comments