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

# This needs to be edited each time a new .c is added
add_library (tpcmodext STATIC 
  bf_model.c cluster_tac.c dftinput.c dftint.c
  extrapolate.c fittime.c img_k1.c img_mtga.c
  imginput.c misc_model.c mrl.c noise.c
  plotdata.c plotfit.c units_check.c weight_model.c
)

# Dependencies on other libraries
include_directories( 
  ${libtpcmisc_HEADER_FILES} 
  ${libtpcsvg_HEADER_FILES} 
  ${libtpcmodel_HEADER_FILES} 
  ${libtpccurveio_HEADER_FILES} 
  ${libtpcimgio_HEADER_FILES} 
  ${libtpcimgp_HEADER_FILES} 
)
target_link_libraries (
  tpcmodext 
  tpcimgp tpcimgio tpccurveio tpcmodel tpcsvg tpcmisc 
  m
)

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

# Compile executable for testing
add_executable (libtpcmodext test_libtpcmodext.c) 
# Link the executable to the libraries. 
target_link_libraries (libtpcmodext tpcmodext 
  tpcimgp tpcimgio tpccurveio tpcmodel tpcsvg tpcmisc
  m
)
# Install the executable
#INSTALL(
#  PROGRAMS 
#  ${CMAKE_CURRENT_BINARY_DIR}/libtpcmodext${CMAKE_EXECUTABLE_SUFFIX}
#  DESTINATION bin
#  COMPONENT librarytests
#)

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

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