# SPDX-FileCopyrightText: 2011-2019 Disney Enterprises, Inc.
# SPDX-License-Identifier: LicenseRef-Apache-2.0
# SPDX-FileCopyrightText: 2020 L. E. Segovia <amy@amyspark.me>
# SPDX-License-Identifier: GPL-3.0-or-later


if (GTest_FOUND AND PNG_FOUND AND Python3_FOUND)
    message("-- Found PNG library: " ${PNG_LIBRARIES})
    message("-- Found Python executable: " ${Python3_EXECUTABLE})

    set(TEST_DEST "share/test/KSeExpr")

    # generate test cases for example developer expressions
    set (GENERATE_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/genImageTestFile.py")
    set (EXAMPLE_DIR ${CMAKE_INSTALL_PREFIX}/share/KSeExpr/demos/imageSynth/examples)
    if (EXISTS ${EXAMPLE_DIR})
        set (EXAMPLE_TESTS "testSeExprExamples.cpp")
        add_custom_command(
            SOURCE ${EXAMPLE_DIR}
            COMMAND ${GENERATE_SCRIPT}
            ARGS "${EXAMPLE_DIR}" "${EXAMPLE_TESTS}"
            OUTPUT ${EXAMPLE_TESTS}
            DEPENDS ${GENERATE_SCRIPT} ${EXAMPLE_DIR})
    endif()

    add_executable(basicTests "basic.cpp")
    target_include_directories(basicTests PRIVATE ${GTEST_INCLUDE_DIR})
    target_link_libraries(basicTests KSeExpr GTest::GTest GTest::Main)
    install(TARGETS basicTests DESTINATION ${TEST_DEST})
    add_test(NAME basicTests COMMAND basicTests)

    add_executable(imageTests "imageTests.cpp" ${EXAMPLE_TESTS})
    target_include_directories(imageTests PRIVATE ${PNG_INCLUDE_DIR})
    target_include_directories(imageTests PRIVATE ${GTEST_INCLUDE_DIR})
    target_link_libraries(imageTests KSeExpr GTest::GTest GTest::Main ${PNG_LIBRARIES})
    install(TARGETS imageTests DESTINATION ${TEST_DEST})
    add_test(NAME imageTests COMMAND imageTests)

    add_executable(stringTests "string.cpp")
    target_include_directories(stringTests PRIVATE ${GTEST_INCLUDE_DIR})
    target_link_libraries(stringTests KSeExpr GTest::GTest GTest::Main)
    install(TARGETS stringTests DESTINATION ${TEST_DEST})
    add_test(NAME stringTests COMMAND stringTests)

    add_executable(typeTests "typeTests.cpp")
    target_include_directories(typeTests PRIVATE ${GTEST_INCLUDE_DIR})
    target_link_libraries(typeTests KSeExpr GTest::GTest GTest::Main)
    install(TARGETS typeTests DESTINATION ${TEST_DEST})
    add_test(NAME typeTests COMMAND typeTests)

    add_executable(typePrinter "TypePrinter.cpp")
    target_link_libraries(typePrinter KSeExpr)
    install(TARGETS typePrinter DESTINATION ${TEST_DEST})

    add_executable(multiTests "multiTests.cpp")
    target_include_directories(multiTests PRIVATE ${GTEST_INCLUDE_DIR})
    target_link_libraries(multiTests KSeExpr GTest::GTest GTest::Main)
    install(TARGETS multiTests DESTINATION ${TEST_DEST})
    add_test(NAME multiTests COMMAND multiTests)

    add_executable(dirtSimple "dirtSimple.cpp")
    target_include_directories(dirtSimple PRIVATE ${PNG_INCLUDE_DIR})
    target_link_libraries(dirtSimple KSeExpr ${PNG_LIBRARIES})
    install(TARGETS dirtSimple DESTINATION ${TEST_DEST})
    add_test(NAME dirtSimple COMMAND dirtSimple)

    if (ENABLE_LLVM_BACKEND)
        add_executable(BlockTests "BlockTests.cpp")
        target_include_directories(BlockTests PRIVATE ${PNG_INCLUDE_DIR})
        target_link_libraries(BlockTests KSeExpr ${PNG_LIBRARIES})
        install(TARGETS BlockTests DESTINATION ${TEST_DEST})
        add_test(NAME BlockTests COMMAND BlockTests)
    endif()

    add_executable(VarBlockExample VarBlockExample.cpp)
    target_link_libraries(VarBlockExample KSeExpr)
    install(TARGETS VarBlockExample DESTINATION ${TEST_DEST})

    if (ENABLE_SLOW_TESTS)
        add_test(NAME VarBlockExample COMMAND VarBlockExample)
    endif()
endif()
