cmake_minimum_required(VERSION 3.12)
project(Pacman)

set(CMAKE_CXX_STANDARD 17)

file(GLOB_RECURSE SOURCES source/*.cpp)

set(SFML_STATIC_LIBRARIES TRUE)
set(BUILD_SHARED_LIBS FALSE)

include(FetchContent)
FetchContent_Declare(SFML GIT_REPOSITORY https://github.com/SFML/SFML.git GIT_TAG 2.6.1)
FetchContent_MakeAvailable(SFML)

if (APPLE AND CMAKE_BUILD_TYPE STREQUAL "Release")
    set(MACOSX_BUNDLE TRUE)
    set(MACOSX_BUNDLE_BUNDLE_NAME "Pacman")
    set(MACOSX_BUNDLE_GUI_IDENTIFIER "dpechenin")
    set(MACOSX_BUNDLE_BUNDLE_VERSION "1.0")
    set(MACOSX_BUNDLE_SHORT_VERSION_STRING "1.0")
    add_executable(PACMAN_MAC_OS_APP MACOSX_BUNDLE ${SOURCES})
endif()

add_executable(PACMAN ${SOURCES})

target_include_directories(PACMAN PUBLIC ${CMAKE_SOURCE_DIR}/source)
target_compile_definitions(PACMAN PUBLIC ASSETS_PATH="${CMAKE_CURRENT_SOURCE_DIR}/assets/")

target_link_libraries(PACMAN PRIVATE sfml-system sfml-window sfml-graphics)

set_target_properties(PACMAN PROPERTIES OUTPUT_NAME "Pacman")

if (APPLE AND CMAKE_BUILD_TYPE STREQUAL "Release")
    target_include_directories(PACMAN_MAC_OS_APP PUBLIC ${CMAKE_SOURCE_DIR}/source)
    target_compile_definitions(PACMAN_MAC_OS_APP PUBLIC ASSETS_PATH="${CMAKE_CURRENT_SOURCE_DIR}/assets/")

    target_link_libraries(PACMAN_MAC_OS_APP PRIVATE sfml-system sfml-window sfml-graphics)

    set_target_properties(PACMAN_MAC_OS_APP PROPERTIES OUTPUT_NAME "Pacman")

    set_source_files_properties(assets/icon.icns PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
    target_sources(PACMAN_MAC_OS_APP PRIVATE assets/icon.icns)
endif()