project(peperoni)

# The plugin uses libusb on every platform. On Windows the device must be
# bound to WinUSB (automatic with firmware >= 0x1000, otherwise use Zadig).
if(NOT LIBUSB_1_FOUND)
    message(WARNING "libusb-1.0 not found: the Peperoni plugin will not be built")
    return()
endif()

set(module_name "peperoni")

set(TS_FILES
    Peperoni_fi_FI.ts
    Peperoni_de_DE.ts
    Peperoni_es_ES.ts
    Peperoni_fr_FR.ts
    Peperoni_it_IT.ts
    Peperoni_nl_NL.ts
    Peperoni_cz_CZ.ts
    Peperoni_pt_BR.ts
    Peperoni_ca_ES.ts
    Peperoni_ja_JP.ts
)

if(QT_VERSION_MAJOR GREATER 5)
    qt_add_translation(QM_FILES ${TS_FILES})
else()
    qt5_add_translation(QM_FILES ${TS_FILES})
endif()

add_library(${module_name}
    SHARED
    ${QM_FILES}
)

target_sources(${module_name} PRIVATE
    ../interfaces/qlcioplugin.cpp ../interfaces/qlcioplugin.h
    ${module_name}.cpp ${module_name}.h
    peperonidevice.cpp peperonidevice.h
    peperonidefs.h
)
target_include_directories(${module_name} PRIVATE
    ../interfaces
    ${LIBUSB_1_INCLUDE_DIRS}
)

target_link_libraries(${module_name} PRIVATE
    Qt${QT_MAJOR_VERSION}::Core
    Qt${QT_MAJOR_VERSION}::Gui
    Qt${QT_MAJOR_VERSION}::Widgets
    ${LIBUSB_1_LINK_LIBRARIES}
)

install(TARGETS ${module_name}
    LIBRARY DESTINATION ${INSTALLROOT}/${PLUGINDIR}
    RUNTIME DESTINATION ${INSTALLROOT}/${PLUGINDIR}
)

if (UNIX AND NOT APPLE)
   # Rules to make USB DMX devices readable & writable by normal users
   install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/z65-peperoni.rules"
           DESTINATION ${UDEVRULESDIR})
   install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/org.qlcplus.QLCPlus.peperoni.metainfo.xml"
           DESTINATION ${METAINFODIR})
endif()
