cmake_minimum_required(VERSION 3.3 FATAL_ERROR)

find_package( LCIO REQUIRED )

find_package( DD4hep REQUIRED COMPONENTS DDCore DDG4 DDRec )

find_package(ROOT REQUIRED COMPONENTS Geom GenVector MathCore)
include(${ROOT_USE_FILE})

FIND_PACKAGE( GBL )
FIND_PACKAGE( aidaTT )

IF( GBL_FOUND )
        ADD_DEFINITIONS( "-DUSE_GBL" )
        ADD_DEFINITIONS( "-DGBL_EIGEN_SUPPORT_ROOT" )
ELSE()
    MESSAGE( STATUS "GBL not found, track fitting with GBL will not be available." )
ENDIF()

IF( DD4hep_FOUND )
        ADD_DEFINITIONS( "-DAIDATT_USE_DD4HEP" )
ELSE()
    MESSAGE( STATUS "DD4hep not found, the geometry decription from DD4hep will not be available." )
ENDIF()

IF( LCIO_FOUND )
        ADD_DEFINITIONS( "-DUSE_LCIO" )
ELSE()
    MESSAGE( STATUS "LCIO not found, LCIO persistency will not be available." )
ENDIF()

IF( streamlog_FOUND )
  ADD_DEFINITIONS( "-DAIDATT_USE_STREAMLOG" )
ENDIF()

set(exe_name gbl_example)
add_executable(${exe_name} src/${exe_name}.cxx)
target_include_directories(${exe_name} PUBLIC
  PRIVATE include )
target_compile_features(${exe_name}
  PUBLIC cxx_auto_type
  PUBLIC cxx_trailing_return_types
  PRIVATE cxx_variadic_templates )

target_link_libraries( ${exe_name}
  PUBLIC DDCore DDG4   DDRec ROOT::Core ROOT::Hist ROOT::GenVector ROOT::Gpad
  ${LCIO_LIBRARIES}  ${aidaTT_LIBRARIES} ${GBL_LIBRARIES} )

message("aidaTT_LIBRARIES : ${aidaTT_LIBRARIES}")

INCLUDE_DIRECTORIES( SYSTEM ${aidaTT_INCLUDE_DIRS} ${GBL_INCLUDE_DIRS} )
#$TARGET_LINK_LIBRARIES( ${exe_name} ${GBL_LIBRARIES} )
ADD_DEFINITIONS( ${${GBL_LIBRARIES}_DEFINITIONS} )

install(TARGETS ${exe_name}
  EXPORT NPDetTargets
  RUNTIME DESTINATION bin )
