#
# This only needs editing by the configure script on Unix platforms. It can be readily used on MacOS
# and Windows (just rename the file to recoll.pro)
#

TEMPLATE        = app
LANGUAGE        = C++
TARGET          = recoll

DEFINES += BUILDING_RECOLL
DEFINES += BUILDING_RECOLLGUI

QT += xml widgets printsupport network

CONFIG  += qt c++17 warn_on thread release lrelease

HEADERS += \
        actsearch_w.h \
        advsearch_w.h \
        advshist.h \
        confgui/confgui.h \
        confgui/confguiindex.h \
        configswitch.h \
        firstidx.h \
        fragbuts.h \
        idxmodel.h \
        idxsched.h \
        preview_load.h \
        preview_plaintorich.h \
        preview_w.h \
        ptrans_w.h \
        rclhelp.h \
        rclmain_w.h \
        rclwebpage.h \
        reslist.h \
        restable.h \
        scbase.h \
        searchclause_w.h \
        snippets_w.h \
        specialindex.h \
        spell_w.h \
        ssearch_w.h \
        systray.h \
        uiprefs_w.h \
        viewaction_w.h \
        webcache.h \
        widgets/editdialog.h \
        widgets/listdialog.h \
        widgets/qxtconfirmationmessage.h

SOURCES += \
        actsearch_w.cpp \
        advsearch_w.cpp \
        advshist.cpp \
        confgui/confgui.cpp \
        confgui/confguiindex.cpp \
        configswitch.cpp \
        fragbuts.cpp \
        guiutils.cpp \
        idxmodel.cpp \
        main.cpp \
        multisave.cpp \
        preview_load.cpp \
        preview_plaintorich.cpp \
        preview_w.cpp \
        ptrans_w.cpp \
        rclhelp.cpp \
        rclm_idx.cpp \
        rclm_menus.cpp \
        rclm_preview.cpp \
        rclm_saveload.cpp \
        rclm_sidefilters.cpp \
        rclm_view.cpp \
        rclm_wins.cpp \
        rclmain_w.cpp \
        rclzg.cpp \
        reslist.cpp \
        respopup.cpp \
        restable.cpp \
        scbase.cpp \
        searchclause_w.cpp \
        snippets_w.cpp \
        spell_w.cpp \
        ssearch_w.cpp \
        systray.cpp \
        uiprefs_w.cpp \
        viewaction_w.cpp \
        webcache.cpp \
        widgets/qxtconfirmationmessage.cpp \
        xmltosd.cpp

FORMS   = \
        actsearch.ui \
        advsearch.ui \
        configswitch.ui \
        firstidx.ui \
        idxsched.ui \
        preview.ui \
        ptrans.ui \
        rclmain.ui \
        restable.ui \
        snippets.ui \
        specialindex.ui \
        spell.ui \
        ssearchb.ui \
        uiprefs.ui \
        viewaction.ui \
        webcache.ui \
        widgets/editdialog.ui \
        widgets/listdialog.ui

RESOURCES = recoll.qrc

TRANSLATIONS = \
i18n/recoll_cs.ts \
i18n/recoll_da.ts \
i18n/recoll_de.ts \
i18n/recoll_el.ts \
i18n/recoll_es.ts \
i18n/recoll_fr.ts \
i18n/recoll_hu.ts \
i18n/recoll_it.ts \
i18n/recoll_ja.ts \
i18n/recoll_ko.ts \
i18n/recoll_lt.ts \
i18n/recoll_nl.ts \
i18n/recoll_pl.ts \
i18n/recoll_ru.ts \
i18n/recoll_sv.ts \
i18n/recoll_tr.ts \
i18n/recoll_uk.ts \
i18n/recoll_xx.ts \
i18n/recoll_zh_CN.ts \
i18n/recoll_zh.ts

windows {
  # NOTE: Copy this file into recoll-win.pro before building

  include(singleapplication.pri)
  
  # QT += webkit webkitwidgets
  # DEFINES += USING_WEBKIT

  QT += widgets webenginewidgets
  DEFINES += USING_WEBENGINE
  
  DEFINES += PSAPI_VERSION=1
  DEFINES += __WIN32__
  DEFINES += UNICODE
  RC_FILE = recoll.rc
  #QCBUILDLOC = Desktop_Qt_6_7_3_MSVC2019_64bit
  QCBUILDLOC = Desktop_Qt_6_8_2_MSVC2022_64bit

  HEADERS += \
    winschedtool.h
  SOURCES += \
    winschedtool.cpp
  FORMS += \
    winschedtool.ui

  INCLUDEPATH += ../common ../index ../internfile ../query ../unac \
              ../utils ../aspell ../rcldb ../qtgui ../xaposix \
              confgui widgets
    
  contains(QMAKE_CC, cl){
    # MSVC. 
    RECOLLDEPS = $$PWD/../../../recolldeps/msvc
    DEFINES += USING_STATIC_LIBICONV
    SOURCES += ../windows/getopt.cc
    PRE_TARGETDEPS = \
      $$PWD/../qmake/build/librecoll/$$QCBUILDLOC-Release/release/recoll.lib
    LIBS += \
      $$PWD/../qmake/build/librecoll/$$QCBUILDLOC-Release/release/recoll.lib \
      $$RECOLLDEPS/libxml2/libxml2-2.9.4+dfsg1/win32/bin.msvc/libxml2.lib \
      $$RECOLLDEPS/libxslt/libxslt-1.1.29/win32/bin.msvc/libxslt.lib \
      $$PWD/../qmake/build/libxapian/$$QCBUILDLOC-Release/release/libxapian.lib \
      $$RECOLLDEPS/wlibiconv/build/$$QCBUILDLOC-Release/release/iconv.lib \
      $$RECOLLDEPS/libmagic/src/lib/libmagic.lib \
      $$RECOLLDEPS/regex/libregex.lib \
      $$RECOLLDEPS/zlib-1.2.11/zdll.lib \
      -lrpcrt4 -lws2_32 -luser32 -lshell32 -lshlwapi -lpsapi -lkernel32
  }
}

@MESONRAN@ = "MESONRAN"
defineTest(macxbundlebuild) {
    # If the MESONRAN variable exists, meson did run, not a bundle build
    equals($$MESONRAN, "MESONRAN") {
      return(false)
    } else {
      return(true)
    }
}

macx:macxbundlebuild() {
  QCBUILDLOC=Qt_6_7_3_for_macOS
  RECOLLDEPS = $$PWD/../../..
  QMAKE_APPLE_DEVICE_ARCHS = x86_64 arm64
  QMAKE_CXXFLAGS += -pthread -Wno-unused-parameter
  DEFINES += RECOLL_AS_MAC_BUNDLE

  QT += widgets webenginewidgets
  DEFINES += USING_WEBENGINE
  
  HEADERS += \
    crontool.h \
    rtitool.h
    
  SOURCES += \
    ../utils/closefrom.cpp \
    ../utils/execmd.cpp \
    ../utils/netcon.cpp \
    ../utils/rclionice.cpp \
    crontool.cpp \
    rtitool.cpp

  FORMS += \
    crontool.ui \
    rtitool.ui

  INCLUDEPATH += ../common ../index ../internfile ../query ../unac \
              ../utils ../aspell ../rcldb ../qtgui ../xaposix \
              confgui widgets

  PRE_TARGETDEPS = $$PWD/../qmake/build/librecoll/$$QCBUILDLOC-Release/librecoll.a

  LIBS += \
    $$PWD/../qmake/build/librecoll/$$QCBUILDLOC-Release/librecoll.a \
    $$PWD/../qmake/build/libxapian/$$QCBUILDLOC-Release/liblibxapian.a \
    $$RECOLLDEPS/libmagic/src/.libs/libmagic.a \
    -lxslt -lxml2 -liconv -lz

  ICON = images/recoll.icns

  APP_DOC.files = \
    ../doc/user/usermanual.html \
    ../doc/user/docbook-xsl.css
  APP_DOC.path = Contents/Resources/doc

  APP_EXAMPLES.files = \
    ../sampleconf/fragment-buttons.xml \
    ../sampleconf/fields \
    ../sampleconf/recoll.conf \
    ../sampleconf/mimeconf \
    ../sampleconf/mimeview \
    ../sampleconf/mimemap \
    ../sampleconf/recoll.qss \
    ../sampleconf/recoll-dark.qss \
    ../sampleconf/recoll-dark.css 
  APP_EXAMPLES.path = Contents/Resources/examples

  APP_EXAMPLES_MAC.files = \
    ../sampleconf/macos/mimeview 
  APP_EXAMPLES_MAC.path = Contents/Resources/examples/macos

  APP_FILTERS.files = \
  ../filters/abiword.xsl \
  ../filters/archivextract.py \
  ../filters/cmdtalk.py \
  ../filters/cnsplitter.py \
  ../python/recoll/recoll/conftree.py \
  ../filters/fb2.xsl \
  ../filters/gnumeric.xsl \
  ../filters/kosplitter.py \
  ../filters/msodump.zip \
  ../filters/okular-note.xsl \
  ../filters/opendoc-body.xsl \
  ../filters/opendoc-flat.xsl \
  ../filters/opendoc-meta.xsl \
  ../filters/openxml-meta.xsl \
  ../filters/openxml-word-body.xsl \
  ../filters/openxml-xls-body.xsl \
  ../filters/ppt-dump.py \
  ../filters/rcl7z.py \
  ../filters/rclaptosidman \
  ../filters/rclaspell-sugg.py \
  ../filters/rclaudio.py \
  ../filters/rclbasehandler.py \
  ../filters/rclbibtex.sh \
  ../filters/rclcheckneedretry.sh \
  ../filters/rclchm.py \
  ../python/recoll/recoll/rclconfig.py \
  ../filters/rcldia.py \
  ../filters/rcldjvu.py \
  ../filters/rcldoc.py \
  ../filters/rcldvi \
  ../filters/rclepub.py \
  ../filters/rclepub1.py \
  ../filters/rclexec1.py \
  ../filters/rclexecm.py \
  ../filters/rclfb2.py \
  ../filters/rclgaim \
  ../filters/rclgenxslt.py \
  ../filters/rclhwp.py \
  ../filters/rclics.py \
  ../filters/rclimg \
  ../filters/rclimg.py \
  ../filters/rclinfo.py \
  ../filters/rclipynb.py \
  ../filters/rcljoplin.py \
  ../filters/rclkar.py \
  ../filters/rclkwd \
  ../filters/rcllatinclass.py \
  ../filters/rcllatinstops.zip \
  ../filters/rcllink.py \
  ../filters/rcllyx \
  ../filters/rclman \
  ../filters/rclmd.py \
  ../filters/rclmidi.py \
  ../filters/rclnamefilter.py \
  ../filters/rclnull.py \
  ../filters/rclocr.py \
  ../filters/rclocrabbyy.py \
  ../filters/rclocrcache.py \
  ../filters/rclocrtesseract.py \
  ../filters/rclopxml.py \
  ../filters/rclorgmode.py \
  ../filters/rclpdf.py \
  ../filters/rclpages.py \
  ../filters/rclppt.py \
  ../filters/rclps \
  ../filters/rclpst.py \
  ../filters/rclpurple \
  ../filters/rclpython.py \
  ../filters/rclrar.py \
  ../filters/rclrtf.py \
  ../filters/rclscribus \
  ../filters/rclsfz.py \
  ../filters/rclshowinfo \
  ../filters/rcltar.py \
  ../filters/rcltex \
  ../filters/rcltext.py \
  ../filters/rcltxtlines.py \
  ../filters/rcluncomp \
  ../filters/rcluncomp.py \
  ../filters/rclwar.py \
  ../filters/rclwebarch.py \
  ../filters/rclxls.py \
  ../filters/rclxml.py \
  ../filters/rclxmp.py \
  ../filters/rclxslt.py \
  ../filters/rclzip.py \
  ../filters/recoll-we-move-files.py \
  ../filters/recollepub.zip \
  ../filters/svg.xsl \
  ../filters/thunderbird-open-message.sh \
  ../filters/xls-dump.py \
  ../filters/xlsxmltocsv.py \
  ../filters/xml.xsl
  APP_FILTERS.path = Contents/Resources/filters

  APP_IMAGES.files = \
  images/asearch.png \
  images/cancel.png \
  images/close.png \
  images/clock.png \
  images/menu.png \
  images/code-block.png \
  images/down.png \
  images/firstpage.png \
  images/history.png \
  images/interro.png \
  images/nextpage.png \
  images/prevpage.png \
  images/recoll.icns \
  images/recoll.png \
  images/sortparms.png \
  images/spell.png \
  images/table.png \
  images/up.png \
  mtpics/License_sidux.txt \
  mtpics/README \
  mtpics/aptosid-book.png \
  mtpics/aptosid-manual-copyright.txt \
  mtpics/aptosid-manual.png \
  mtpics/archive.png \
  mtpics/book.png \
  mtpics/bookchap.png \
  mtpics/document.png \
  mtpics/drawing.png \
  mtpics/emblem-symbolic-link.png \
  mtpics/folder.png \
  mtpics/html.png \
  mtpics/image.png \
  mtpics/message.png \
  mtpics/mozilla_doc.png \
  mtpics/pdf.png \
  mtpics/pidgin.png \
  mtpics/postscript.png \
  mtpics/presentation.png \
  mtpics/sidux-book.png \
  mtpics/soffice.png \
  mtpics/source.png \
  mtpics/sownd.png \
  mtpics/spreadsheet.png \
  mtpics/text-x-python.png \
  mtpics/txt.png \
  mtpics/video.png \
  mtpics/wordprocessing.png
  APP_IMAGES.path = Contents/Resources/images

  QMAKE_BUNDLE_DATA = APP_EXAMPLES APP_EXAMPLES_MAC APP_FILTERS APP_IMAGES APP_DOC
}

unix:!macxbundlebuild() {

VPATH = @srcdir@
# For SingleApplication
include(@srcdir@/singleapplication.pri)

@QMAKE_ENABLE_WEBKIT@QT += webkitwidgets
@QMAKE_ENABLE_WEBKIT@DEFINES += USING_WEBKIT

@QMAKE_ENABLE_WEBENGINE@DEFINES += USING_WEBENGINE
@QMAKE_ENABLE_WEBENGINE@QT += webenginewidgets

@QMAKE_ENABLE_ZEITGEIST@QT += dbus
@QMAKE_ENABLE_ZEITGEIST@QMAKE_CXXFLAGS += -DUSE_ZEITGEIST

@QMAKE_ENABLE_GUIDEBUG@CONFIG += debug force_debug_info

  HEADERS += crontool.h \
             rtitool.h

  SOURCES += crontool.cpp \
        rtitool.cpp

  FORMS  += crontool.ui \
        rtitool.ui

  UI_DIR = .ui
  MOC_DIR = .moc
  OBJECTS_DIR = .obj
  LIBS += @LIBRECOLL_FOR_QMAKE@
  # You will need LD_PRELOAD=/path/to/libasan.xx because -lasan need to be
  # first in libs, so can't use LIBS +=
  #  QMAKE_CXXFLAGS += -fsanitize=address -fno-omit-frame-pointer
  
  LIBS +=  @XAPIAN_LIBS@ \
       @LIBICONV@ $(BDYNAMIC) @LIBQZEITGEIST@ @XSLT_LIBS@ -lz

  INCLUDEPATH += ../ ../common @srcdir@/../common @srcdir@/../index \
              @srcdir@/../internfile @srcdir@/../query @srcdir@/../unac \
              @srcdir@/../utils @srcdir@/../aspell @srcdir@/../rcldb \
              @srcdir@/../qtgui @srcdir@/../xaposix @srcdir@/confgui \
              @srcdir@/widgets
  DEPENDPATH += $$INCLUDEPATH

  isEmpty(PREFIX) {
    PREFIX = /usr/local
  }
  message("Prefix is $$PREFIX")
  DEFINES += PREFIX=\\\"$$PREFIX\\\"

 # Installation stuff
  target.path = "$$PREFIX/bin"

  imdata.files = @srcdir@/mtpics/*.png
  imdata.path = $$PREFIX/share/recoll/images
  trdata.files = .qm/*.qm
  trdata.path = $$PREFIX/share/recoll/translations
  desktop.files += @srcdir@/../desktop/recoll-searchgui.desktop
  desktop.path = $$PREFIX/share/applications/
  icona.files += @srcdir@/../desktop/recoll.png
  icona.path = $$PREFIX/share/icons/hicolor/48x48/apps/
  iconb.files += @srcdir@/../desktop/recoll.png
  iconb.path = $$PREFIX/share/pixmaps/
  appdata.files = @srcdir@/../desktop/org.recoll.recoll.appdata.xml
  appdata.path = $$PREFIX/share/metainfo/
  INSTALLS += target imdata trdata desktop icona iconb appdata

  UNAME = $$system(uname -s)
  contains( UNAME, [lL]inux ) {
          LIBS += -ldl -lX11
  }
  contains( UNAME, SunOS ) {
          LIBS += -ldl
  }
}
