configure_file(ht_config.h.in ht_config.h @ONLY)
configure_file(htio2/config.h.in htio2/config.h @ONLY)

file(GLOB HTIO_SOURCE_FILES htio2/*.cpp)
file(GLOB HTQC_SOURCE_FILES htqc/*.cpp)
file(GLOB JUCE_SOURCE_FILES htio2/JUCE-3.0.8/modules/*/*.cpp)

add_library(htio2 STATIC ${HTIO_SOURCE_FILES} ${JUCE_SOURCE_FILES})

add_library(ht_common STATIC ${HTQC_SOURCE_FILES})

add_executable(ht2-convert ht2-convert.cpp)
target_link_libraries(ht2-convert
    ht_common
    htio2
    ${juce_dep_libs}
    ${ZLIB_LIBRARIES}
)

add_executable(ht2-demul ht2-demul.cpp)
target_link_libraries(ht2-demul
    ht_common
    htio2
    ${juce_dep_libs}
    ${ZLIB_LIBRARIES}
)

add_executable(ht2-stat ht2-stat.cpp
    htqc/BaseQualCounter.cpp
    htqc/FastqStat.cpp
)
target_link_libraries(ht2-stat
    ht_common
    htio2
    ${juce_dep_libs}
    ${ZLIB_LIBRARIES}
)

add_executable(ht2-trim ht2-trim.cpp)
target_link_libraries(ht2-trim
    ht_common
    htio2
    ${juce_dep_libs}
    ${ZLIB_LIBRARIES}
)

add_executable(ht2-filter ht2-filter.cpp)
target_link_libraries(ht2-filter
    ht_common
    htio2
    ${juce_dep_libs}
    ${ZLIB_LIBRARIES}
)

add_executable(ht2-rename ht2-rename.cpp)
target_link_libraries(ht2-rename
    ht_common
    htio2
    ${juce_dep_libs}
    ${ZLIB_LIBRARIES}
)

add_executable(ht2-sample ht2-sample.cpp)
target_link_libraries(ht2-sample
    ht_common
    htio2
    ${juce_dep_libs}
    ${ZLIB_LIBRARIES}
)

add_executable(ht2-overlap ht2-overlap.cpp)
target_link_libraries(ht2-overlap
    ht_common
    htio2
    ${juce_dep_libs}
    ${ZLIB_LIBRARIES}
)

add_executable(ht2-primer-trim ht2-primer-trim.cpp)
target_link_libraries(ht2-primer-trim
    ht_common
    htio2
    ${juce_dep_libs}
    ${ZLIB_LIBRARIES}
)

add_executable(ht2-lane-tile ht2-lane-tile.cpp)
target_link_libraries(ht2-lane-tile
    ht_common
    htio2
    ${juce_dep_libs}
    ${ZLIB_LIBRARIES}
)

install(TARGETS ht2-demul ht2-primer-trim ht2-convert ht2-stat ht2-trim ht2-filter ht2-sample ht2-overlap ht2-rename htio2
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(PROGRAMS ht2-stat-draw.pl DESTINATION bin)
install(FILES ${CMAKE_BINARY_DIR}/src/htio2/config.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/htio2)
install(DIRECTORY htio2/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/htio2 FILES_MATCHING PATTERN "*.h")
