@@ -32,6 +32,8 @@ if(AUDIO_BACKEND STREQUAL "")
3232 set (AUDIO_BACKEND "openal" )
3333 elseif (PLATFORM STREQUAL "ps2" )
3434 set (AUDIO_BACKEND "ps2" )
35+ elseif (PLATFORM STREQUAL "libretro" )
36+ set (AUDIO_BACKEND "none" )
3537 else ()
3638 set (AUDIO_BACKEND "miniaudio" )
3739 endif ()
@@ -95,7 +97,11 @@ if (ENABLE_GLES AND ENABLE_LEGACY_GL)
9597 set (ENABLE_LEGACY_GL OFF )
9698endif ()
9799
98- add_executable (butterscotch ${SOURCES} ${PLATFORM_SOURCES} ${AUDIO_SOURCES} )
100+ if (PLATFORM STREQUAL "libretro" )
101+ add_library (butterscotch MODULE ${SOURCES} ${PLATFORM_SOURCES} ${AUDIO_SOURCES} )
102+ else ()
103+ add_executable (butterscotch ${SOURCES} ${PLATFORM_SOURCES} ${AUDIO_SOURCES} )
104+ endif ()
99105target_include_directories (butterscotch PRIVATE ${CMAKE_SOURCE_DIR } /src )
100106
101107if (AUDIO_BACKEND STREQUAL "openal" )
@@ -586,6 +592,44 @@ elseif(PLATFORM STREQUAL "ps3")
586592 find_package (SDL2 REQUIRED )
587593 target_include_directories (butterscotch PRIVATE ${SDL2_INCLUDE_DIRS} )
588594 target_link_libraries (butterscotch PRIVATE ${SDL2_LIBRARIES} m gcm_sys rsx sysutil io audio rt lv2 io audio bzip2 )
595+ elseif (PLATFORM STREQUAL "libretro" )
596+ # bzip2 needs -fPIC for linking into shared library
597+ set_target_properties (bzip2 PROPERTIES POSITION_INDEPENDENT_CODE ON )
598+
599+ # SW renderer, image decoder, stb image loader
600+ target_sources (butterscotch PRIVATE
601+ src/sw/sw_renderer.c
602+ src/image/image_decoder.c
603+ src/desktop/stb_impl.c
604+ )
605+ target_include_directories (butterscotch PRIVATE
606+ ${CMAKE_SOURCE_DIR } /src/sw
607+ ${CMAKE_SOURCE_DIR } /src/image
608+ ${CMAKE_SOURCE_DIR } /src/desktop
609+ ${CMAKE_SOURCE_DIR } /src/libretro
610+ vendor/stb/image
611+ )
612+
613+ # Rename output to butterscotch_libretro.so
614+ set_target_properties (butterscotch PROPERTIES
615+ PREFIX ""
616+ OUTPUT_NAME "butterscotch_libretro"
617+ )
618+
619+ # Version script for symbol visibility
620+ target_link_options (butterscotch PRIVATE
621+ -Wl,--version-script=${CMAKE_SOURCE_DIR}/src/libretro/link.T
622+ -Wl,--no-undefined
623+ )
624+
625+ # Libraries
626+ find_library (DL_LIB dl )
627+ target_link_libraries (butterscotch PRIVATE bzip2 m ${DL_LIB} )
628+
629+ target_compile_definitions (butterscotch PRIVATE
630+ _GNU_SOURCE
631+ _FILE_OFFSET_BITS=64
632+ )
589633else ()
590634 message (FATAL_ERROR "Unknown platform! ${PLATFORM} " )
591635endif ()
0 commit comments