set (SRC
  main.c
  prosilica.c       prosilica.h
  viewer.c          viewer.h
  burst.c           burst.h
  )

# find libPvAPI library
include_directories (../../third-party/prosilica/inc-pc)
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
  set (PROSILICA_BIN_DIR "x64")
  set (PROSILICA_LIB_DIR "x64")
  add_definitions (-D_LINUX -D_x64)
elseif (CMAKE_SYSTEM_PROCESSOR STREQUAL "i386")
  set (PROSILICA_BIN_DIR "i386")
  set (PROSILICA_LIB_DIR "x86")
  add_definitions (-D_LINUX -D_x86)
else ()
  message (SEND_ERROR "Uknown CMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}")
endif ()
find_library (LIB_PvAPI PvAPI 
  PATHS ../../third-party/prosilica/bin-pc
  PATH_SUFFIXES ${PROSILICA_LIB_DIR}
  )


# build exe)
add_executable (prosilica ${SRC})
target_link_libraries (prosilica common lcmtypes ${LIB_PvAPI} ${LIB_PTHREAD} ${LIB_TIFF} ${LIB_IMAGEMAGICK} ${LIB_OPENCV})




#///////////////////////////////////////////////////////////////////////////////
# build prosilica example code?
#-------------------------------------------------------------------------------
set (EXAMPLES_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../third-party/prosilica/examples)
option (BUILD_PROSILICA_EXAMPLES "Build Prosilica example code?" OFF)
if (BUILD_PROSILICA_EXAMPLES)

  # find libImagelib library
  string (SUBSTRING ${GCC_VERSION} 0 3 VER)
  find_library (LIB_Imagelib Imagelib
    PATHS ../../third-party/prosilica/lib-pc
    PATH_SUFFIXES ${PROSILICA_LIB_DIR}/${VER}
    )
  if (NOT LIB_Imagelib)
    message (SEND_ERROR "WARNING: Prosilica SDK examples do not have a version of libImagelib.a that matches your version of gcc, which is ${VER}.  CMake config will try linking against Prosilica 4.2 version of libImagelib.a, but this may cause errors.")
    find_library (LIB_Imagelib Imagelib
      PATHS ../../third-party/prosilica/lib-pc
      PATH_SUFFIXES ${PROSILICA_LIB_DIR}/4.2
      )
  endif ()

  find_library (LIB_AA aa
    DOC "Path to ascii art library."
    )
  if (NOT LIB_AA)
    message (SEND_ERROR "on ubuntu `sudo apt-get install libaa1-dev`")
  endif ()

  # 1-level deep example programs
  file (GLOB EXAMPLE_DIRS RELATIVE ${EXAMPLES_PATH} ${EXAMPLES_PATH}/*)  
  foreach (EXAMPLE_DIR ${EXAMPLE_DIRS})
    file (GLOB EXAMPLE_SRC ${EXAMPLES_PATH}/${EXAMPLE_DIR}/*.cpp ${EXAMPLES_PATH}/${EXAMPLE_DIR}/*.[c,h])
    if (EXAMPLE_SRC)
      add_executable (${EXAMPLE_DIR} ${EXAMPLE_SRC})
      target_link_libraries (${EXAMPLE_DIR} ${LIB_PvAPI} ${LIB_Imagelib} ${LIB_TIFF} aa)
      set_target_properties (${EXAMPLE_DIR} PROPERTIES 
        RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}/Prosilica"
        )
    endif ()
  endforeach ()

  # SampleViewer
  find_package (wxWidgets COMPONENTS base core)
  if (wxWidgets_FOUND)
    include (${wxWidgets_USE_FILE})
    include_directories (${EXAMPLES_PATH}/SampleViewer/inc)
    include_directories (${EXAMPLES_PATH}/SampleViewer/rsc)
    file (GLOB EXAMPLE_SRC ${EXAMPLES_PATH}/SampleViewer/src/*.cpp ${EXAMPLES_PATH}/SampleViewer/inc/*.h)
    add_executable (SampleViewer ${EXAMPLE_SRC})
    target_link_libraries (SampleViewer ${LIB_PvAPI} ${LIB_Imagelib} ${LIB_TIFF} ${wxWidgets_LIBRARIES})
    set_target_properties (SampleViewer PROPERTIES 
      RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}/Prosilica"
      COMPILE_FLAGS "-Wno-write-strings -Wno-sign-compare"
      )
  else ()
    message (SEND_ERROR "on ubuntu `sudo apt-get install libwxgtk2.8-dev`")
  endif ()


endif ()
