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

# This needs to be edited each time a new .c is added
add_library (${libname} STATIC 
  convolut.c
  sim1cm.c sim2cm.c sim3cms.c sim3cmp.c simkloss.c 
  simrtcm.c simdicm.c simdispersion.c simoxygen.c
  simblood.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/libtpctac
  ${CMAKE_SOURCE_DIR}/v2/libtpcpar
  ${CMAKE_SOURCE_DIR}/v2/libtpcfunc
  ${CMAKE_SOURCE_DIR}/v2/libtpctacmod
  ${CMAKE_SOURCE_DIR}/v2/libtpcmodels
)
target_link_libraries ( 
  ${libname} 
  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_convolut.c
  test_sim1cm.c test_sim2cm.c test_sim3cms.c test_sim3cmp.c test_simkloss.c 
  test_simrtcm.c test_simdicm.c test_simdispersion.c test_simoxygen.c
  test_simblood.c
) 
# Link the executable to the libraries. 
target_link_libraries (
  lib${libname} ${libname} 
  tpctacmod tpcmodels tpcfunc tpcpar tpctac tpcli 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"
)
