Skip to content

Commit

Permalink
Merge pull request #1137 from ivan-mogilko/ags3--sdl2
Browse files Browse the repository at this point in the history
SDL2 Port
  • Loading branch information
ivan-mogilko authored Dec 2, 2020
2 parents a52e537 + b4708c9 commit d4b4ec4
Show file tree
Hide file tree
Showing 377 changed files with 32,838 additions and 43,346 deletions.
30 changes: 30 additions & 0 deletions CMake/FetchSDL2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FetchContent_Declare(
sdl2_content
URL https://www.libsdl.org/release/SDL2-2.0.12.tar.gz
URL_HASH MD5=783b6f2df8ff02b19bb5ce492b99c8ff
)

FetchContent_GetProperties(sdl2_content)
if(NOT sdl2_content_POPULATED)
FetchContent_Populate(sdl2_content)
if(ANDROID)
set(SDL_SHARED ON CACHE BOOL "shared")
set(SDL_STATIC ON CACHE BOOL "static")
add_subdirectory(${sdl2_content_SOURCE_DIR} ${sdl2_content_BINARY_DIR} EXCLUDE_FROM_ALL)
add_library(SDL2::SDL2 ALIAS SDL2)
add_library(SDL2::SDL2main ALIAS SDL2main)
elseif(WIN32 OR LINUX OR MACOS)
set(SDL_SHARED OFF CACHE BOOL "no shared")
set(SDL_STATIC ON CACHE BOOL "static")
set(SDL_STATIC_PIC ON CACHE BOOL "Static version of the library should be built with Position Independent Code")
set(SDL_SHARED OFF)
set(SDL_STATIC ON)
set(SDL_STATIC_PIC ON)
set(FORCE_STATIC_VCRT ON CACHE BOOL "static windows static vcrc")
add_subdirectory(${sdl2_content_SOURCE_DIR} ${sdl2_content_BINARY_DIR} EXCLUDE_FROM_ALL)
add_library(SDL2::SDL2 ALIAS SDL2-static)
add_library(SDL2::SDL2main ALIAS SDL2main)
endif()
endif()


20 changes: 20 additions & 0 deletions CMake/FetchSDL_Sound.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FetchContent_Declare(
sdlsound_content
URL https://hg.icculus.org/icculus/SDL_sound/archive/9262f9205898.tar.gz
URL_HASH MD5=64ece3216dcc4877378e6f03064f51ca
)

FetchContent_GetProperties(sdlsound_content)
if(NOT sdlsound_content)
FetchContent_Populate(sdlsound_content)

set(SDLSOUND_BUILD_SHARED off CACHE BOOL "no shared")
set(SDLSOUND_BUILD_TEST off CACHE BOOL "no tests")
set(SDLSOUND_BUILD_STATIC on CACHE BOOL "static")
file(COPY CMake/SDL_Sound/CMakeLists.txt DESTINATION ${sdlsound_content_SOURCE_DIR})
add_subdirectory(${sdlsound_content_SOURCE_DIR} ${sdlsound_content_BINARY_DIR} EXCLUDE_FROM_ALL)
include_directories(${sdlsound_content_SOURCE_DIR}/src/)
add_library(sdl2_sound-interface INTERFACE)
target_link_libraries(sdl2_sound-interface INTERFACE SDL2_sound-static)
add_library(SDL2_sound::SDL2_sound ALIAS sdl2_sound-interface)
endif()
10 changes: 10 additions & 0 deletions CMake/FindLocalAllegro.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
add_subdirectory(libsrc/allegro EXCLUDE_FROM_ALL)
target_compile_definitions (allegro
INTERFACE
ALLEGRO_STATICLINK
ALLEGRO_NO_COMPATIBILITY
ALLEGRO_NO_FIX_ALIASES
ALLEGRO_NO_FIX_CLASS
ALLEGRO_NO_KEY_DEFINES
)
add_library(Allegro::Allegro ALIAS allegro)
16 changes: 16 additions & 0 deletions CMake/FindLocalOpenAL.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Grab system openAL or use embedded mojoAL

find_package(OpenAL)

if (OPENAL_FOUND)
add_library(openal-interface INTERFACE)
target_link_libraries(openal-interface INTERFACE ${OPENAL_LIBRARY})
target_include_directories(openal-interface INTERFACE ${OPENAL_INCLUDE_DIR})
add_library(External::OpenAL ALIAS openal-interface)
else()
add_subdirectory(libsrc/mojoAL EXCLUDE_FROM_ALL)

add_library(openal-interface INTERFACE)
target_link_libraries(openal-interface INTERFACE MojoAL::MojoAL)
add_library(External::OpenAL ALIAS openal-interface)
endif()
239 changes: 239 additions & 0 deletions CMake/SDL_Sound/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
# SDL_sound; An abstract sound format decoding API.
#
# Please see the file LICENSE.txt in the source's root directory.

cmake_minimum_required(VERSION 2.8.4)

project(SDL_sound)
set(SDLSOUND_VERSION 1.9.0)

# Increment this if/when we break backwards compatibility.
set(SDLSOUND_SOVERSION 1)

# I hate that they define "WIN32" ... we're about to move to Win64...I hope!
if(WIN32 AND NOT WINDOWS)
set(WINDOWS TRUE)
endif()

include_directories(src)

if(CMAKE_COMPILER_IS_GNUCC)
# Don't use -rpath.
set(CMAKE_SKIP_RPATH ON CACHE BOOL "Skip RPATH" FORCE)
endif()

if(CMAKE_C_COMPILER_ID STREQUAL "SunPro")
add_definitions(-erroff=E_EMPTY_TRANSLATION_UNIT)
add_definitions(-xldscope=hidden)
endif()

find_package(SDL2 REQUIRED)
include_directories(${SDL2_INCLUDE_DIRS})


# Decoders ...
# These are (mostly) on by default now, so these options are only useful for
# disabling them.

macro(sdlsound_decoder_option _VAR _NAME _EXTS)
option(SDLSOUND_DECODER_${_VAR} "Enable ${_NAME} support (${_EXTS})" TRUE)
if(NOT SDLSOUND_DECODER_${_VAR})
add_definitions("-DSOUND_SUPPORTS_${_VAR}=0")
endif()
endmacro()

sdlsound_decoder_option(WAV "Wave" ".WAV")
sdlsound_decoder_option(AIFF "Audio Interchange" ".AIFF")
sdlsound_decoder_option(AU "Sun/NeXT audio" ".AU")
sdlsound_decoder_option(VOC "Creative Labs voice" ".VOC")
sdlsound_decoder_option(FLAC "Free Lossless Audio Codec" ".FLAC")
sdlsound_decoder_option(VORBIS "Ogg Vorbis" ".OGG")
sdlsound_decoder_option(RAW "raw PCM audio" ".RAW")
sdlsound_decoder_option(SHN "Shorten" ".SHN")
sdlsound_decoder_option(MODPLUG "ModPlug" "various tracker formats")
sdlsound_decoder_option(MP3 "MPEG-1 Layers I-III" ".MP3, .MP2, .MP1")

if(APPLE)
sdlsound_decoder_option(COREAUDIO "CoreAudio" "various audio formats")
if(SDLSOUND_DECODER_COREAUDIO)
set(OPTIONAL_LIBRARY_LIBS ${OPTIONAL_LIBRARY_LIBS} "-framework AudioToolbox")
endif()
endif()

if(SDLSOUND_DECODER_MODPLUG)
set(LIBMODPLUG_SRCS
src/libmodplug/fastmix.c
src/libmodplug/load_669.c
src/libmodplug/load_abc.c
src/libmodplug/load_amf.c
src/libmodplug/load_ams.c
src/libmodplug/load_dbm.c
src/libmodplug/load_dmf.c
src/libmodplug/load_dsm.c
src/libmodplug/load_far.c
src/libmodplug/load_it.c
src/libmodplug/load_mdl.c
src/libmodplug/load_med.c
src/libmodplug/load_mid.c
src/libmodplug/load_mod.c
src/libmodplug/load_mt2.c
src/libmodplug/load_mtm.c
src/libmodplug/load_okt.c
src/libmodplug/load_pat.c
src/libmodplug/load_psm.c
src/libmodplug/load_ptm.c
src/libmodplug/load_s3m.c
src/libmodplug/load_stm.c
src/libmodplug/load_ult.c
src/libmodplug/load_umx.c
src/libmodplug/load_xm.c
src/libmodplug/mmcmp.c
src/libmodplug/modplug.c
src/libmodplug/snd_dsp.c
src/libmodplug/snd_flt.c
src/libmodplug/snd_fx.c
src/libmodplug/sndfile.c
src/libmodplug/sndmix.c
)
endif()

# Almost everything is "compiled" here, but things that don't apply to the
# build are #ifdef'd out. This is to make it easy to embed SDL_sound into
# another project or bring up a new build system: just compile all the source
# code and #define the things you want.
set(SDLSOUND_SRCS
src/SDL_sound.c
src/SDL_sound_aiff.c
src/SDL_sound_au.c
src/SDL_sound_coreaudio.c
src/SDL_sound_flac.c
src/SDL_sound_modplug.c
src/SDL_sound_mp3.c
src/SDL_sound_raw.c
src/SDL_sound_shn.c
src/SDL_sound_voc.c
src/SDL_sound_vorbis.c
src/SDL_sound_wav.c
${LIBMODPLUG_SRCS}
)

option(SDLSOUND_BUILD_STATIC "Build static library" TRUE)
if(SDLSOUND_BUILD_STATIC)
add_library(SDL2_sound-static STATIC ${SDLSOUND_SRCS})
# Don't rename this on Windows, since DLLs will also produce an import
# library named "SDL2_sound.lib" which would conflict; Unix tend to like
# the same library name with a different extension for static libs, but
# Windows can just have a separate name.
if(NOT MSVC)
set_target_properties(SDL2_sound-static PROPERTIES OUTPUT_NAME "SDL2_sound")
endif()
set(SDLSOUND_LIB_TARGET SDL2_sound-static)
set(SDLSOUND_INSTALL_TARGETS ${SDLSOUND_INSTALL_TARGETS} ";SDL2_sound-static")
endif()

option(SDLSOUND_BUILD_SHARED "Build shared library" TRUE)
if(SDLSOUND_BUILD_SHARED)
add_library(SDL2_sound SHARED ${SDLSOUND_SRCS})
set_target_properties(SDL2_sound PROPERTIES MACOSX_RPATH 1)
set_target_properties(SDL2_sound PROPERTIES VERSION ${SDLSOUND_VERSION})
set_target_properties(SDL2_sound PROPERTIES SOVERSION ${SDLSOUND_SOVERSION})
target_link_libraries(SDL2_sound ${SDL2_LIBRARIES} ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS})
set(SDLSOUND_LIB_TARGET SDL2_sound)
set(SDLSOUND_INSTALL_TARGETS ${SDLSOUND_INSTALL_TARGETS} ";SDL2_sound")
endif()

if(NOT SDLSOUND_BUILD_SHARED AND NOT SDLSOUND_BUILD_STATIC)
message(FATAL "Both shared and static libraries are disabled!")
endif()

# CMake FAQ says I need this...
if(SDLSOUND_BUILD_SHARED AND SDLSOUND_BUILD_STATIC AND NOT WINDOWS)
set_target_properties(SDL2_sound PROPERTIES CLEAN_DIRECT_OUTPUT 1)
set_target_properties(SDL2_sound-static PROPERTIES CLEAN_DIRECT_OUTPUT 1)
endif()

option(SDLSOUND_BUILD_TEST "Build stdio test program." TRUE)
mark_as_advanced(SDLSOUND_BUILD_TEST)
if(SDLSOUND_BUILD_TEST)
add_executable(playsound playsound/playsound.c)
target_link_libraries(playsound ${SDLSOUND_LIB_TARGET} ${OTHER_LDFLAGS})
set(SDLSOUND_INSTALL_TARGETS ${SDLSOUND_INSTALL_TARGETS} ";playsound")
add_executable(playsound_simple playsound/playsound_simple.c)
target_link_libraries(playsound_simple ${SDLSOUND_LIB_TARGET} ${OTHER_LDFLAGS})
#set(SDLSOUND_INSTALL_TARGETS ${SDLSOUND_INSTALL_TARGETS} ";playsound_simple")
if(NOT SDLSOUND_BUILD_SHARED)
target_link_libraries(playsound ${SDL2_LIBRARIES} ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS})
target_link_libraries(playsound_simple ${SDL2_LIBRARIES} ${OPTIONAL_LIBRARY_LIBS} ${OTHER_LDFLAGS})
endif()
endif()

install(TARGETS ${SDLSOUND_INSTALL_TARGETS}
RUNTIME DESTINATION bin
LIBRARY DESTINATION lib${LIB_SUFFIX}
ARCHIVE DESTINATION lib${LIB_SUFFIX})
install(FILES SDL_sound.h DESTINATION include)

find_package(Doxygen)
if(DOXYGEN_FOUND)
set(SDLSOUND_OUTPUT_DOXYFILE "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile")
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile"
"${SDLSOUND_OUTPUT_DOXYFILE}"
COPYONLY
)
file(APPEND "${SDLSOUND_OUTPUT_DOXYFILE}" "\n\n# Below auto-generated by cmake...\n\n")
file(APPEND "${SDLSOUND_OUTPUT_DOXYFILE}" "PROJECT_NUMBER = \"${SDLSOUND_VERSION}\"\n")
file(APPEND "${SDLSOUND_OUTPUT_DOXYFILE}" "OUTPUT_DIRECTORY = \"${CMAKE_CURRENT_BINARY_DIR}/docs\"\n")
file(APPEND "${SDLSOUND_OUTPUT_DOXYFILE}" "\n# End auto-generated section.\n\n")

add_custom_target(
docs
${DOXYGEN_EXECUTABLE} "${SDLSOUND_OUTPUT_DOXYFILE}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "Building documentation..."
)
else()
message(STATUS "Doxygen not found. You won't be able to build documentation.")
endif()

if(UNIX)
set(SDLSOUND_TARBALL "${CMAKE_CURRENT_SOURCE_DIR}/../SDL_sound-${SDLSOUND_VERSION}.tar.bz2")
add_custom_target(
SDL_Sound_dist
hg archive -t tbz2 "${SDLSOUND_TARBALL}"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "Building source tarball '${SDLSOUND_TARBALL}'..."
)
add_custom_target(
SDL_Sound_uninstall
"${CMAKE_CURRENT_SOURCE_DIR}/docs/uninstall.sh"
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
COMMENT "Uninstall the project..."
)
endif()

macro(message_bool_option _NAME _VALUE)
if(${_VALUE})
message(STATUS " ${_NAME}: enabled")
else()
message(STATUS " ${_NAME}: disabled")
endif()
endmacro()

message(STATUS "SDL_sound will build with the following options:")
message_bool_option("WAV support" SDLSOUND_DECODER_WAV)
message_bool_option("AIFF support" SDLSOUND_DECODER_AIFF)
message_bool_option("AU support" SDLSOUND_DECODER_AU)
message_bool_option("VOC support" SDLSOUND_DECODER_VOC)
message_bool_option("FLAC support" SDLSOUND_DECODER_FLAC)
message_bool_option("VORBIS support" SDLSOUND_DECODER_VORBIS)
message_bool_option("RAW support" SDLSOUND_DECODER_RAW)
message_bool_option("SHN support" SDLSOUND_DECODER_SHN)
message_bool_option("MODPLUG support" SDLSOUND_DECODER_MODPLUG)
message_bool_option("MP3 support" SDLSOUND_DECODER_MP3)
message_bool_option("COREAUDIO support" SDLSOUND_DECODER_COREAUDIO)
message_bool_option("Build static library" SDLSOUND_BUILD_STATIC)
message_bool_option("Build shared library" SDLSOUND_BUILD_SHARED)
message_bool_option("Build stdio test program" SDLSOUND_BUILD_TEST)

# end of CMakeLists.txt ...
36 changes: 31 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@ option(AGS_NO_VIDEO_PLAYER "Disable Video" OFF)
option(AGS_BUILTIN_PLUGINS "Built in plugins" OFF)
set(AGS_BUILD_STR "" CACHE STRING "Engine Build Information")

# Tools like ninja don't have a pseudo-terminal so compilers assume no coloured output
option (AGS_FORCE_COLOURED_OUTPUT "Always produce ANSI-coloured output (GNU/Clang only)." OFF)
if (${AGS_FORCE_COLOURED_OUTPUT})
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_compile_options (-fdiagnostics-color=always)
elseif ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
add_compile_options (-fcolor-diagnostics)
endif ()
endif ()

include(FetchContent)
set(FETCHCONTENT_UPDATES_DISCONNECTED on)

Expand All @@ -28,10 +38,25 @@ else()
message(FATAL_ERROR "Unsupported system: ${CMAKE_SYSTEM_NAME}")
endif ()

message( "CMAKE_SYSTEM_NAME:" ${CMAKE_SYSTEM_NAME} )
message( "WIN32:" ${WIN32} )
message( "LINUX:" ${LINUX} )
message( "MACOS:" ${MACOS} )

if (WIN32 AND NOT CMAKE_SIZEOF_VOID_P EQUAL 4)
message(FATAL_ERROR "Windows builds only support 32bit for now")
endif()

if(LINUX)
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
if (CMAKE_COMPILER_IS_GNUCC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 9.0)
# without no-pie we can't double-click run ags in Nautilus
# this should only be needed in newer gcc versions
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fno-pie -no-pie")
endif ()
endif ()
endif (LINUX)


include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_supported OUTPUT ipo_not_supported_reason)
Expand Down Expand Up @@ -111,7 +136,12 @@ elseif (LINUX)
find_package(X11)
endif()

include(FetchAllegro)
include(FetchSDL2)
include(FetchSDL_Sound)

include(FindLocalOpenAL)
include(FindLocalAllegro)

include(FetchOgg)
include(FetchVorbis)
include(FetchTheora)
Expand All @@ -121,12 +151,8 @@ add_subdirectory(Common/libsrc/alfont-2.0.9 EXCLUDE_FROM_ALL)
add_subdirectory(Common/libsrc/freetype-2.1.3 EXCLUDE_FROM_ALL)
add_subdirectory(Common EXCLUDE_FROM_ALL)

add_subdirectory(Engine/libsrc/almp3-2.0.5 EXCLUDE_FROM_ALL)
add_subdirectory(Engine/libsrc/alogg EXCLUDE_FROM_ALL)
add_subdirectory(Engine/libsrc/apeg-1.2.1 EXCLUDE_FROM_ALL)
add_subdirectory(Engine/libsrc/dumb-0.9.2 EXCLUDE_FROM_ALL)
add_subdirectory(Engine/libsrc/glad EXCLUDE_FROM_ALL)
add_subdirectory(Engine/libsrc/hq2x EXCLUDE_FROM_ALL)
add_subdirectory(Engine/libsrc/libcda-0.5 EXCLUDE_FROM_ALL)

add_subdirectory(Engine)
Expand Down
Loading

0 comments on commit d4b4ec4

Please sign in to comment.