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

# This needs to be edited each time a new .c is added
add_library (${libname} STATIC 
  bf_dexp.c bf_dms.c bf_1tcm.c bf_srtm.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/libtpcnlopt
  ${CMAKE_SOURCE_DIR}/v2/libtpclinopt
  ${CMAKE_SOURCE_DIR}/v2/libtpcrand
  ${CMAKE_SOURCE_DIR}/v2/libtpctacmod
  ${CMAKE_SOURCE_DIR}/v2/libtpcli
  ${CMAKE_SOURCE_DIR}/v2/libtpcfunc
  ${CMAKE_SOURCE_DIR}/v2/libtpctac
  ${CMAKE_SOURCE_DIR}/v2/libtpcmodels
  ${CMAKE_SOURCE_DIR}/v2/libtpcpar
  ${CMAKE_SOURCE_DIR}/v2/libtpccm
  ${CMAKE_SOURCE_DIR}/v1/libtpcsvg
)
target_link_libraries (
  ${libname} 
  tpclinopt tpcli tpctacmod tpctac tpccm 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_bfm.c test_bf_dexp.c test_bf_dms.c test_bf_1tcm.c test_bf_srtm.c
) 
# Link the executable to the libraries. 
target_link_libraries (
  lib${libname} ${libname} 
  tpclinopt tpcli tpctac tpccm 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"
)
