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

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(DQUAD_TESTS ${DQUAD_TEST_SINGLE_FILENAMES} ${DQUAD_TEST_DOUBLE_FILENAMES})

foreach (DQUAD_TEST ${DQUAD_TESTS})
    add_executable("DQUAD_${DQUAD_TEST}")
    target_sources("DQUAD_${DQUAD_TEST}" PRIVATE "${DQUAD_SOURCE_DIR}/${DQUAD_TEST}.c")
    target_link_libraries("DQUAD_${DQUAD_TEST}" PRIVATE DQUAD Netlib::libf2cWithFortranMain m)

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

    add_test(NAME "DQUAD_${DQUAD_TEST}" COMMAND "DQUAD_${DQUAD_TEST}")
endforeach ()
