cmake_minimum_required(VERSION 3.10)

project(puzzle15)

option(ENABLE_ASAN "Enable AddressSanitizer" OFF)
option(ENABLE_TSAN "Enable ThreadSanitizer" OFF)
option(ENABLE_UBSAN "Enable UndefinedBehaviorSanitizer" OFF)
option(ENABLE_MSAN "Enable MemorySanitizer" OFF)

if(ENABLE_ASAN)
    message(STATUS "AddressSanitizer enabled")
    add_compile_options(-fsanitize=address -fno-omit-frame-pointer)
    add_link_options(-fsanitize=address)
endif()

if(ENABLE_TSAN)
    message(STATUS "ThreadSanitizer enabled")
    add_compile_options(-fsanitize=thread -fno-omit-frame-pointer)
    add_link_options(-fsanitize=thread)
endif()

if(ENABLE_UBSAN)
    message(STATUS "UndefinedBehaviorSanitizer enabled")
    add_compile_options(-fsanitize=undefined -fno-omit-frame-pointer)
    add_link_options(-fsanitize=undefined)
endif()

if(ENABLE_MSAN)
    message(STATUS "MemorySanitizer enabled")
    add_compile_options(-fsanitize=memory -fno-omit-frame-pointer)
    add_link_options(-fsanitize=memory)
endif()

# Warn if multiple sanitizers are enabled (most are incompatible)
set(SANITIZER_COUNT 0)
foreach(san ASAN TSAN MSAN)
    if(ENABLE_${san})
        math(EXPR SANITIZER_COUNT "${SANITIZER_COUNT} + 1")
    endif()
endforeach()
if(SANITIZER_COUNT GREATER 1)
    message(WARNING "Multiple sanitizers enabled - they may be incompatible!")
endif()

find_package(SDL3 REQUIRED)
find_package(SDL3_image REQUIRED)
find_package(SDL3_ttf REQUIRED)
find_package(SDL3_mixer REQUIRED)


add_subdirectory(../source/ build-puzzle15)

#add_subdirectory(../ build-puzzle15)


# install
include(GNUInstallDirs)
install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/build-puzzle15/puzzle15
        DESTINATION ${CMAKE_INSTALL_BINDIR}
)

install(FILES ../pkg/puzzle15.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)
install(FILES ../pkg/puzzle15.png DESTINATION ${CMAKE_INSTALL_DATADIR}/pixmaps)

install(DIRECTORY ../assets
        DESTINATION ${CMAKE_INSTALL_DATADIR}/puzzle15
)


