cmake_minimum_required(VERSION 4.1)

project(wayland_lock_pointer LANGUAGES C CXX)

set(wayland_lock_pointer_DIR ${CMAKE_CURRENT_LIST_DIR}/src/wayland_lock_pointer CACHE PATH "")

# Set C++20
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# Set platform variables
if(UNIX)
    set(CMAKE_POSITION_INDEPENDENT_CODE ON)
else()
    message( FATAL_ERROR "Unsupported platform. Please submit a pull request to support this platform." )
endif()

find_package(Python3 COMPONENTS Interpreter Development)

find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)
pkg_check_modules(WAYLAND REQUIRED wayland-client)

# Find libraries
if (NOT TARGET pybind11::module)
    find_package(pybind11 CONFIG REQUIRED)
endif()

# Add python extension
pybind11_add_module(_wayland_lock_pointer
	src/wayland_lock_pointer/_wayland_lock_pointer.py.cpp
	src/wayland_lock_pointer/pointer-constraints-unstable-v1-protocol.c
	src/wayland_lock_pointer/relative-pointer-unstable-v1-protocol.c
)
target_link_libraries(_wayland_lock_pointer PRIVATE ${GTK3_LIBRARIES} ${WAYLAND_LIBRARIES})
target_include_directories(_wayland_lock_pointer PRIVATE ${GTK3_INCLUDE_DIRS} ${WAYLAND_INCLUDE_DIRS})
target_compile_definitions(_wayland_lock_pointer PRIVATE PYBIND11_DETAILED_ERROR_MESSAGES)

if(NOT DEFINED WAYLAND_LOCK_POINTER_EXT_DIR)
    set(WAYLAND_LOCK_POINTER_EXT_DIR ${wayland_lock_pointer_DIR})
endif()

# Install
install(TARGETS _wayland_lock_pointer DESTINATION ${WAYLAND_LOCK_POINTER_EXT_DIR})
