# FindVmb.cmake - locate the Allied Vision Vimba X SDK (VmbC + VmbCPP).
#
# The Vimba X SDK is proprietary and must be installed manually from Allied
# Vision (https://www.alliedvision.com/en/products/software/vimba-x-sdk/).
# It is NOT available through any package manager.
#
# Search hints (any one is enough):
#   -DVMB_HOME=/opt/VimbaX_2024-1      (CMake cache variable)
#   export VIMBA_X_HOME=/opt/VimbaX... (environment variable)
#
# Provides imported targets:
#   Vmb::VmbC    Vmb::VmbCPP
# and variables: Vmb_FOUND, Vmb_INCLUDE_DIR, Vmb_C_LIBRARY, Vmb_CPP_LIBRARY

set(_vmb_hints
  "${VMB_HOME}"
  "$ENV{VMB_HOME}"
  "$ENV{VIMBA_X_HOME}"
  "$ENV{VIMBAX_HOME}"
  /opt/VimbaX
  /opt/VimbaX_2025-1
  /opt/VimbaX_2024-1
  /opt/vimbax
  /usr/local/VimbaX
)

find_path(Vmb_INCLUDE_DIR
  NAMES VmbCPP/VmbCPP.h VmbC/VmbC.h
  HINTS ${_vmb_hints}
  PATH_SUFFIXES api/include include
)

find_library(Vmb_C_LIBRARY
  NAMES VmbC
  HINTS ${_vmb_hints}
  PATH_SUFFIXES api/lib lib lib64
)

find_library(Vmb_CPP_LIBRARY
  NAMES VmbCPP
  HINTS ${_vmb_hints}
  PATH_SUFFIXES api/lib lib lib64
)

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(Vmb
  REQUIRED_VARS Vmb_INCLUDE_DIR Vmb_C_LIBRARY Vmb_CPP_LIBRARY
  FAIL_MESSAGE
    "Vimba X SDK not found. Install it from Allied Vision and set -DVMB_HOME=<sdk_root> \
or the VIMBA_X_HOME environment variable. To build without camera support, \
configure with -DWITH_VIMBA=OFF."
)

if(Vmb_FOUND)
  if(NOT TARGET Vmb::VmbC)
    add_library(Vmb::VmbC UNKNOWN IMPORTED)
    set_target_properties(Vmb::VmbC PROPERTIES
      IMPORTED_LOCATION "${Vmb_C_LIBRARY}"
      INTERFACE_INCLUDE_DIRECTORIES "${Vmb_INCLUDE_DIR}")
  endif()
  if(NOT TARGET Vmb::VmbCPP)
    add_library(Vmb::VmbCPP UNKNOWN IMPORTED)
    set_target_properties(Vmb::VmbCPP PROPERTIES
      IMPORTED_LOCATION "${Vmb_CPP_LIBRARY}"
      INTERFACE_INCLUDE_DIRECTORIES "${Vmb_INCLUDE_DIR}"
      INTERFACE_LINK_LIBRARIES "Vmb::VmbC")
  endif()
endif()

mark_as_advanced(Vmb_INCLUDE_DIR Vmb_C_LIBRARY Vmb_CPP_LIBRARY)
