####################################################
##
##  Select the appropriate coroutine source files
##
####################################################

# List all coroutine source files. This will be exported to the parent scope
# at the end of this CMakeLists.txt file.
set (coroutine_SOURCES
        coroutine/coroutine.cpp
        coroutine/coroutinemutex.cpp
        coroutine/coroutinewaitcondition.cpp
        coroutine/coroutinecont.cpp
        )

# Add architecture-specific co-routine source files
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR APPLE)
    if (WIN32)
        list (APPEND coroutine_SOURCES
                coroutine/backend/switchstack_gcc_32_win.s
                coroutine/backend/initializestack_32.cpp
                )
        message (STATUS "LGPL - Coroutines using switchstack_gcc_32_win.s")

    elseif (ALLINEA_ARCH MATCHES "x86_64")
        list (APPEND coroutine_SOURCES
                coroutine/backend/switchstack_gcc_64_linux_mac.s
                coroutine/backend/initializestack_64_linux_mac.cpp
                )
        message (STATUS "LGPL - Coroutines using switchstack_gcc_64_linux_mac.s")

    elseif (ALLINEA_ARCH MATCHES "x86")
        list (APPEND coroutine_SOURCES
                coroutine/backend/switchstack_gcc_32_linux_mac.s
                coroutine/backend/initializestack_32.cpp
                )
        message (STATUS "LGPL - Coroutines using switchstack_gcc_32_linux_mac.s")

    elseif (ALLINEA_ARCH MATCHES "armv7l")
        list (APPEND coroutine_SOURCES
                coroutine/backend/switchstack_gcc_arm_linux_mac.s
                coroutine/backend/initializestack_arm.cpp
                )
        message (STATUS "LGPL - Coroutines using switchstack_gcc_arm_linux_mac.s")

    elseif (ALLINEA_ARCH MATCHES "aarch64")
        list (APPEND coroutine_SOURCES
                coroutine/backend/initializestack_aarch64.cpp
                coroutine/backend/switchstack_gcc_aarch64_linux_mac.s
                )
        message (STATUS "LGPL - Coroutines using switchstack_gcc_aarch64_linux_mac.s")

    elseif (ALLINEA_ARCH MATCHES "s64fx")
        list (APPEND coroutine_SOURCES
                coroutine/backend/switchstack_s64fx.s
                coroutine/backend/initializestack_s64fx.cpp
                )
        message (STATUS "LGPL - Coroutines using switchstack_s64fx.s")

    elseif (ALLINEA_ARCH STREQUAL "k1om")
        list (APPEND coroutine_SOURCES
                coroutine/backend/switchstack_gcc_k1om_linux.s
                coroutine/backend/initializestack_k1om_linux.cpp
                )
        message (STATUS "LGPL - Coroutines using switchstack_gcc_k1om_linux.s")

    else ()
        message (FATAL_ERROR "LGPL - Sorry, there are no lgpl/coroutines/backend bindings for your current "
                             "architecture (ALLINEA_ARCH - ${ALLINEA_ARCH}). "
                             "Check ALLINEA_ARCH is set correctly, or start writing assembler!")
    endif ()

elseif (WIN32 AND CMAKE_CXX_COMPILER MATCHES "cl")
    list (APPEND coroutine_SOURCES
            coroutine/backend/switchstack_msvc.cpp
            coroutine/backend/initializestack_msvc.cpp
            )
    message (STATUS "LGPL - Coroutines using switchstack_msvc.cpp")

else ()
    message (FATAL_ERROR "LGPL - Sorry, there are no lgpl/coroutines/backend bindings for your current "
                         "architecture (ALLINEA_ARCH - ${ALLINEA_ARCH}) and compiler (${CMAKE_CXX_COMPILER}). "
                         "Try compiling with g++ instead, or start writing assembler!")
endif ()

# Export the list of coroutine sources to the parent scope
set (coroutine_SOURCES ${coroutine_SOURCES} PARENT_SCOPE)
