# Helper: register a strategy implementation behind its BUILD_* flag.
#
# Usage:
#   gps_denied_register_strategy(
#     NAME my_strategy
#     FLAG BUILD_MY_STRATEGY
#     SOURCES src1.cpp src2.cpp
#   )
#
# When the FLAG is OFF, the strategy target is NOT created at all. The
# composition-root validator (Python side) refuses to wire a strategy whose
# flag is OFF — see `src/gps_denied_onboard/runtime_root.py`.

function(gps_denied_register_strategy)
  cmake_parse_arguments(_ARG "" "NAME;FLAG" "SOURCES;LINK_LIBRARIES" ${ARGN})
  if(NOT _ARG_NAME OR NOT _ARG_FLAG)
    message(FATAL_ERROR "gps_denied_register_strategy: NAME and FLAG are required.")
  endif()
  if(NOT ${${_ARG_FLAG}})
    message(STATUS "[strategy] Skipping ${_ARG_NAME} (${_ARG_FLAG}=OFF)")
    return()
  endif()
  add_library(${_ARG_NAME} STATIC ${_ARG_SOURCES})
  target_include_directories(${_ARG_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
  if(_ARG_LINK_LIBRARIES)
    target_link_libraries(${_ARG_NAME} PUBLIC ${_ARG_LINK_LIBRARIES})
  endif()
  message(STATUS "[strategy] Registered ${_ARG_NAME} (${_ARG_FLAG}=ON)")
endfunction()
