cmake_minimum_required(VERSION 3.14)
project(BeagleRescue VERSION 1.0.0 )

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_REQUIRED ON)

include(FetchContent)
include(FindPkgConfig)

PKG_SEARCH_MODULE(SDL2 REQUIRED sdl2)
PKG_SEARCH_MODULE(SDL2IMAGE REQUIRED SDL2_image>=2.0.0)
PKG_SEARCH_MODULE(SDL2MIXER REQUIRED SDL2_mixer>=2.0.0)

# Point to our own cmake modules
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/sdl2)

# Find SDL2
# find_package(SDL2 REQUIRED)
#find_file(SDL2_INCLUDE_DIR NAME SDL.h HINTS SDL2)
#find_library(SDL2_LIBRARY NAME SDL2)
#find_package(SDL2_image REQUIRED)
#find_package(SDL2_mixer REQUIRED)

#add_subdirectory(libtmx-parser)
#add_library(libtmx-parser)
#       target_sources(libtmx-parser
#       PRIVATE
#                    $(CMAKE_CURRENT_LIST_DIR)/libtmx-parser/src/base64.h
#                    $(CMAKE_CURRENT_LIST_DIR)/libtmx-parser/src/base64.cpp
#                    $(CMAKE_CURRENT_LIST_DIR)/libtmx-parser/src/tmxparser.cpp
#       PUBLIC
#                    $(CMAKE_CURRENT_LIST_DIR)/libtmx-parser/src/tmxparser.h
#       )

#set(TMXPARSER "tmxparser")
#FetchContent_Declare(
#                    tmxparser
#                    GIT_REPOSITORY "https://github.com/halsafar/libtmx-parser"
#                    GIT_TAG "master"
#                    )
#FetchContent_MakeAvailable(tmxparser)

# Add global definitions
add_definitions("-Wall")
include_directories(${PROJECT_NAME} ${SDL2_INCLUDE_DIRS} ${SDL2IMAGE_INCLUDE_DIRS} ${SDL2MIXER_INCLUDE_DIRS})
#add_custom_target(${TMXPARSER})

# add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libtmx-parser/)

file(GLOB_RECURSE CSOURCES src/cjson/*.c)
file(GLOB_RECURSE CPPSOURCES src/*.cpp)
# file(GLOB_RECURSE TMXSOURCES libtmx-parser/src/*.cpp)
#add_dependencies(${PROJECT_NAME} ${TMXPARSER})

add_executable(${PROJECT_NAME} ${CSOURCES} ${CPPSOURCES})
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
target_link_libraries(${PROJECT_NAME} PRIVATE ${SDL2_LIBRARIES} ${SDL2IMAGE_LIBRARIES} ${SDL2MIXER_LIBRARIES})
