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

# This needs to be edited each time a par .c is added
add_library (tpcpar STATIC 
  par.c parcsv.c parift.c parxmlio.c pario.c 
  parres.c parfit.c parcomb.c parcomp.c
  parselect.c parorder.c parexample.c
)
# Dependencies on other libraries
include_directories(
#  ${tpcpar_SOURCE_DIR}
  ${libtpcextensions_HEADER_FILES}
  ${libtpcift_HEADER_FILES}
  ${libtpccsv_HEADER_FILES}
  ${libtpcmodels_HEADER_FILES}
)
target_link_libraries (
  tpcpar 
  tpcmodels tpcift tpccsv tpcextensions
  m
)

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

# Compile executable for testing
add_executable (libtpcpar libtpcpar.c 
  test_par.c test_parcsv.c test_parift.c test_parxmlio.c test_pario.c
  test_parres.c test_parfit.c test_parcomb.c test_parcomp.c
  test_parselect.c test_parorder.c test_parexample.c
) 
# Link the executable to the libraries. 
target_link_libraries (
  libtpcpar tpcpar 
  tpcmodels tpcextensions 
  m
)

# Copy test data folder
file(COPY test DESTINATION ${CMAKE_CURRENT_BINARY_DIR} )

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