cmake_minimum_required(VERSION 2.8.7)
if(POLICY CMP0046)
  cmake_policy(SET CMP0046 NEW)
endif()
if(POLICY CMP0054)
  cmake_policy(SET CMP0054 NEW)
endif()

project(Caffe-Examples C CXX)

find_package(Gflags REQUIRED)
find_package(Protobuf REQUIRED)
find_package(OpenCV REQUIRED)
find_package(Caffe REQUIRED)

set(CMAKE_CXX_FLAGS "-DUSE_OPENCV")

file(GLOB_RECURSE examples_srcs "${PROJECT_SOURCE_DIR}/*.cpp")

foreach(source_file ${examples_srcs})
  # get file name
  get_filename_component(name ${source_file} NAME_WE)
    
  # get folder name
  get_filename_component(path ${source_file} PATH)
  get_filename_component(folder ${path} NAME_WE)
    
  add_executable(${name} ${source_file})
  target_include_directories(${name} PUBLIC ${OpenCV_INCLUDE_DIRS})
  target_link_libraries(${name} ${Caffe_LINK} ${OpenCV_LIBS} ${Caffe_LIBRARIES} -lglog -lprotobuf)

endforeach()
