cmake_minimum_required(VERSION 3.24)
project(copper_orchard_probe LANGUAGES CXX OBJCXX)
if(NOT APPLE)
  message(FATAL_ERROR "Copper Orchard requires macOS and the Apple SDK")
endif()
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_OBJCXX_STANDARD 23)
set(CMAKE_OBJCXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_OBJCXX_EXTENSIONS OFF)
add_executable(orchard-probe orchard_probe.mm)
target_compile_options(orchard-probe PRIVATE -fobjc-arc -Wall -Wextra -Wpedantic)
target_link_libraries(orchard-probe PRIVATE "-framework Foundation" "-framework Metal")
set(METAL_CPP_INCLUDE_DIR "" CACHE PATH "Path containing Foundation/ and Metal/ metal-cpp headers")
if(METAL_CPP_INCLUDE_DIR)
  add_executable(orchard-cpp-device metal_cpp_device.cpp)
  target_include_directories(orchard-cpp-device SYSTEM PRIVATE "${METAL_CPP_INCLUDE_DIR}")
  target_compile_options(orchard-cpp-device PRIVATE -Wall -Wextra -Wpedantic)
  target_link_libraries(orchard-cpp-device PRIVATE "-framework Foundation" "-framework Metal")
  add_executable(orchard-window orchard_window.mm window_renderer.cpp)
  target_include_directories(orchard-window SYSTEM PRIVATE "${METAL_CPP_INCLUDE_DIR}")
  target_compile_options(orchard-window PRIVATE -Wall -Wextra -Wpedantic -Wconversion -Wshadow
    "$<$<COMPILE_LANGUAGE:OBJCXX>:-fobjc-arc>")
  target_link_libraries(orchard-window PRIVATE "-framework Cocoa" "-framework MetalKit"
    "-framework Foundation" "-framework Metal" "-framework QuartzCore")
endif()
enable_testing()
add_test(NAME bounded-compute COMMAND orchard-probe)
