cmake_minimum_required(VERSION 3.16)
project(totk_lsfg LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
option(TOTK_LSFG_HOST_TEST "Native-image host test; no AHB or external semaphore required" OFF)
file(GLOB CORE CONFIGURE_DEPENDS framegen/src/common/*.cpp framegen/src/core/*.cpp framegen/src/pool/*.cpp
    framegen/v3.1_src/*.cpp framegen/v3.1_src/shaders/*.cpp)
file(GLOB DXBC CONFIGURE_DEPENDS third_party/dxbc/src/dxbc/*.cpp third_party/dxbc/src/spirv/*.cpp third_party/dxbc/src/util/*.cpp)
add_library(lsfg_backend STATIC ${CORE} ${DXBC} third_party/volk/volk.c shaders.cpp extract/trans.cpp
    third_party/pe-parse/src/buffer.cpp third_party/pe-parse/src/parse.cpp third_party/pe-parse/src/unicode_codecvt.cpp)
target_include_directories(lsfg_backend PUBLIC . framegen/include framegen/public framegen/v3.1_include
    third_party/volk third_party/pe-parse/include third_party/dxbc/include/dxbc
    third_party/dxbc/include/spirv third_party/dxbc/include/util third_party/dxbc/include/dxvk)
target_compile_options(lsfg_backend PRIVATE -Wno-deprecated-declarations)
target_link_libraries(lsfg_backend PUBLIC ${CMAKE_DL_LIBS})
if(ANDROID)
    target_compile_definitions(lsfg_backend PUBLIC VK_USE_PLATFORM_ANDROID_KHR)
    add_library(totk_lsfg SHARED library.cpp)
    target_link_libraries(totk_lsfg PRIVATE lsfg_backend android)
    target_link_options(totk_lsfg PRIVATE -Wl,-Bsymbolic -Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/exports.map -Wl,--no-undefined)
elseif(TOTK_LSFG_HOST_TEST)
    target_compile_definitions(lsfg_backend PUBLIC TOTK_LSFG_HOST_TEST)
    add_executable(lsfgtest ../../../../../tests/test_lsfg.cpp library.cpp)
    target_link_libraries(lsfgtest PRIVATE lsfg_backend)
endif()
