cmake_minimum_required(VERSION 3.10)
project(retroarch-activity LANGUAGES C CXX)

option(HAVE_NEON "Enable NEON" ON)
option(HAVE_FILE_LOGGER "Enable File Logger" ON)

# 添加可执行文件或库
add_library(retroarch-activity SHARED
        ${CMAKE_SOURCE_DIR}/griffin/griffin.c
        ${CMAKE_SOURCE_DIR}/griffin/griffin_cpp.cpp)

# 添加定义
execute_process(
        COMMAND git rev-parse --short HEAD
        RESULT_VARIABLE GIT_RESULT
        OUTPUT_VARIABLE GIT_VERSION
        OUTPUT_STRIP_TRAILING_WHITESPACE
)

if (GIT_RESULT EQUAL 0)
    target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_GIT_VERSION GIT_VERSION="${GIT_VERSION}")
endif ()

target_link_libraries(${PROJECT_NAME} PRIVATE GLESv2)
target_compile_definitions(${PROJECT_NAME} PRIVATE HAVE_OPENGLES2)

target_compile_definitions(${PROJECT_NAME} PRIVATE
        RARCH_MOBILE
        HAVE_GRIFFIN
        # HAVE_STB_VORBIS
        ANDROID
        HAVE_DYNAMIC
        HAVE_OPENGL
        # HAVE_OVERLAY
        HAVE_OPENGLES
        # GLSL_DEBUG
        HAVE_DYLIB
        HAVE_EGL
        HAVE_GLSL
        # HAVE_MENU
        HAVE_CONFIGFILE
        HAVE_PATCH
        HAVE_DSP_FILTER
        HAVE_VIDEO_FILTER
        HAVE_SCREENSHOTS
        HAVE_REWIND
        # HAVE_CHEATS
        # HAVE_RGUI
        HAVE_ZLIB
        HAVE_NO_BUILTINZLIB
        HAVE_RPNG
        HAVE_RJPEG
        HAVE_RBMP
        HAVE_RTGA
        INLINE=inline
        HAVE_THREADS
        __LIBRETRO__
        HAVE_RSOUND
        # HAVE_NETWORKGAMEPAD
        # HAVE_NETWORKING
        # HAVE_IFINFO
        # HAVE_NETPLAYDISCOVERY
        RARCH_INTERNAL
        HAVE_FILTERS_BUILTIN
        # HAVE_MATERIALUI
        # HAVE_XMB
        # HAVE_OZONE
        # HAVE_SHADERPIPELINE
        # HAVE_LIBRETRODB
        # HAVE_STB_FONT
        HAVE_IMAGEVIEWER
        # HAVE_ONLINE_UPDATER
        # HAVE_UPDATE_ASSETS
        # HAVE_UPDATE_CORES
        # HAVE_UPDATE_CORE_INFO
        HAVE_CC_RESAMPLER
        HAVE_KEYMAPPER
        # HAVE_NETWORKGAMEPAD
        HAVE_FLAC
        # HAVE_DR_FLAC
        # HAVE_DR_MP3
        HAVE_CHD
        WANT_SUBCODE
        WANT_RAW_DATA_SECTOR
        HAVE_RUNAHEAD
        ENABLE_HLSL
        # HAVE_AUDIOMIXER
        # HAVE_RWAV
        # WANT_IFADDRS
        HAVE_CORE_INFO_CACHE)

target_compile_definitions(${PROJECT_NAME} PRIVATE
        HAVE_7ZIP
        _7ZIP_ST
        HAVE_SL)

target_compile_definitions(${PROJECT_NAME} PRIVATE
        FLAC_PACKAGE_VERSION="retroarch"
        HAVE_LROUND
        FLAC__HAS_OGG=0)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -std=gnu99 -pthread -Wno-unused-function -fno-stack-protector -funroll-loops")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions -fpermissive -std=gnu++11 -fno-rtti -Wno-reorder")

target_link_libraries(${PROJECT_NAME} PRIVATE android EGL log dl)
target_include_directories(${PROJECT_NAME} PRIVATE
        libretro-common/include
        deps
        deps/stb
        deps/7zip
        deps/libFLAC/include)

target_link_libraries(${PROJECT_NAME} PRIVATE OpenSLES z)

if (SAMOTOZER)
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -fsanitize=$(SANITIZER) -fno-omit-frame-pointer -Wmissing-braces")
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -fsanitize=$(SANITIZER) -fno-omit-frame-pointer")

    target_link_options(${PROJECT_NAME} PRIVATE -fsanitize=${SANITIZER})
endif ()

