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

# This needs to be edited each time a func .c is added
add_library (tpcfunc STATIC 
  func.c rgamma.c
)
# Dependencies on other libraries
include_directories(
  ${tpcfunc_SOURCE_DIR}
  ${libtpcextensions_HEADER_FILES}
  ${libtpcmodels_HEADER_FILES}
)
target_link_libraries (
  tpcfunc 
  tpcmodels tpcextensions 
  m
)

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

# Compile executable for testing
add_executable (libtpcfunc libtpcfunc.c 
  test_func.c test_rgamma.c
) 
# Link the executable to the libraries. 
target_link_libraries (
  libtpcfunc tpcfunc 
  tpcmodels tpcextensions
  m
)
# Install the executable
#install (
#  PROGRAMS 
#  ${CMAKE_CURRENT_BINARY_DIR}/libtpcfunc${CMAKE_EXECUTABLE_SUFFIX}
#  DESTINATION bin
#  COMPONENT librarytests
#)

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

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