#[[
CMake build script for ACM Collected Algorithms: DCUHRE and DQUAD
Copyright (C) 2024  Tim Kaune

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this program.  If not, see
<https://www.gnu.org/licenses/>.
]]

set(DCUHRE_TESTS ${DCUHRE_TEST_SINGLE_FILENAMES} ${DCUHRE_TEST_DOUBLE_FILENAMES})

foreach (DCUHRE_TEST ${DCUHRE_TESTS})
    add_executable("DCUHRE_${DCUHRE_TEST}")
    target_sources("DCUHRE_${DCUHRE_TEST}" PRIVATE "${DCUHRE_SOURCE_DIR}/${DCUHRE_TEST}.c")
    target_link_libraries("DCUHRE_${DCUHRE_TEST}" PRIVATE DCUHRE Netlib::libf2cWithFortranMain m)

    target_compile_features("DCUHRE_${DCUHRE_TEST}" PRIVATE c_std_90)
    target_compile_options("DCUHRE_${DCUHRE_TEST}" PRIVATE -w)
    set_target_properties("DCUHRE_${DCUHRE_TEST}" PROPERTIES C_STANDARD 90)

    if (BUILD_SHARED_LIBS)
        set_target_properties("DCUHRE_${DCUHRE_TEST}" PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
    else ()
        target_link_options(
            "DCUHRE_${DCUHRE_TEST}"
            PRIVATE
            $<$<NOT:$<PLATFORM_ID:Darwin>>:-static>
        )
    endif ()

    add_test(NAME "DCUHRE_${DCUHRE_TEST}" COMMAND "DCUHRE_${DCUHRE_TEST}")
    add_dependencies(check "DCUHRE_${DCUHRE_TEST}")
endforeach ()
