# Get default values for PROSILICA_ROOT and PROSILICA_LAYOUT

IF(WIN32)
  SET(PROSILICA_ROOT "C:\\Program Files\\Prosilica\\GigESDK")
ELSE(WIN32)
  IF(APPLE)
    SET(PROSILICA_ROOT "/Prosilica GigE SDK")
  ELSE(APPLE)
    # Assume headers and libraries are installed in FHS locations
    SET(PROSILICA_ROOT "/usr")
  ENDIF(APPLE)
ENDIF(WIN32)

# defaults for PROSILICA_LAYOUT
IF(WIN32)
  SET(PROSILICA_LAYOUT "prosilica")
ELSE(WIN32)
  IF(APPLE)
    SET(PROSILICA_LAYOUT "prosilica")
  ELSE(APPLE)
    # Assume headers and libraries are installed in FHS locations
    SET(PROSILICA_LAYOUT "FHS")
  ENDIF(APPLE)
ENDIF(WIN32)

#############################################
# Environment variable overrides

SET(PROSILICA_TEST_INCLUDE_PATHS "$ENV{PROSILICA_TEST_INCLUDE_PATHS}")
IF(PROSILICA_TEST_INCLUDE_PATHS STREQUAL "")
  # not set with env var, use defaults
  IF(PROSILICA_LAYOUT STREQUAL "prosilica")
    SET(PROSILICA_TEST_INCLUDE_PATHS ${PROSILICA_ROOT}/inc-pc)
  ELSE(PROSILICA_LAYOUT STREQUAL "prosilica")
    IF(NOT PROSILICA_LAYOUT STREQUAL "FHS")
      MESSAGE(FATAL_ERROR "unknown PROSILICA_LAYOUT " ${PROSILICA_LAYOUT})
    ENDIF(NOT PROSILICA_LAYOUT STREQUAL "FHS")
    SET(PROSILICA_TEST_INCLUDE_PATHS ${PROSILICA_ROOT}/include)
  ENDIF(PROSILICA_LAYOUT STREQUAL "prosilica")
ENDIF(PROSILICA_TEST_INCLUDE_PATHS STREQUAL "")

SET(PROSILICA_TEST_LIB_PATHS "$ENV{PROSILICA_TEST_LIB_PATHS}")
IF(PROSILICA_TEST_LIB_PATHS STREQUAL "")
  # not set with env var, use defaults
  IF(PROSILICA_LAYOUT STREQUAL "prosilica")
    SET(PROSILICA_TEST_LIB_PATHS ${PROSILICA_ROOT}/lib-pc)
  ELSE(PROSILICA_LAYOUT STREQUAL "prosilica")
    IF(NOT PROSILICA_LAYOUT STREQUAL "FHS")
      MESSAGE(FATAL_ERROR "unknown PROSILICA_LAYOUT " ${PROSILICA_LAYOUT})
    ENDIF(NOT PROSILICA_LAYOUT STREQUAL "FHS")
    SET(PROSILICA_TEST_LIB_PATHS ${PROSILICA_ROOT}/lib)
  ENDIF(PROSILICA_LAYOUT STREQUAL "prosilica")
ENDIF(PROSILICA_TEST_LIB_PATHS STREQUAL "")

#############################################
# No more environment variable settings

IF(NOT "$ENV{PROSILICA_CMAKE_DEBUG}" STREQUAL "")
  MESSAGE("PROSILICA_TEST_INCLUDE_PATHS " ${PROSILICA_TEST_INCLUDE_PATHS})
  MESSAGE("PROSILICA_TEST_LIB_PATHS " ${PROSILICA_TEST_LIB_PATHS})
ENDIF(NOT "$ENV{PROSILICA_CMAKE_DEBUG}" STREQUAL "")

FIND_PATH(PROSILICA_GIGE_INCLUDE_PATH PvApi.h
  ${PROSILICA_TEST_INCLUDE_PATHS}
)

FIND_LIBRARY(PROSILICA_GIGE_LIBRARY PvAPI ${PROSILICA_TEST_LIB_PATHS})

INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PROSILICA_GIGE DEFAULT_MSG
                                                 PROSILICA_GIGE_INCLUDE_PATH
                                                 PROSILICA_GIGE_LIBRARY)
SET(PROSILICA_GIGE_LIBRARIES ${PROSILICA_GIGE_LIBRARY})
SET(PROSILICA_GIGE_INCLUDE_DIRS ${PROSILICA_GIGE_INCLUDE_PATH})

IF(APPLE)
  SET(PROSILICA_GIGE_LIBRARIES
    ${PROSILICA_GIGE_LIBRARIES}
    "-framework CoreFoundation"
    )
ENDIF(APPLE)
