# - spirit_fcn_test
cmake_minimum_required(VERSION 3.17)

project(spirit_fcn_test VERSION 0.1 LANGUAGES CXX)

#--- set a default build type if none was specified ---------------------------
set(default_build_type "Debug")

if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
  message(STATUS "Setting build type to '${default_build_type}' as none was specified.")
  set(CMAKE_BUILD_TYPE "${default_build_type}" CACHE
      STRING "Choose the type of build." FORCE)
  # Set the possible values of build type for cmake-gui
  set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS
    "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif ()

#--- check for pkg-config -----------------------------------------------------
find_package(PkgConfig REQUIRED)

#--- check for ROOT -----------------------------------------------------------
find_package(ROOT 6.18 REQUIRED COMPONENTS Gui MathMore Minuit2 XMLParser)
if (ROOT_mathmore_FOUND)
  execute_process(COMMAND root-config --bindir OUTPUT_VARIABLE ROOT_BINDIR)
  string(STRIP ${ROOT_BINDIR} ROOT_BINDIR)
  execute_process(COMMAND root-config --version OUTPUT_VARIABLE ROOT_VERSION)
  string(STRIP ${ROOT_VERSION} ROOT_VERSION)
  message("-- Found ROOT: ${ROOT_BINDIR} (found version: ${ROOT_VERSION})")
  #---Define useful ROOT functions and macros (e.g. ROOT_GENERATE_DICTIONARY)
  include(${ROOT_USE_FILE})
endif (ROOT_mathmore_FOUND)

#--- check for boost ----------------------------------------------------------
find_package(Boost QUIET)
if (Boost_VERSION VERSION_GREATER_EQUAL "1.89")
  find_package(Boost REQUIRED
    COMPONENTS
      filesystem
  )
else (Boost_VERSION VERSION_GREATER_EQUAL "1.89")
  find_package(Boost REQUIRED
    COMPONENTS
      system
      filesystem
  )
endif (Boost_VERSION VERSION_GREATER_EQUAL "1.89")

#--- create executable --------------------------------------------------------
add_executable(spirit_fcn_test
	       spirit_fcn_test.cpp
               PFunction.cpp
	       PFunctionHandler.cpp
)

#--- add include directories --------------------------------------------------
target_include_directories(spirit_fcn_test
  BEFORE PRIVATE
    ${Boost_INCLUDE_DIR}
)

#--- link libraries -----------------------------------------------------------
target_link_libraries(spirit_fcn_test
  ${ROOT_LIBRARIES}
  ${Boost_LIBRARIES}
)

#--- installation info --------------------------------------------------------
install(
  TARGETS
    spirit_fcn_test
  RUNTIME DESTINATION
    bin
)
