#
# $Id$
# $HeadURL$
# $Author$
#

FIND_PACKAGE(RTI)
FIND_PACKAGE(Grantlee5)

NGL_ADD_LIBRARY(ALL codegen_base SHARED
  codegen_export.h
  SqlGenerator.cpp
  SqlGenerator.h
  StructBuilder.cpp
  StructBuilder.h
  XmlReader.cpp
  XmlReader.h
)
NGL_TARGET_LINK_LIBRARIES(codegen_base
  PRIVATE
    Qt5::Xml
    NGLLogger
    ngltools
  PUBLIC
    Qt5::Core
)
NGL_TARGET_INCLUDE_DIRECTORIES(codegen_base
  PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/../
)
# If RTI target is available, propagate its include dirs/compile defs
if (TARGET RTI::nddscpp2)
  NGL_TARGET_INCLUDE_DIRECTORIES(codegen_base
    PUBLIC
      $<TARGET_PROPERTY:RTI::nddscpp2,INTERFACE_INCLUDE_DIRECTORIES>
  )
  NGL_TARGET_COMPILE_DEFINITIONS(codegen_base
    PUBLIC
      $<TARGET_PROPERTY:RTI::nddscpp2,INTERFACE_COMPILE_DEFINITIONS>
  )
else()
  message(STATUS "RTI not found; building codegen_base without RTI include/compile definitions")
endif()
NGL_INSTALL_TARGET(codegen_base)

if (TARGET Grantlee5::Templates)
  NGL_ADD_LIBRARY(ALL codegen_grantlee STATIC
    CppTopicGeneratorGrantlee.cpp
    CppTopicGeneratorGrantlee.h
    DaoGeneratorGrantlee.cpp
    DaoGeneratorGrantlee.h
    DatabaseGeneratorGrantlee.cpp
    DatabaseGeneratorGrantlee.h
    GeneratorGrantleeBase.cpp
    GeneratorGrantleeBase.h
    GrantleeWrappers.cpp
    GrantleeWrappers.h

    svc.idl.grantlee
    svc_enums.idl.grantlee

    svc_translation.cpp.grantlee
    svc_translation.h.grantlee

    svc_dao.cpp.grantlee
    svc_dao.h.grantlee

    svc_db.h.grantlee
    svc_db_impl.h.grantlee
    svc_db_impl.cpp.grantlee

    svc_dtc.h.grantlee
    svc_dtc_impl.cpp.grantlee
    svc_dtc_impl.h.grantlee

    svc_dts.h.grantlee
    svc_dts_impl.cpp.grantlee
    svc_dts_impl.h.grantlee

    svc_ftc.h.grantlee
    svc_ftc_impl.cpp.grantlee
    svc_ftc_impl.h.grantlee

    svc_fts.h.grantlee
    svc_fts_impl.cpp.grantlee
    svc_fts_impl.h.grantlee

    svc_json.cpp.grantlee
    svc_json.h.grantlee

    svc_topic_type_plugin.cpp.grantlee
    svc_topic_type_plugin.h.grantlee

    svc_record_replay_plugin.cpp.grantlee
    svc_record_replay_plugin.h.grantlee

    codegen_simple.py
  )

  NGL_TARGET_LINK_LIBRARIES(codegen_grantlee
    PRIVATE
      Grantlee5::Templates
      NGLLogger
      ProjectConfig
    PUBLIC
      codegen_base
  )
  NGL_TARGET_INCLUDE_DIRECTORIES(codegen_grantlee
    PUBLIC
      ${CMAKE_CURRENT_SOURCE_DIR}/../
  )
else()
  message(STATUS "Grantlee5 not found; skipping codegen_grantlee target")
endif()

NGL_ADD_EXECUTABLE(ALL codegen
  main_grantlee.cpp
)
NGL_TARGET_LINK_LIBRARIES(codegen
  codegen_grantlee
  LtsCommandLineParser
  nglcoreapplication
  Qt5::Core
)

NGL_WRAP_UI(codegen_gui_uics
    main_grantlee_gui.ui
)
NGL_ADD_EXECUTABLE(WS AAR SV NO_TRANSLATION codegen_gui
  ${codegen_gui_uics}
  main_grantlee_gui.cpp
  main_grantlee_gui.ui
)
NGL_TARGET_LINK_LIBRARIES(codegen_gui
  codegen_grantlee
  LtsCommandLineParser
  nglapplication
  Qt5::Widgets
  Grantlee5::Templates
)
