cmake_minimum_required(VERSION 3.22)
project(royal_stockfish LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
file(GLOB STOCKFISH_SOURCES CONFIGURE_DEPENDS src/*.cpp src/nnue/*.cpp src/nnue/features/*.cpp src/syzygy/*.cpp)
add_executable(stockfish ${STOCKFISH_SOURCES})
set_target_properties(stockfish PROPERTIES OUTPUT_NAME libstockfish.so)
target_compile_definitions(stockfish PRIVATE NDEBUG USE_PREFETCH)
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
    target_compile_definitions(stockfish PRIVATE IS_64BIT)
endif()
target_compile_options(stockfish PRIVATE -O3 "-Wa,-I${STOCKFISH_NET_DIR}")
target_link_options(stockfish PRIVATE "-Wl,-z,max-page-size=16384")
if(ANDROID_ABI STREQUAL "arm64-v8a")
    target_compile_definitions(stockfish PRIVATE USE_NEON=8 USE_POPCNT)
elseif(ANDROID_ABI STREQUAL "armeabi-v7a")
    target_compile_definitions(stockfish PRIVATE USE_NEON=7 USE_POPCNT)
    target_compile_options(stockfish PRIVATE -mfpu=neon)
elseif(ANDROID_ABI STREQUAL "x86_64" OR ANDROID_ABI STREQUAL "x86")
    target_compile_definitions(stockfish PRIVATE USE_SSE2)
    target_compile_options(stockfish PRIVATE -msse2)
else()
    message(FATAL_ERROR "Unsupported Android ABI: ${ANDROID_ABI}")
endif()
