cmake_minimum_required(VERSION 3.10) # Stockfish as a program of its own, for Android. # # The application starts this as a separate process and talks to it in UCI over # its standard input and output, as it does with a Stockfish binary on Windows. # Nothing built here is linked into the application, and the application loads # nothing from it. # # An executable cannot go into an APK under its own name: the packager takes # only files called lib*.so from the native output folder, and the installer # extracts only those into the one directory an app may start a program from. # So the program is given that name. It is still an executable — a # position-independent one with its own `main` — and not a shared library. project(stockfish_engine CXX) # 16 KB page size support (required by Google Play). add_link_options(-Wl,-z,max-page-size=16384) add_link_options(-Wl,-z,common-page-size=16384) file(GLOB_RECURSE cppPaths "../src/*.cpp") # Stockfish 19's universal/ holds the entry points of its multi-arch release # binaries (one main per CPU slice, and a second copy of the network). Upstream # compiles them only for the *-universal targets, never for plain armv8. list(FILTER cppPaths EXCLUDE REGEX "/universal/") add_executable(stockfish ${cppPaths}) set_target_properties(stockfish PROPERTIES OUTPUT_NAME "libstockfish" SUFFIX ".so") # The Android build collects what it packages from the library output folder; # an executable would otherwise be written beside it and left out. if(CMAKE_LIBRARY_OUTPUT_DIRECTORY) set_target_properties(stockfish PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}") endif() if(ANDROID_ABI STREQUAL arm64-v8a) if (CMAKE_BUILD_TYPE STREQUAL "Debug") target_compile_options(stockfish PRIVATE -DUSE_PTHREADS -DIS_64BIT -DUSE_POPCNT -DUSE_NEON=8) else() target_compile_options(stockfish PRIVATE -fno-exceptions -DUSE_PTHREADS -DNDEBUG -O3 -DIS_64BIT -DUSE_POPCNT -DUSE_NEON=8) endif() else() if (CMAKE_BUILD_TYPE STREQUAL "Debug") target_compile_options(stockfish PRIVATE -DUSE_PTHREADS) else() target_compile_options(stockfish PRIVATE -fno-exceptions -DUSE_PTHREADS -DNDEBUG -O3) endif() endif() # Stockfish 19 has one network (EvalFileDefaultName in src/evaluate.h); the # big/small pair of 16.1-18 is gone. The hash is the file's own SHA-256 prefix, # so a truncated or substituted download fails the build instead of embedding. file(DOWNLOAD https://tests.stockfishchess.org/api/nn/nn-1a298aa575a0.nnue ${CMAKE_BINARY_DIR}/nn-1a298aa575a0.nnue EXPECTED_HASH SHA256=1a298aa575a085434d29027978dc36867fe9c5bcea9376654b7a8eba1e52dfc2)