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

# This needs to be edited each time a new .c is added
add_library (${libname} STATIC 
  image.c imageheader.c imageio.c
  imagedcm.c imagenii.c
  imagesif.c imagecomp.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/libtpcfileutil
  ${CMAKE_SOURCE_DIR}/v2/libtpcecat
  ${CMAKE_SOURCE_DIR}/v2/libtpcdcm
  ${CMAKE_SOURCE_DIR}/v2/libtpcnifti
  ${CMAKE_SOURCE_DIR}/v2/libtpctac
)
target_link_libraries (
  ${libname} 
  tpcextensions tpcift tpccsv tpcisotope tpctac
  tpcecat tpcdcm tpcnifti
  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_image.c test_imageheader.c test_imageio.c
  test_imagedcm.c test_imagenii.c
  test_imagesif.c test_imagecomp.c
) 
# Link the executable to the libraries. 
target_link_libraries (
  lib${libname} ${libname} 
  tpcextensions tpcift tpccsv tpcisotope tpctac
  tpcecat tpcdcm tpcnifti
  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"
)
