#string(FIND ${CMAKE_CURRENT_SOURCE_DIR} "/" TMP_POS REVERSE)
#math(EXPR TMP_POS "${TMP_POS} + 1")
#string(SUBSTRING ${CMAKE_CURRENT_SOURCE_DIR} ${TMP_POS} -1 CURRENT_SRCDIR)
#message(STATUS " SRCDIR=${CURRENT_SRCDIR}")

# Create variable so that other source codes can find the include files
set(libtpctac_HEADER_FILES "${CMAKE_CURRENT_SOURCE_DIR}" PARENT_SCOPE)

# This needs to be edited each time a new .c is added
add_library (tpctac 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(
#  ${tpctac_SOURCE_DIR}
  ${libtpcextensions_HEADER_FILES}
  ${libtpcift_HEADER_FILES}
  ${libtpcisotope_HEADER_FILES}
  ${libtpccsv_HEADER_FILES}
)
target_link_libraries (
  tpctac 
  tpcift tpcisotope tpccsv tpcextensions 
  m
)

# Install the library and headers
install (
  TARGETS tpctac
  ARCHIVE 
  DESTINATION ${LIBPATH}
  COMPONENT libraries
)

install (
  FILES tpctac.h 
  DESTINATION ${LIBPATH}/include
  COMPONENT headers
)

# Compile executable for testing
add_executable (libtpctac libtpctac.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 (
  libtpctac tpctac 
  tpcextensions 
  m
)
# Install the executable
#install (
#  PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/libtpctac${CMAKE_EXECUTABLE_SUFFIX}
#  DESTINATION bin
#  COMPONENT librarytests
#)


# Copy test data folder
add_custom_target(tests_${CURRENT_SRCDIR} ALL
  COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/test ${CMAKE_CURRENT_BINARY_DIR}/test
)

# Run tests
add_test (
  NAME libtpctacTests
  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test
  COMMAND libtpctac "--verbose" "--test"
)

