option(ENABLE_LIB_xcbXorg "Enable XCB/Xorg Connection Manager backend lib" ON)

if(ENABLE_LIB_xcbXorg)
    pkg_check_modules(XCB REQUIRED xcb)
    if(NOT XCB_FOUND)
        message(FATAL_ERROR "XCB library not found. XCB/Xorg requires the XCB dev headers and shlib.")
    endif()

    add_library(xcbXorg SHARED
        xcbXorg.cpp
    )

    set_target_properties(xcbXorg PROPERTIES
        VERSION ${PROJECT_VERSION}
        SOVERSION ${PROJECT_VERSION_MAJOR}
    )

    # Set config define for header generation
    add_compile_definitions(CONFIG_LIB_XCBXORG_ENABLED)
    target_include_directories(xcbXorg PUBLIC ${XCB_INCLUDE_DIRS})
    target_link_libraries(xcbXorg ${XCB_LIBRARIES})

    # Install rules
    install(TARGETS xcbXorg
        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} NAMELINK_SKIP
    )
endif()
