# ParmaBasic: minimal Geant4 application using the PARMA source.
# Built as part of parma-g4 when Geant4 is found, or standalone against an
# installed PARMA:  cmake -S . -B build -DParma_DIR=<install>/lib/cmake/Parma
cmake_minimum_required(VERSION 3.16)
project(ParmaBasic CXX)

if(NOT TARGET Parma::parma_g4)
  find_package(Parma REQUIRED)
endif()
find_package(Geant4 REQUIRED)

add_executable(ParmaBasic
  ParmaBasic.cc
  src/DetectorConstruction.cc
  src/ActionInitialization.cc
  src/RunAction.cc
  src/SteppingAction.cc)
target_include_directories(ParmaBasic PRIVATE include)
target_link_libraries(ParmaBasic PRIVATE Parma::parma_g4 ${Geant4_LIBRARIES})

# macros next to the executable
foreach(mac run.mac mt.mac plane.mac test.mac)
  configure_file(${mac} ${CMAKE_CURRENT_BINARY_DIR}/${mac} COPYONLY)
endforeach()

# smoke test when built inside parma-g4; the Geant4 DLLs are found through PATH on Windows
if(PARMA_BUILD_TESTS)
  add_test(NAME parma_basic COMMAND ParmaBasic test.mac WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
  set_tests_properties(parma_basic PROPERTIES
    FAIL_REGULAR_EXPRESSION "Parma00[23]|Parma010|command not found|\\*\\*\\* Fatal")
  if(WIN32)
    get_filename_component(G4_BIN_DIR "${Geant4_DIR}/../../../bin" ABSOLUTE)
    set_tests_properties(parma_basic PROPERTIES ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:${G4_BIN_DIR}")
  endif()
endif()
