# Set the name of library
set(libname "tpctacmod")

# This needs to be edited each time a new .c is added
add_library (${libname} STATIC 
  litac.c lisim.c tacmodelinput.c 
  tacfitplot.c histplot.c partac.c mftac.c delay.c
# litacrange.c
)
# Dependencies on other libraries
include_directories(
  ${CMAKE_SOURCE_DIR}/v2/libtpcextensions
  ${CMAKE_SOURCE_DIR}/v2/libtpcift
  ${CMAKE_SOURCE_DIR}/v2/libtpcisotope
  ${CMAKE_SOURCE_DIR}/v2/libtpccsv
  ${CMAKE_SOURCE_DIR}/v2/libtpcli
  ${CMAKE_SOURCE_DIR}/v2/libtpcfunc
  ${CMAKE_SOURCE_DIR}/v2/libtpctac
  ${CMAKE_SOURCE_DIR}/v2/libtpccm
  ${CMAKE_SOURCE_DIR}/v2/libtpcmodels
  ${CMAKE_SOURCE_DIR}/v2/libtpcstatist
  ${CMAKE_SOURCE_DIR}/v2/libtpclinopt
  ${CMAKE_SOURCE_DIR}/v2/libtpcpar
  ${CMAKE_SOURCE_DIR}/v1/libtpcsvg
)
target_link_libraries (
  ${libname} 
  tpctac tpcpar tpclinopt tpcfunc tpcmodels tpcli tpcstatist tpcextensions tpcsvg
  m
)

# Install the library and headers
install (
  TARGETS ${libname}
  ARCHIVE 
  DESTINATION ${LIBPATH}
  COMPONENT libraries
)
install (
  FILES ${libname}.h
  DESTINATION ${LIBPATH}/include
  COMPONENT headers
)

# Compile executable for testing
add_executable (lib${libname} lib${libname}.c 
  test_litac.c test_lisim.c test_tacmodelinput.c
  test_tacfitplot.c test_histplot.c test_partac.c test_mftac.c test_delay.c
# test_litacrange.c
) 
# Link the executable to the libraries. 
target_link_libraries (
  lib${libname} ${libname}
  tpctac tpcpar tpcfunc tpcmodels tpcli tpclinopt tpccm tpcstatist tpcextensions 
  m
)


# Copy test data folder
add_custom_target(tests_${libname} ALL
  COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/test ${CMAKE_CURRENT_BINARY_DIR}/test
)
# And delete test data folder with clean
set_property(DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_CURRENT_BINARY_DIR}/test")

#set(testname test_${libname})
#add_custom_target(${testname} ALL
#  COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/test
#  COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/test ${CMAKE_CURRENT_BINARY_DIR}/test/
#)


# Run tests
add_test (
  NAME lib${libname}Tests
  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test
  COMMAND lib${libname} "--verbose" "--test"
)
