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

# This needs to be edited each time a new .c is added
add_library (${libname} STATIC 
  tac.c tacio.c tacift.c simpleio.c dftio.c
  sifio.c tacnan.c tacselect.c tacorder.c 
  taccomp.c tacunits.c tacname.c
  pmodio.c taccsv.c hcio.c qviewio.c matio.c 4dmio.c tacabss.c
  tacx.c tacy.c tacw.c tacdc.c tacxmlio.c
  mtac.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
)
target_link_libraries (
  ${libname} 
  tpcift tpcisotope tpccsv tpcextensions 
  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_tac.c test_tacio.c test_tacift.c test_simpleio.c test_dftio.c
  test_sifio.c test_tacnan.c test_tacselect.c test_tacorder.c 
  test_taccomp.c test_tacunits.c test_tacname.c 
  test_pmodio.c test_taccsv.c test_hcio.c test_qviewio.c test_matio.c test_4dmio.c test_tacabss.c
  test_tacx.c test_tacy.c test_tacw.c test_tacdc.c test_tacxmlio.c
  test_mtac.c
) 
# Link the executable to the libraries. 
target_link_libraries (
  lib${libname} ${libname} 
  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")

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

