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

# This needs to be edited each time a cm .c is added
add_library (tpccm 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(
#  ${tpccm_SOURCE_DIR}
  ${libtpcextensions_HEADER_FILES}
# just for test routines
  ${libtpcli_HEADER_FILES}
  ${libtpccsv_HEADER_FILES}
  ${libtpcift_HEADER_FILES}
  ${libtpcisotope_HEADER_FILES}
  ${libtpctac_HEADER_FILES}
  ${libtpcpar_HEADER_FILES}
  ${libtpcfunc_HEADER_FILES}
  ${libtpcmodels_HEADER_FILES}
  ${libtpctacmod_HEADER_FILES}
)
target_link_libraries ( 
  tpccm
  tpcextensions
  m
)

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

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

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

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