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

# This needs to be edited each time a new .c is added
add_library (${libname} STATIC 
  stringext.c decpoint.c filename.c proginfo.c
  units.c statusmsg.c readasciifile.c datetime.c
  doubleutil.c floatutil.c intutil.c endian.c
  studynr.c roiname.c 
)

# Dependencies on other libraries
# Try to keep empty
include_directories(
#  ${CMAKE_SOURCE_DIR}/v2/libtpcextensions
#  ${CMAKE_SOURCE_DIR}/v2/libtpcfileutil
)

# 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_stringext.c test_decpoint.c test_filename.c test_proginfo.c
  test_units.c test_statusmsg.c test_readasciifile.c test_datetime.c
  test_doubleutil.c test_floatutil.c test_intutil.c test_endian.c
  test_studynr.c test_roiname.c
) 
# Link the executable to the libraries. 
target_link_libraries (
  lib${libname} ${libname}
  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"
)

