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

# This needs to be edited each time a new .c is added
add_library (tpcmodel STATIC 
  aic.c bobyqa.c bootstrap.c bvls.c constraints.c
  gaussdev.c hholder.c integr.c llsqwt.c lms.c lts.c
  median.c mertwi.c mestim.c mtga.c nlopt1d.c nnls.c normaldistr.c
  o2.c pearson.c powell.c qr.c runs_test.c shuffle.c
  simplex.c simulate.c tgo.c 
)

# Dependencies on other libraries
include_directories( 
  ${libtpcmisc_HEADER_FILES} 
)
target_link_libraries (tpcmodel tpcmisc m)

# Install the library and headers
install (
  TARGETS tpcmodel
  ARCHIVE 
  DESTINATION ${LIBPATH}
  COMPONENT libraries
)

install (
  FILES libtpcmodel.h 
  DESTINATION ${LIBPATH}/include
  COMPONENT headers
)

# Compile executable for testing
add_executable (libtpcmodel test_libtpcmodel.c) 
# Link the executable to the libraries. 
target_link_libraries (libtpcmodel tpcmodel tpcmisc m)
# Install the executable
#INSTALL(
#  PROGRAMS 
#  ${CMAKE_CURRENT_BINARY_DIR}/libtpcmodel${CMAKE_EXECUTABLE_SUFFIX}
#  DESTINATION bin
#  COMPONENT librarytests
#)

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

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

