# Make sure the compiler can find include files from our libraries. 
include_directories (${CMAKE_SOURCE_DIR}/v1/libtpcmisc) 
include_directories (${CMAKE_SOURCE_DIR}/v1/libtpccurveio) 
include_directories (${CMAKE_SOURCE_DIR}/v1/libtpcmodel) 
include_directories (${CMAKE_SOURCE_DIR}/v1/libtpcimgio) 
include_directories (${CMAKE_SOURCE_DIR}/v1/libtpcimgp) 
include_directories (${CMAKE_SOURCE_DIR}/v1/libtpcsvg) 
include_directories (${CMAKE_SOURCE_DIR}/v1/libtpcmodext) 
include_directories (${CMAKE_SOURCE_DIR}/v1/libtpcroi) 
include_directories (${CMAKE_SOURCE_DIR}/v1/libtpcidi) 

# Make sure the linker can find the libraries once they are built. 
link_directories (${CMAKE_BINARY_DIR}/v1/libtpcmisc) 
link_directories (${CMAKE_BINARY_DIR}/v1/libtpccurveio) 
link_directories (${CMAKE_BINARY_DIR}/v1/libtpcmodel) 
link_directories (${CMAKE_BINARY_DIR}/v1/libtpcimgio) 
link_directories (${CMAKE_BINARY_DIR}/v1/libtpcimgp) 
link_directories (${CMAKE_BINARY_DIR}/v1/libtpcsvg) 
link_directories (${CMAKE_BINARY_DIR}/v1/libtpcmodext) 
link_directories (${CMAKE_BINARY_DIR}/v1/libtpcroi) 
link_directories (${CMAKE_BINARY_DIR}/v1/libtpcidi) 

# Add executable that is built from the source file(s) 
# The extensions are automatically found. 
add_executable (upet2e7 upet2e7.c) 
add_executable (upet2sif upet2sif.c) 

# Link the executable to the libraries. 
target_link_libraries (upet2e7 tpcimgp tpcimgio tpcmisc m)
target_link_libraries (upet2sif tpcimgp tpcimgio tpcmisc m)

# Install the executable(s)
INSTALL(
  PROGRAMS
  ${CMAKE_CURRENT_BINARY_DIR}/upet2e7${CMAKE_EXECUTABLE_SUFFIX}
  ${CMAKE_CURRENT_BINARY_DIR}/upet2sif${CMAKE_EXECUTABLE_SUFFIX}
  DESTINATION bin
  COMPONENT applications
)


# Copy test data folder
add_custom_target(upettests ALL
  COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/test
  COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/test ${CMAKE_CURRENT_BINARY_DIR}/test/
)
# And delete test data folder with clean
set_property(DIRECTORY PROPERTY ADDITIONAL_MAKE_CLEAN_FILES "${CMAKE_CURRENT_BINARY_DIR}/test")


#
# Simple tests
#
if(NOT (MINGW OR MSYS))
# Does the usage message work
add_test(upet2e7Usage upet2e7 "--help")
add_test(upet2sifUsage upet2sif "--help")
set_tests_properties(
  upet2e7Usage upet2sifUsage
  PROPERTIES PASS_REGULAR_EXPRESSION "Usage: *"
)
endif()

#
# Run test scripts
# 
add_test (
  NAME upet2e7Tests
  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test/upet2e7
  COMMAND ${BASH_EXEC} "./test_upet2e7.sh"
)
add_test (
  NAME upet2sifTests
  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test/upet2sif
  COMMAND ${BASH_EXEC} "./test_upet2sif.sh"
)
# Add app installation location to PATH so that bash scripts can find the other apps
set_tests_properties(
  upet2e7Tests upet2sifTests
  PROPERTIES ENVIRONMENT_MODIFICATION PATH=path_list_append:${CMAKE_BINARY_DIR}
)
