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

# This needs to be edited each time a new .c is added
add_library (tpcmicropet STATIC 
  micropetio.c
)
# Dependencies on other libraries
include_directories(
  $(libtpcmicropet_SOURCE_DIR)
  ${libtpcextensions_HEADER_FILES}
  ${libtpcfileutil_HEADER_FILES}
  ${libtpcift_HEADER_FILES}
)
target_link_libraries (
  tpcmicropet 
  tpcextensions 
  tpcfileutil
  tpcift 
  m
)

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

# Compile executable for testing
add_executable (libtpcmicropet libtpcmicropet.c 
  test_micropetio.c
) 
# Link the executable to the libraries. 
target_link_libraries (
  libtpcmicropet tpcmicropet 
  tpcextensions 
  m
)

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

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