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

# This needs to be edited each time a new .c is added
add_library (${libname} STATIC 
  dcmuid.c dcmvr.c dcmdictionary.c dcmio.c
  dcmdata.c dcmfile.c dcmsop.c dcmmatrix.c
  dcmimage.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/libtpcfileutil
)
target_link_libraries (
  ${libname} 
  tpcextensions tpcift tpcfileutil tpcisotope
  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_dcmuid.c test_dcmvr.c test_dcmdictionary.c test_dcmio.c
  test_dcmdata.c test_dcmfile.c test_dcmsop.c test_dcmmatrix.c
  test_dcmimage.c
) 
# Link the executable to the libraries. 
target_link_libraries (
  lib${libname} ${libname} 
  tpcextensions tpcift tpcfileutil tpcisotope
  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"
)
