# Make sure the compiler can find include files from our libraries. 
include_directories (${CMAKE_SOURCE_DIR}/v2/libtpcextensions) 
include_directories (${CMAKE_SOURCE_DIR}/v2/libtpcift) 

# Make sure the linker can find the libraries once they are built. 
link_directories (${CMAKE_BINARY_DIR}/v2/libtpcextensions) 
link_directories (${CMAKE_BINARY_DIR}/v2/libtpcift) 

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

# Link the executable to the libraries. 
target_link_libraries (addvers tpcift tpcextensions m)
target_link_libraries (htmlgall tpcextensions m)
target_link_libraries (pdoc2htm tpcextensions m)

# Install the executable(s)
install (
  PROGRAMS
  ${CMAKE_CURRENT_BINARY_DIR}/addvers${CMAKE_EXECUTABLE_SUFFIX}
  ${CMAKE_CURRENT_BINARY_DIR}/htmlgall${CMAKE_EXECUTABLE_SUFFIX}
  ${CMAKE_CURRENT_BINARY_DIR}/pdoc2htm${CMAKE_EXECUTABLE_SUFFIX}
  DESTINATION bin
  COMPONENT applications
)

# Copy test data folder
add_custom_target(misctests 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
#
add_test(addversUsage addvers "--help")
add_test(htmlgallUsage htmlgall "--help")
add_test(pdoc2htmUsage pdoc2htm "--help")
set_tests_properties(
  addversUsage htmlgallUsage pdoc2htmUsage
  PROPERTIES PASS_REGULAR_EXPRESSION "Usage: *"
)

#
# Run test scripts
# 
add_test (
  NAME addversTests
  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test/addvers
  COMMAND bash "./test_addvers.sh"
)
add_test (
  NAME pdoc2htmTests
  WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test/pdoc2htm
  COMMAND bash "./test_pdoc2htm.sh"
)
