diff --git a/CMakeLists.txt b/CMakeLists.txt index 30ef1338..dc511c7e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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/) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e9f52321..442ddca6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -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 -add_compile_options(-mno-ms-bitfields) +if(NOT CLANG) + add_compile_options(-mno-ms-bitfields) +endif() add_subdirectory(sdl) diff --git a/src/sdl/CMakeLists.txt b/src/sdl/CMakeLists.txt index 66dfeb99..e445eb72 100644 --- a/src/sdl/CMakeLists.txt +++ b/src/sdl/CMakeLists.txt @@ -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,14 +79,36 @@ if(${SDL2_FOUND}) ) endif() - add_executable(${SRB2_SDL2_EXE_NAME} WIN32 ${SRB2_SDL2_TOTAL_SOURCES}) + 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() - target_link_libraries(${SRB2_SDL2_EXE_NAME} PRIVATE - ${SDL2_LIBRARIES} - ${PNG_LIBRARIES} - ${ZLIB_LIBRARIES} - ${OPENGL_LIBRARIES} - ) + 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 + ${SDL2_LIBRARIES} + ${PNG_LIBRARIES} + ${ZLIB_LIBRARIES} + ${OPENGL_LIBRARIES} + ) + + endif() if(${CMAKE_SYSTEM} MATCHES Windows) target_link_libraries(${SRB2_SDL2_EXE_NAME} PRIVATE