@@ -44,25 +44,103 @@ include(FindPkgConfig)
4444set (CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH } "${CMAKE_SOURCE_DIR } /cmake/" )
4545
4646set (ALLEGRO_VERSION 5)
47- pkg_check_modules (ALLEGRO5 allegro-${ALLEGRO_VERSION} )
48- if (NOT ALLEGRO5_FOUND)
49- set (ALLEGRO_VERSION 5.0)
50- pkg_check_modules (ALLEGRO5 REQUIRED allegro-${ALLEGRO_VERSION} )
51- endif (NOT ALLEGRO5_FOUND )
52-
53- pkg_check_modules (ALLEGRO5_AUDIO REQUIRED allegro_audio-${ALLEGRO_VERSION} )
54- pkg_check_modules (ALLEGRO5_IMAGE REQUIRED allegro_image-${ALLEGRO_VERSION} )
55- pkg_check_modules (ALLEGRO5_MEMFILE REQUIRED allegro_memfile-${ALLEGRO_VERSION} )
56- pkg_check_modules (ALLEGRO5_PRIMITIVES REQUIRED allegro_primitives-${ALLEGRO_VERSION} )
57- if (APPLE )
58- pkg_check_modules (ALLEGRO5_MAIN REQUIRED allegro_main-${ALLEGRO_VERSION} )
59- endif (APPLE )
60- include_directories (SYSTEM ${ALLEGRO5_INCLUDE_DIRS} )
47+ if (CMAKE_SYSTEM_NAME STREQUAL "iOS" )
48+ # For iOS, pkg-config finds macOS libraries which can't be linked
49+ # Prevent pkg-config from being used to avoid finding macOS libraries
50+ set (PKG_CONFIG_EXECUTABLE "" )
51+
52+ # Look for iOS-built Allegro in the expected location
53+ set (ALLEGRO_IOS_PREFIX "$ENV{ALLEGRO_IOS_PREFIX} " CACHE PATH "Path to iOS-built Allegro installation" )
54+ if (NOT ALLEGRO_IOS_PREFIX)
55+ set (ALLEGRO_IOS_PREFIX "${CMAKE_CURRENT_SOURCE_DIR } /../allegro-ios-install" )
56+ endif ()
57+
58+ # Find iOS-built Allegro libraries
59+ find_library (ALLEGRO5_LIBRARY
60+ NAMES allegro allegro-5.2 allegro-5.0
61+ PATHS ${ALLEGRO_IOS_PREFIX} /lib
62+ NO_DEFAULT_PATH
63+ )
64+ find_library (ALLEGRO5_AUDIO_LIBRARY
65+ NAMES allegro_audio allegro_audio-5.2 allegro_audio-5.0
66+ PATHS ${ALLEGRO_IOS_PREFIX} /lib
67+ NO_DEFAULT_PATH
68+ )
69+ find_library (ALLEGRO5_IMAGE_LIBRARY
70+ NAMES allegro_image allegro_image-5.2 allegro_image-5.0
71+ PATHS ${ALLEGRO_IOS_PREFIX} /lib
72+ NO_DEFAULT_PATH
73+ )
74+ find_library (ALLEGRO5_MEMFILE_LIBRARY
75+ NAMES allegro_memfile allegro_memfile-5.2 allegro_memfile-5.0
76+ PATHS ${ALLEGRO_IOS_PREFIX} /lib
77+ NO_DEFAULT_PATH
78+ )
79+ find_library (ALLEGRO5_PRIMITIVES_LIBRARY
80+ NAMES allegro_primitives allegro_primitives-5.2 allegro_primitives-5.0
81+ PATHS ${ALLEGRO_IOS_PREFIX} /lib
82+ NO_DEFAULT_PATH
83+ )
84+ find_library (ALLEGRO5_MAIN_LIBRARY
85+ NAMES allegro_main allegro_main-5.2 allegro_main-5.0
86+ PATHS ${ALLEGRO_IOS_PREFIX} /lib
87+ NO_DEFAULT_PATH
88+ )
89+
90+ if (ALLEGRO5_LIBRARY AND ALLEGRO5_AUDIO_LIBRARY AND ALLEGRO5_IMAGE_LIBRARY AND ALLEGRO5_MEMFILE_LIBRARY AND ALLEGRO5_PRIMITIVES_LIBRARY)
91+ set (ALLEGRO5_FOUND TRUE )
92+ set (ALLEGRO5_LIBRARIES ${ALLEGRO5_LIBRARY} )
93+ set (ALLEGRO5_AUDIO_LIBRARIES ${ALLEGRO5_AUDIO_LIBRARY} )
94+ set (ALLEGRO5_IMAGE_LIBRARIES ${ALLEGRO5_IMAGE_LIBRARY} )
95+ set (ALLEGRO5_MEMFILE_LIBRARIES ${ALLEGRO5_MEMFILE_LIBRARY} )
96+ set (ALLEGRO5_PRIMITIVES_LIBRARIES ${ALLEGRO5_PRIMITIVES_LIBRARY} )
97+ if (ALLEGRO5_MAIN_LIBRARY)
98+ set (ALLEGRO5_MAIN_LIBRARIES ${ALLEGRO5_MAIN_LIBRARY} )
99+ endif ()
100+
101+ # Set include directories
102+ find_path (ALLEGRO5_INCLUDE_DIRS
103+ NAMES allegro5/allegro.h
104+ PATHS ${ALLEGRO_IOS_PREFIX} /include
105+ NO_DEFAULT_PATH
106+ )
107+ if (ALLEGRO5_INCLUDE_DIRS)
108+ include_directories (SYSTEM ${ALLEGRO5_INCLUDE_DIRS} )
109+ else ()
110+ message (FATAL_ERROR "Allegro headers not found in ${ALLEGRO_IOS_PREFIX} /include" )
111+ endif ()
112+ else ()
113+ message (FATAL_ERROR "Allegro libraries not found for iOS in ${ALLEGRO_IOS_PREFIX} /lib.\n "
114+ "Please build Allegro for iOS first. See the GitHub workflow for build steps." )
115+ endif ()
116+ else ()
117+ pkg_check_modules (ALLEGRO5 allegro-${ALLEGRO_VERSION} )
118+ if (NOT ALLEGRO5_FOUND)
119+ set (ALLEGRO_VERSION 5.0)
120+ pkg_check_modules (ALLEGRO5 REQUIRED allegro-${ALLEGRO_VERSION} )
121+ endif (NOT ALLEGRO5_FOUND )
122+
123+ pkg_check_modules (ALLEGRO5_AUDIO REQUIRED allegro_audio-${ALLEGRO_VERSION} )
124+ pkg_check_modules (ALLEGRO5_IMAGE REQUIRED allegro_image-${ALLEGRO_VERSION} )
125+ pkg_check_modules (ALLEGRO5_MEMFILE REQUIRED allegro_memfile-${ALLEGRO_VERSION} )
126+ pkg_check_modules (ALLEGRO5_PRIMITIVES REQUIRED allegro_primitives-${ALLEGRO_VERSION} )
127+ if (APPLE )
128+ pkg_check_modules (ALLEGRO5_MAIN REQUIRED allegro_main-${ALLEGRO_VERSION} )
129+ endif (APPLE )
130+ include_directories (SYSTEM ${ALLEGRO5_INCLUDE_DIRS} )
131+ endif ()
61132
62133if (PANDORA)
63134 find_package (OpenGLES )
64135 include_directories (SYSTEM ${OPENGLES_INCLUDE_DIR} )
65136 set (OPENGL_LIBRARIES ${OPENGLES_LIBRARIES} )
137+ elseif (CMAKE_SYSTEM_NAME STREQUAL "iOS" )
138+ # iOS uses OpenGL ES, but Allegro handles graphics internally
139+ # Link against OpenGLES framework
140+ find_library (OPENGLES_LIBRARY OpenGLES )
141+ if (OPENGLES_LIBRARY)
142+ set (OPENGL_LIBRARIES ${OPENGLES_LIBRARY} )
143+ endif (OPENGLES_LIBRARY )
66144else (PANDORA )
67145 find_package (OpenGL )
68146 include_directories (SYSTEM ${OPENGL_INCLUDE_DIR} )
@@ -82,8 +160,21 @@ if(WIN32)
82160 list (APPEND OPTIONAL_LIBRARIES winmm)
83161elseif (APPLE )
84162 find_library (AUDIOTOOLBOX_LIBRARY AudioToolbox )
85- find_library (AUDIOUNIT_LIBRARY AudioUnit )
86- list (APPEND OPTIONAL_LIBRARIES ${AUDIOTOOLBOX_LIBRARY} ${AUDIOUNIT_LIBRARY} )
163+ if (CMAKE_SYSTEM_NAME STREQUAL "iOS" )
164+ # On iOS, AudioUnit is part of AudioToolbox, no need to link separately
165+ if (AUDIOTOOLBOX_LIBRARY)
166+ list (APPEND OPTIONAL_LIBRARIES ${AUDIOTOOLBOX_LIBRARY} )
167+ endif (AUDIOTOOLBOX_LIBRARY )
168+ else ()
169+ # macOS: link both AudioToolbox and AudioUnit
170+ find_library (AUDIOUNIT_LIBRARY AudioUnit )
171+ if (AUDIOTOOLBOX_LIBRARY)
172+ list (APPEND OPTIONAL_LIBRARIES ${AUDIOTOOLBOX_LIBRARY} )
173+ endif (AUDIOTOOLBOX_LIBRARY )
174+ if (AUDIOUNIT_LIBRARY)
175+ list (APPEND OPTIONAL_LIBRARIES ${AUDIOUNIT_LIBRARY} )
176+ endif (AUDIOUNIT_LIBRARY )
177+ endif ()
87178elseif (WITH_ALSA_MIDI)
88179 pkg_check_modules (ALSA alsa )
89180 if (ALSA_FOUND)
@@ -143,16 +234,31 @@ include_directories("include" "${PROJECT_BINARY_DIR}/include")
143234add_executable (dunedynasty WIN32
144235 ${DUNEDYNASTY_SRC_FILES} ${CMAKE_SOURCE_DIR } /src/icon/icon.rc )
145236
146- target_link_libraries (dunedynasty
147- ${OPTIONAL_LIBRARIES}
148- ${ALLEGRO5_AUDIO_LDFLAGS}
149- ${ALLEGRO5_IMAGE_LDFLAGS}
150- ${ALLEGRO5_MEMFILE_LDFLAGS}
151- ${ALLEGRO5_PRIMITIVES_LDFLAGS}
152- ${ALLEGRO5_MAIN_LDFLAGS}
153- ${ALLEGRO5_LDFLAGS}
154- ${OPENGL_LIBRARIES}
155- )
237+ if (CMAKE_SYSTEM_NAME STREQUAL "iOS" )
238+ # For iOS, use the directly found libraries
239+ target_link_libraries (dunedynasty
240+ ${OPTIONAL_LIBRARIES}
241+ ${ALLEGRO5_LIBRARIES}
242+ ${ALLEGRO5_AUDIO_LIBRARIES}
243+ ${ALLEGRO5_IMAGE_LIBRARIES}
244+ ${ALLEGRO5_MEMFILE_LIBRARIES}
245+ ${ALLEGRO5_PRIMITIVES_LIBRARIES}
246+ ${ALLEGRO5_MAIN_LIBRARIES}
247+ ${OPENGL_LIBRARIES}
248+ )
249+ else ()
250+ # For other platforms, use pkg-config LDFLAGS
251+ target_link_libraries (dunedynasty
252+ ${OPTIONAL_LIBRARIES}
253+ ${ALLEGRO5_AUDIO_LDFLAGS}
254+ ${ALLEGRO5_IMAGE_LDFLAGS}
255+ ${ALLEGRO5_MEMFILE_LDFLAGS}
256+ ${ALLEGRO5_PRIMITIVES_LDFLAGS}
257+ ${ALLEGRO5_MAIN_LDFLAGS}
258+ ${ALLEGRO5_LDFLAGS}
259+ ${OPENGL_LIBRARIES}
260+ )
261+ endif ()
156262
157263if (CMAKE_MACOSX_BUNDLE )
158264 set_target_properties (dunedynasty PROPERTIES
0 commit comments