Skip to content

Commit 2d9ec99

Browse files
committed
Mac build improvements
Move closer to allowing an "out of the box" distributable build for Mac: * fix the icon for the .app * link SDL2 statically, a PR has been sent to the original repo here: tcbrindle/sdl2-cmake-scripts#9 * link SFML statically TODO: For a releasable build on OS X, system libs must be linked dynamically while third party libs are linked statically or bundled. The goal is to link them statically. The two remaining libs that need static linking are PNG and wX. For PNG a similar approach to the one used for SDL2 using pkg-config should work fine and be simple to implement. For wX things are more complicated. The default build of wX does not include static libs, I will need to submit a PR for Homebrew to change the default build to include both dynamic and static versions.
1 parent 6899b97 commit 2d9ec99

File tree

4 files changed

+97
-26
lines changed

4 files changed

+97
-26
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ src/wx/cmdtab.cpp
66
src/wx/wxvbam.xrs
77
build/
88

9+
# vim swap files
10+
*.sw?

CMakeLists.txt

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,6 @@ ELSE()
6565
ADD_DEFINITIONS(-DNDEBUG)
6666
ENDIF()
6767

68-
# Fill in SDLMAIN_LIBRARY on OS X manually to avoid using SDLMain.m
69-
# OS X users will have to compile and install SDL from source.
70-
if( APPLE AND ENABLE_SDL )
71-
ADD_DEFINITIONS (-DwxMAC_USE_CORE_GRAPHICS )
72-
SET(SDL2MAIN_LIBRARY "-lSDL2main")
73-
endif( APPLE AND ENABLE_SDL )
74-
7568
# Add support for Homebrew, MacPorts and Fink on OS X
7669
# as well as for ObjectiveC code
7770
IF(APPLE)
@@ -107,7 +100,7 @@ IF(APPLE)
107100

108101
# and compile as Objective-C++ for ObjectiveC #ifdefs
109102
SET(CMAKE_CXX_COMPILE_OBJECT "<CMAKE_CXX_COMPILER> -x objective-c++ <DEFINES> <INCLUDES> <FLAGS> -o <OBJECT> -c <SOURCE>")
110-
ENDIF()
103+
ENDIF(APPLE)
111104

112105
# We do not support amd64 asm yet
113106
IF((ENABLE_ASM_CORE OR ENABLE_ASM_SCALERS OR ENABLE_MMX)
@@ -129,17 +122,26 @@ if( ENABLE_ASM_SCALERS )
129122
endif( ENABLE_ASM_SCALERS )
130123

131124
# Look for some dependencies using CMake scripts
132-
FIND_PACKAGE ( ZLIB REQUIRED )
133-
FIND_PACKAGE ( PNG REQUIRED )
134-
FIND_PACKAGE ( OpenGL REQUIRED )
135-
FIND_PACKAGE ( SDL2 REQUIRED )
125+
FIND_PACKAGE(ZLIB REQUIRED)
126+
FIND_PACKAGE(OpenGL REQUIRED)
127+
128+
# TODO: make static on mac
129+
FIND_PACKAGE(PNG REQUIRED)
130+
131+
IF(APPLE)
132+
SET(SDL2_STATIC ON)
133+
ENDIF(APPLE)
134+
135+
FIND_PACKAGE(SDL2 REQUIRED)
136+
ADD_DEFINITIONS(${SDL2_DEFINITIONS})
136137

137138
if( ENABLE_LINK )
138-
if( WIN32 )
139+
if(WIN32 OR APPLE)
139140
set(SFML_STATIC_LIBRARIES TRUE)
140-
endif( WIN32 )
141+
endif(WIN32 OR APPLE)
141142
FIND_PACKAGE ( SFML 2 COMPONENTS network system )
142143
endif( ENABLE_LINK )
144+
143145
# set the standard libraries all ports use
144146
SET(VBAMCORE_LIBS
145147
vbamcore

CMakeScripts/FindSDL2.cmake

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,22 @@
1-
21
# This module defines
32
# SDL2_LIBRARY, the name of the library to link against
43
# SDL2_FOUND, if false, do not try to link to SDL2
54
# SDL2_INCLUDE_DIR, where to find SDL.h
65
#
6+
# If you have pkg-config, these extra variables are also defined:
7+
# SDL2_DEFINITIONS, extra CFLAGS
8+
# SDL2_EXTRA_LIBS, extra link libs
9+
# SDL2_LINKER_FLAGS, extra link flags
10+
#
11+
# The latter two are automatically added to SDL2_LIBRARY
12+
#
13+
# To use them, add code such as:
14+
#
15+
# # SET(SDL2_STATIC ON) # if you want to link SDL2 statically
16+
# FIND_PACKAGE(SDL2 REQUIRED)
17+
# ADD_DEFINITIONS(${SDL2_DEFINITIONS})
18+
# TARGET_LINK_LIBRARIES(your-executable-target ${SDL2_LIBRARY} ...)
19+
#
720
# This module responds to the the flag:
821
# SDL2_BUILDING_LIBRARY
922
# If this is defined, then no SDL2main will be linked in because
@@ -12,6 +25,8 @@
1225
# module will attempt to locate and set the the proper link flags
1326
# as part of the returned SDL2_LIBRARY variable.
1427
#
28+
# If you want to link SDL2 statically, set SDL2_STATIC to ON.
29+
#
1530
# Don't forget to include SDLmain.h and SDLmain.m your project for the
1631
# OS X framework based version. (Other versions link to -lSDL2main which
1732
# this module will try to find on your behalf.) Also for OS X, this
@@ -47,7 +62,7 @@
4762
# SDL2_LIBRARY to override this selection or set the CMake environment
4863
# CMAKE_INCLUDE_PATH to modify the search paths.
4964
#
50-
# Note that the header path has changed from SDL2/SDL.h to just SDL.h
65+
# Note that the header path has changed from SDL3/SDL.h to just SDL.h
5166
# This needed to change because "proper" SDL convention
5267
# is #include "SDL.h", not <SDL2/SDL.h>. This is done for portability
5368
# reasons because not all systems place things in SDL2/ (see FreeBSD).
@@ -86,11 +101,21 @@ FIND_PATH(SDL2_INCLUDE_DIR SDL.h
86101
PATHS ${SDL2_SEARCH_PATHS}
87102
)
88103

104+
SET(CURRENT_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES})
105+
106+
IF(SDL2_STATIC)
107+
IF(WIN32)
108+
SET(CMAKE_FIND_LIBRARY_SUFFIXES .lib .a)
109+
ELSE(WIN32)
110+
SET(CMAKE_FIND_LIBRARY_SUFFIXES .a)
111+
ENDIF(WIN32)
112+
ENDIF(SDL2_STATIC)
113+
89114
FIND_LIBRARY(SDL2_LIBRARY_TEMP
90115
NAMES SDL2
91116
HINTS
92117
$ENV{SDL2DIR}
93-
PATH_SUFFIXES lib64 lib
118+
PATH_SUFFIXES lib64 lib lib/x64 lib/x86
94119
PATHS ${SDL2_SEARCH_PATHS}
95120
)
96121

@@ -104,12 +129,15 @@ IF(NOT SDL2_BUILDING_LIBRARY)
104129
NAMES SDL2main
105130
HINTS
106131
$ENV{SDL2DIR}
107-
PATH_SUFFIXES lib64 lib
132+
PATH_SUFFIXES lib64 lib lib/x64 lib/x86
108133
PATHS ${SDL2_SEARCH_PATHS}
109134
)
110135
ENDIF(NOT ${SDL2_INCLUDE_DIR} MATCHES ".framework")
111136
ENDIF(NOT SDL2_BUILDING_LIBRARY)
112137

138+
SET(CMAKE_FIND_LIBRARY_SUFFIXES ${CURRENT_FIND_LIBRARY_SUFFIXES})
139+
UNSET(CURRENT_FIND_LIBRARY_SUFFIXES)
140+
113141
# SDL2 may require threads on your system.
114142
# The Apple build may not need an explicit flag because one of the
115143
# frameworks may already provide it.
@@ -118,11 +146,10 @@ IF(NOT APPLE)
118146
FIND_PACKAGE(Threads)
119147
ENDIF(NOT APPLE)
120148

121-
# MinGW needs an additional library, mwindows
122-
# It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -lmwindows
123-
# (Actually on second look, I think it only needs one of the m* libraries.)
149+
# MinGW needs an additional link flag, -mwindows
150+
# It's total link flags should look like -lmingw32 -lSDL2main -lSDL2 -mwindows
124151
IF(MINGW)
125-
SET(MINGW32_LIBRARY mingw32 CACHE STRING "mwindows for MinGW")
152+
SET(MINGW32_LIBRARY mingw32 "-mwindows" CACHE STRING "mwindows for MinGW")
126153
ENDIF(MINGW)
127154

128155
IF(SDL2_LIBRARY_TEMP)
@@ -155,6 +182,37 @@ IF(SDL2_LIBRARY_TEMP)
155182
SET(SDL2_LIBRARY_TEMP ${MINGW32_LIBRARY} ${SDL2_LIBRARY_TEMP})
156183
ENDIF(MINGW)
157184

185+
# Add some stuff from pkg-config, if available
186+
IF(NOT PKG_CONFIG_EXECUTABLE)
187+
FIND_PACKAGE(PkgConfig QUIET)
188+
ENDIF(NOT PKG_CONFIG_EXECUTABLE)
189+
190+
IF(PKG_CONFIG_EXECUTABLE)
191+
# get any definitions
192+
EXECUTE_PROCESS(COMMAND ${PKG_CONFIG_EXECUTABLE} --cflags-only-other sdl2 OUTPUT_VARIABLE SDL2_DEFINITIONS)
193+
194+
SET(SDL2_DEFINITIONS ${SDL2_DEFINITIONS} CACHE STRING "Extra CFLAGS for SDL2 from pkg-config")
195+
196+
# get any extra stuff needed for linking
197+
IF(NOT SDL2_STATIC)
198+
EXECUTE_PROCESS(COMMAND ${PKG_CONFIG_EXECUTABLE} --libs-only-other sdl2 OUTPUT_VARIABLE SDL2_LINKER_FLAGS_RAW OUTPUT_STRIP_TRAILING_WHITESPACE)
199+
200+
EXECUTE_PROCESS(COMMAND ${PKG_CONFIG_EXECUTABLE} --libs-only-l sdl2 OUTPUT_VARIABLE SDL2_EXTRA_LIBS_RAW OUTPUT_STRIP_TRAILING_WHITESPACE)
201+
ELSE(NOT SDL2_STATIC)
202+
EXECUTE_PROCESS(COMMAND ${PKG_CONFIG_EXECUTABLE} --static --libs-only-other sdl2 OUTPUT_VARIABLE SDL2_LINKER_FLAGS_RAW OUTPUT_STRIP_TRAILING_WHITESPACE)
203+
EXECUTE_PROCESS(COMMAND ${PKG_CONFIG_EXECUTABLE} --static --libs-only-l sdl2 OUTPUT_VARIABLE SDL2_EXTRA_LIBS_RAW OUTPUT_STRIP_TRAILING_WHITESPACE)
204+
ENDIF(NOT SDL2_STATIC)
205+
206+
STRING(REGEX REPLACE "[^ ]+SDL2[^ ]*" "" SDL2_EXTRA_LIBS_RAW2 "${SDL2_EXTRA_LIBS_RAW}")
207+
STRING(REGEX REPLACE " +" ";" SDL2_EXTRA_LIBS "${SDL2_EXTRA_LIBS_RAW2}")
208+
STRING(REGEX REPLACE " +" ";" SDL2_LINKER_FLAGS "${SDL2_LINKER_FLAGS_RAW}")
209+
210+
SET(SDL2_LINKER_FLAGS ${SDL2_LINKER_FLAGS} CACHE STRING "Linker flags for linking SDL2")
211+
SET(SDL2_EXTRA_LIBS ${SDL2_EXTRA_LIBS} CACHE STRING "Extra libraries for linking SDL2")
212+
213+
SET(SDL2_LIBRARY_TEMP ${SDL2_LIBRARY_TEMP} ${SDL2_EXTRA_LIBS} ${SDL2_LINKER_FLAGS})
214+
ENDIF(PKG_CONFIG_EXECUTABLE)
215+
158216
# Set the final string here so the GUI reflects the final state.
159217
SET(SDL2_LIBRARY ${SDL2_LIBRARY_TEMP} CACHE STRING "Where the SDL2 Library can be found")
160218
# Set the temp variable to INTERNAL so it is not seen in the CMake GUI
@@ -166,4 +224,3 @@ message("</FindSDL2.cmake>")
166224
INCLUDE(FindPackageHandleStandardArgs)
167225

168226
FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR)
169-

src/wx/CMakeLists.txt

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ if( WIN32 )
1010
endif( WIN32 )
1111
option( ENABLE_OPENAL "Enable OpenAL for the wxWidgets port" ON )
1212

13+
IF(APPLE)
14+
ADD_DEFINITIONS(-DwxMAC_USE_CORE_GRAPHICS)
15+
ENDIF(APPLE)
16+
1317
if( NOT ENABLE_CAIRO )
1418
ADD_DEFINITIONS (-DNO_CAIRO)
1519
endif( NOT ENABLE_CAIRO )
@@ -38,6 +42,10 @@ IF(CMAKE_BUILD_TYPE STREQUAL "Debug")
3842
ENDIF()
3943
ENDIF()
4044

45+
IF(APPLE)
46+
SET(wxWidgets_USE_STATIC ON)
47+
ENDIF(APPLE)
48+
4149
SET(wxWidgets_USE_UNICODE ON)
4250
# adv is for wxAboutBox
4351
# xml, html is for xrc
@@ -189,7 +197,9 @@ ENDIF( WIN32 )
189197

190198
link_directories( ${CMAKE_BINARY_DIR} )
191199

192-
SET(VBAM_ICON ${CMAKE_CURRENT_SOURCE_DIR}/icons/vbam.icns)
200+
SET(VBAM_ICON vbam.icns)
201+
202+
SET(VBAM_ICON_PATH ${CMAKE_CURRENT_SOURCE_DIR}/icons/${VBAM_ICON})
193203

194204
ADD_EXECUTABLE (
195205
visualboyadvance-m
@@ -198,7 +208,7 @@ ADD_EXECUTABLE (
198208
${SRC_WX}
199209
${HDR_WX}
200210
${RES_WX}
201-
${VBAM_ICON}
211+
${VBAM_ICON_PATH}
202212
${CM_STUFF}
203213
)
204214

@@ -221,7 +231,7 @@ if(APPLE)
221231
# this should set ROM file types correctly
222232
SET_PROPERTY(TARGET visualboyadvance-m APPEND PROPERTY MACOSX_BUNDLE_INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/wxplist.in)
223233
SET(MACOSX_BUNDLE_ICON_FILE ${VBAM_ICON})
224-
SET_SOURCE_FILES_PROPERTIES(${VBAM_ICON} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
234+
SET_SOURCE_FILES_PROPERTIES(${VBAM_ICON_PATH} PROPERTIES MACOSX_PACKAGE_LOCATION Resources)
225235
endif(APPLE)
226236

227237
SET(WX_EXE_NAME visualboyadvance-m-wx${CMAKE_EXECUTABLE_SUFFIX})

0 commit comments

Comments
 (0)