## CMake
cmake_minimum_required(VERSION 3.14)
if(NOT CMAKE_BUILD_TYPE)
    set(CMAKE_BUILD_TYPE Debug)
endif()

## Project
project(glbackend
    VERSION 1.0.0
    LANGUAGES CXX
)

## Main target
add_library(${PROJECT_NAME})

## Variables
set(GLBACKEND_DEPENDENCIES)
set(GLBACKEND_DEFINITIONS)

## glfw
find_package(glfw3)
if(glfw3_FOUND)
    list(APPEND GLBACKEND_DEPENDENCIES glfw)
    list(APPEND GLBACKEND_DEFINITIONS  GLBACKEND_GLFW)
endif()

## sdl
find_package(SDL2)
if(SDL2_FOUND)
    list(APPEND GLBACKEND_DEPENDENCIES SDL2)
    list(APPEND GLBACKEND_DEFINITIONS  GLBACKEND_SDL)
endif()

## wxwidgets
# https://cmake.org/cmake/help/v3.14/module/FindwxWidgets.html
# https://cmake.org/cmake/help/v3.14/module/UsewxWidgets.html
find_package(wxWidgets COMPONENTS gl core base)
if(wxWidgets_FOUND)
    add_library(wxWidgets INTERFACE)
    set_target_properties(wxWidgets PROPERTIES
        INTERFACE_INCLUDE_DIRECTORIES        "${wxWidgets_INCLUDE_DIRS}"
        INTERFACE_SYSTEM_INCLUDE_DIRECTORIES "${wxWidgets_INCLUDE_DIRS}"
        INTERFACE_LINK_DIRECTORIES           "${wxWidgets_LIBRARY_DIRS}"
        INTERFACE_COMPILE_DEFINITIONS        "${wxWidgets_DEFINITIONS}"
        INTERFACE_COMPILE_DEFINITIONS_DEBUG  "${wxWidgets_DEFINITIONS_DEBUG}"
        INTERFACE_COMPILE_OPTIONS            "${wxWidgets_CXX_FLAGS}"
        INTERFACE_LINK_LIBRARIES             "${wxWidgets_LIBRARIES}"
    )
    list(APPEND GLBACKEND_DEPENDENCIES wxWidgets)
    list(APPEND GLBACKEND_DEFINITIONS  GLBACKEND_WXWIDGETS)
endif()

## Common
include(common.cmake)
common(
    CXX_STANDARD 11
    FETCHCONTENT
        https://git.rcrnstn.net/rcrnstn/glbase
        https://git.rcrnstn.net/rcrnstn/cxx-str
    DEPENDENCIES_PRIVATE
        glbase
        cxx-str
        ${GLBACKEND_DEPENDENCIES}
    DEPENDENCIES_TESTS
        glbase
        cxx-str
        ${GLBACKEND_DEPENDENCIES}
    DEFINITIONS
        ${GLBACKEND_DEFINITIONS}
)