# Builds the examples against this SDK: cmake -S examples -B build && cmake --build build
cmake_minimum_required(VERSION 3.10)
project(bacore_examples C)

get_filename_component(BACORE_SDK "${CMAKE_CURRENT_SOURCE_DIR}/.." ABSOLUTE)
add_library(bacore SHARED IMPORTED)
set_target_properties(bacore PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${BACORE_SDK}/include")
if (WIN32)
    set_target_properties(bacore PROPERTIES
        IMPORTED_LOCATION "${BACORE_SDK}/bin/bacore.dll"
        IMPORTED_IMPLIB "${BACORE_SDK}/lib/bacore.lib")
elseif (APPLE)
    set_target_properties(bacore PROPERTIES IMPORTED_LOCATION "${BACORE_SDK}/lib/libbacore.dylib")
else ()
    set_target_properties(bacore PROPERTIES IMPORTED_LOCATION "${BACORE_SDK}/lib/libbacore.so")
endif ()

foreach (example connect read_eeg)
    add_executable(${example} ${example}.c)
    target_link_libraries(${example} PRIVATE bacore)
    if (WIN32)
        # Windows finds DLLs next to the executable.
        add_custom_command(TARGET ${example} POST_BUILD
            COMMAND ${CMAKE_COMMAND} -E copy_if_different "${BACORE_SDK}/bin/bacore.dll" "$<TARGET_FILE_DIR:${example}>")
    endif ()
endforeach ()
