cmake_minimum_required(VERSION 3.12 FATAL_ERROR)

find_package ( DD4hep REQUIRED DDG4 )

dd4hep_configure_output()
dd4hep_set_compiler_flags()

set( sdet_headers
  include/PMTHit.h
  )


ROOT_GENERATE_DICTIONARY(G__DDG4_PIDsdet
  #$<BUILD_INTERFACE:-I${SPDLOG_INCLUDE_DIR}>
  #$<BUILD_INTERFACE:-I${FMT_INCLUDE_DIR}>
  OPTIONS -I${CMAKE_CURRENT_SOURCE_DIR} 
  OPTIONS -I${CMAKE_CURRENT_SOURCE_DIR}/include 
  OPTIONS -I${DD4hep_INCLUDE_DIR}
  ${sdet_headers}
  LINKDEF LinkDef.h
  )
add_custom_target(G__DDG4_PIDsdet_ROOTDICT DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/G__DDG4_PIDsdet.cxx)

#dd4hep_add_dictionary(G__DDG4_PIDsdet
#  SOURCES ${DD4hep_DIR}/include/ROOT/Warnings.h src/PMTHit.h
#  LINKDEF ${DD4hep_DIR}/include/ROOT/LinkDef.h
#  OUTPUT  ${LIBRARY_OUTPUT_PATH}
#  USES    DD4hep::DDCore DD4hep::DDG4 Geant4::Interface
#  )
#
#----  Example of a client library with user defined plugins  --------------------
dd4hep_add_plugin( DDG4_PIDsdet
  GENERATED G__DDG4_PIDsdet.cxx
  SOURCES   
    src/PMTHit.cpp 
    src/PhotoMultiplierSDAction.cpp
    USES DD4hep::DDCore DD4hep::DDG4 Geant4::Interface ROOT::Core ROOT::GenVector
  )
add_dependencies(DDG4_PIDsdet G__DDG4_PIDsdet_ROOTDICT)
target_include_directories(DDG4_PIDsdet 
  PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
  PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
  PUBLIC $<INSTALL_INTERFACE:include/npdet>
  )

install(TARGETS DDG4_PIDsdet 
  EXPORT NPDetTargets
  DESTINATION lib)
install(FILES  ${sdet_headers} 
  DESTINATION include/npdet)

if (${ROOT_VERSION} VERSION_LESS 6.22.0)
  install(
    FILES ${CMAKE_CURRENT_BINARY_DIR}/G__DDG4_PIDsdet_rdict.pcm
    DESTINATION lib)
else()
  install(
    FILES ${CMAKE_CURRENT_BINARY_DIR}/libDDG4_PIDsdet_rdict.pcm
    DESTINATION lib)
endif()

  # # Geant4 material scan. From position=0,0,0 to end-of-world 
  # dd4hep_add_test_reg( DDG4_PIDsdet_g4material_scan_SiliconBlock_LONGTEST
  #   COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_DDG4_PIDsdet.sh"
  #   EXEC_ARGS  python ${DD4hep_ROOT}/bin/g4MaterialScan --compact=file:${CMAKE_INSTALL_PREFIX}/examples/ClientTests/compact/SiliconBlock.xml
  #              "--position=0,0,0" "--direction=0,1,0"
  #   REGEX_PASS " Terminate Geant4 and delete associated actions."
  # )
  #            
  # dd4hep_add_test_reg( DDG4_PIDsdet_sim_SiliconBlock_LONGTEST
  #   COMMAND    "${CMAKE_INSTALL_PREFIX}/bin/run_test_DDG4_PIDsdet.sh"
  #   EXEC_ARGS  python ${DDG4_PIDsdet_INSTALL}/scripts/PhotoMultiplierSD_sim.py 
  #              --compact=file:${CMAKE_INSTALL_PREFIX}/examples/ClientTests/compact/SiliconBlock.xml
  #   REGEX_PASS NONE
  #   REGEX_FAIL "Exception;EXCEPTION;ERROR;Error" )

  #endif()
