cmake_minimum_required(VERSION 3.20)
project(base01_lane_a LANGUAGES CXX)
if(NOT DEFINED BASE01_SOURCE OR NOT DEFINED BASE01_BUILD)
  message(FATAL_ERROR "Supply pristine audited BASE01_SOURCE and its separately built BASE01_BUILD")
endif()
# No add_subdirectory, source overlay, benchmark registration, or frozen experiment.
# Reuse only archives produced by the audited project's normal CMake targets.
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(CMAKE_CXX_FLAGS MATCHES "flto" OR CMAKE_CXX_FLAGS_RELEASE MATCHES "flto")
  message(FATAL_ERROR "Lane A batch retention requires LTO disabled")
endif()
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION OFF)
add_executable(base01_lane_a runner.cpp kernels.cpp)
target_include_directories(base01_lane_a PRIVATE "${BASE01_SOURCE}/include" "${BASE01_SOURCE}/tests/cpp")
file(GLOB archives "${BASE01_BUILD}/libt81_*.a")
if(NOT archives)
  message(FATAL_ERROR "Build audited correctness targets first")
endif()
# Repeat static archives to resolve their mutual references on GNU ld as well as ld64.
target_link_libraries(base01_lane_a PRIVATE ${archives} ${archives} ${archives})
if(UNIX AND NOT APPLE)
  target_link_libraries(base01_lane_a PRIVATE pthread dl)
endif()
if(APPLE)
  get_filename_component(compiler_bin "${CMAKE_CXX_COMPILER}" DIRECTORY)
  get_filename_component(compiler_root "${compiler_bin}" DIRECTORY)
  if(EXISTS "${compiler_root}/lib/c++/libc++.dylib")
    target_link_options(base01_lane_a PRIVATE "-L${compiler_root}/lib/c++")
  endif()
endif()
