cmake_minimum_required(VERSION 3.10 )
set(CMAKE_C_STANDARD 11)
project(wlgol
    VERSION 0.0.1
    DESCRIPTION "Wayland Game Of Life"
    LANGUAGES C)

find_package(PkgConfig REQUIRED)
pkg_check_modules(XKBCOMMON REQUIRED xkbcommon)

# Download xdg-shell.xml
# file(DOWNLOAD "https://cgit.freedesktop.org/wayland/wayland-protocols/plain/stable/xdg-shell/xdg-shell.xml" "${CMAKE_CURRENT_BINARY_DIR}/xdg-shell.xml")

# Generation of xdg-shell.h and xdg-shell.c
add_custom_command(
    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/include/xdg-shell.h
    COMMAND wayland-scanner client-header ${CMAKE_SOURCE_DIR}/xdg-shell.xml ${CMAKE_CURRENT_BINARY_DIR}/include/xdg-shell.h
    DEPENDS ${CMAKE_SOURCE_DIR}/xdg-shell.xml
)

add_custom_command(
    OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/xdg-shell.c
    COMMAND wayland-scanner private-code ${CMAKE_SOURCE_DIR}/xdg-shell.xml ${CMAKE_CURRENT_BINARY_DIR}/xdg-shell.c
    DEPENDS ${CMAKE_SOURCE_DIR}/xdg-shell.xml
)

set(SOURCES
    tkeyboard.c
    tpointer.c
	hashtable.c
    ${CMAKE_CURRENT_BINARY_DIR}/xdg-shell.c
)

set(GENHEADERS
    ${CMAKE_CURRENT_BINARY_DIR}/include/xdg-shell.h
)

add_executable(wlgol wlgol.c ${SOURCES} ${GENHEADERS})

target_include_directories(wlgol
    PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/include
    PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include
    PUBLIC ${XKBCOMMON_INCLUDE_DIRS}
)

target_link_libraries(wlgol
    wayland-client
    wayland-cursor
    ${XKBCOMMON_LIBRARIES}
)

target_compile_options(wlgol PRIVATE
    ${XKBCOMMON_CFLAGS_OTHER}
)



add_executable(test_hashtable tests/test_hashtable.c
    ${SOURCES}
)
target_link_libraries(test_hashtable
    wayland-client
    wayland-cursor
    ${XKBCOMMON_LIBRARIES}
)
target_include_directories(test_hashtable
    PUBLIC ${CMAKE_CURRENT_BINARY_DIR}/include
    PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include
    PUBLIC ${XKBCOMMON_INCLUDE_DIRS}
)
target_compile_options(test_hashtable PRIVATE
    ${XKBCOMMON_CFLAGS_OTHER}
)

enable_testing()
add_test(NAME Hashtable COMMAND test_hashtable)
