Add Xcode target support

It is really messy at the moment. There is no support for copying the
necessary frameworks and dylibs out to the bundle for distribution, and
it is a frankenstein of manual find_library and find_package which can
sometimes pick up Homebrew dylibs.
This commit is contained in:
Ronald Kinard 2015-01-28 00:58:30 -06:00
parent 05f5ec664a
commit 479ebc3f94
3 changed files with 63 additions and 9 deletions

View file

@ -15,6 +15,24 @@ function(prepend_sources SOURCE_FILES)
set(${SOURCE_FILES} ${MODIFIED} PARENT_SCOPE)
endfunction()
# Macro to add OSX framework
macro(add_framework fwname appname)
find_library(FRAMEWORK_${fwname}
NAMES ${fwname}
PATHS ${CMAKE_OSX_SYSROOT}/System/Library
${CMAKE_OSX_SYSROOT}/Library
/System/Library
/Library
PATH_SUFFIXES Frameworks
NO_DEFAULT_PATH)
if( ${FRAMEWORK_${fwname}} STREQUAL FRAMEWORK_${fwname}-NOTFOUND)
MESSAGE(ERROR ": Framework ${fwname} not found")
else()
TARGET_LINK_LIBRARIES(${appname} PRIVATE "${FRAMEWORK_${fwname}}/${fwname}")
MESSAGE(STATUS "Framework ${fwname} found at ${FRAMEWORK_${fwname}}")
endif()
endmacro()
# 64-bit check
if(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
message(STATUS "Target is 64-bit")
@ -32,12 +50,21 @@ endif()
if (UNIX)
add_definitions(-DUNIXCOMMON)
endif()
if(${CMAKE_SYSTEM} MATCHES "Linux")
add_definitions(-DLINUX)
if(${SRB2_SYSTEM_BITS} EQUAL 64)
add_definitions(-DLINUX64)
endif()
endif()
if(${CMAKE_SYSTEM} MATCHES "Darwin")
add_definitions(-DMACOSX)
if(${CMAKE_C_COMPILER_ID} MATCHES "Clang")
set(CLANG ON)
endif()
endif()
# TODO support MacOSX builds
add_subdirectory(src/)

View file

@ -64,7 +64,7 @@ set(SRB2_CORE_SOURCES
screen.c
sounds.c
st_stuff.c
string.c
#string.c
tables.c
v_video.c
w_wad.c
@ -342,6 +342,8 @@ endif()
# Compatibility flag with later versions of GCC
# We should really fix our code to not need this
if(NOT CLANG)
add_compile_options(-mno-ms-bitfields)
endif()
add_subdirectory(sdl)

View file

@ -40,6 +40,9 @@ set(SRB2_SDL2_EXE_NAME srb2sdl2)
if(${CMAKE_SYSTEM} MATCHES "Windows")
set(SRB2_SDL2_EXE_NAME srb2win)
endif()
if(CLANG)
set(SRB2_SDL2_EXE_NAME SRB2)
endif()
# Dependency
find_package(SDL2)
@ -76,6 +79,26 @@ if(${SDL2_FOUND})
)
endif()
if(${CMAKE_SYSTEM} MATCHES Darwin)
set(MACOSX_BUNDLE_ICON_FILE Srb2mac.icns)
set_source_files_properties(macosx/Srb2mac.icns PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
set(SRB2_SDL2_TOTAL_SOURCES ${SRB2_SDL2_TOTAL_SOURCES}
macosx/mac_alert.c
macosx/mac_alert.h
macosx/Srb2mac.icns
)
endif()
if(CLANG)
add_executable(${SRB2_SDL2_EXE_NAME} MACOSX_BUNDLE ${SRB2_SDL2_TOTAL_SOURCES})
add_framework(CoreFoundation ${SRB2_SDL2_EXE_NAME})
add_framework(SDL2 ${SRB2_SDL2_EXE_NAME})
target_link_libraries(${SRB2_SDL2_EXE_NAME} PRIVATE
${PNG_LIBRARIES}
${ZLIB_LIBRARIES}
${OPENGL_LIBRARIES}
)
else()
add_executable(${SRB2_SDL2_EXE_NAME} WIN32 ${SRB2_SDL2_TOTAL_SOURCES})
target_link_libraries(${SRB2_SDL2_EXE_NAME} PRIVATE
@ -85,6 +108,8 @@ if(${SDL2_FOUND})
${OPENGL_LIBRARIES}
)
endif()
if(${CMAKE_SYSTEM} MATCHES Windows)
target_link_libraries(${SRB2_SDL2_EXE_NAME} PRIVATE
ws2_32