#
# CMake Script
# $Id$
# $HeadURL$
# $Author$
#

# BZip2 (legacy REQUIRED it; defines HAVE_BZIP2 so the real impl compiles instead of the stub)
FIND_PACKAGE(BZip2 REQUIRED)

SET(nglcomp_SRCS
  nglcomp_bzip2iodevice.cpp
  nglcomp_bzip2iodevice.h
  nglcomp_compress.cpp
  nglcomp_compress.h
  nglcomp_export.h
  nglcomp_tarfilter.cpp
  nglcomp_tarfilter.h
)
NGL_ADD_LIBRARY2(WS nglcompression SHARED ${nglcomp_SRCS})
NGL_TARGET_LINK_LIBRARIES(nglcompression
  PUBLIC
    Qt6::Core
  PRIVATE
    Qt6::Concurrent
    NGLLogger
    ${BZIP2_LIBRARIES}
)
NGL_TARGET_INCLUDE_DIRECTORIES(nglcompression
  PRIVATE
    ${BZIP2_INCLUDE_DIR}
)
# Enable the real bzip2 impl (guard in nglcomp_bzip2iodevice.{h,cpp}); legacy always compiled it
TARGET_COMPILE_DEFINITIONS(nglcompression PRIVATE HAVE_BZIP2)
NGL_INSTALL_TARGET(nglcompression)

IF(BUILD_WS AND BUILD_TESTING)
  REMOVE_DEFINITIONS(-DQT_GUI_LIB)
  ADD_EXECUTABLE(nglcomp_test nglcomp_test.cpp nglcomp_test.h)

  TARGET_LINK_LIBRARIES(nglcomp_test
      NGLLogger
      nglcoreapplication
      ngltools
      nglcompression
      Qt6::Test
      )

  ADD_TEST(NAME nglcomp_test COMMAND $<TARGET_FILE:nglcomp_test>)
ENDIF()
