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

# This needs to be edited each time a new .c is added
add_library (${libname} 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(
  ${CMAKE_SOURCE_DIR}/v2/libtpcextensions
  ${CMAKE_SOURCE_DIR}/v2/libtpcift
  ${CMAKE_SOURCE_DIR}/v2/libtpccsv
  ${CMAKE_SOURCE_DIR}/v2/libtpcmodels
)
target_link_libraries (
  ${libname} 
  tpcift tpcmodels 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_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 (
  lib${libname} ${libname} 
  tpcmodels tpcextensions 
  m
)

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

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