cmake_minimum_required(VERSION 3.0)

project(hfg-webcam-particles LANGUAGES CXX)

list(APPEND CMAKE_CXX_FLAGS "-std=c++14 -Wall -pthread")

add_executable(webcam-particles
  source/Application.cpp
  source/Application.hpp
  source/main.cpp
  source/main.hpp
  source/Resources.cpp
  source/Resources.hpp
  source/ThreadSyncTripleBuffer.hpp
  source/Webcam.cpp
  source/Webcam.hpp
)

target_include_directories(webcam-particles PRIVATE /usr/include/SDL2)
target_link_libraries(webcam-particles opencv_highgui opencv_imgproc opencv_core SDL2 GL m)

add_custom_command(TARGET webcam-particles POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory "${PROJECT_SOURCE_DIR}/resource" "$<TARGET_FILE_DIR:webcam-particles>")

cmake_minimum_required(VERSION 3.0)

project(hfg-webcam-particles LANGUAGES CXX)

find_package(OpenCV REQUIRED)

list(APPEND CMAKE_CXX_FLAGS "-std=c++14 -Wall -pthread")

add_executable(webcam-particles
  source/Application.cpp
  source/Application.hpp
  source/main.cpp
  source/main.hpp
  source/Resources.cpp
  source/Resources.hpp
  source/ThreadSyncTripleBuffer.hpp
  source/Webcam.cpp
  source/Webcam.hpp
)

target_include_directories(webcam-particles PRIVATE /usr/include/SDL2)
target_link_libraries(webcam-particles ${OpenCV_LIBS} SDL2 GL m)

add_custom_command(TARGET webcam-particles POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory "${PROJECT_SOURCE_DIR}/resource" "$<TARGET_FILE_DIR:webcam-particles>")

Use CMake find_package to find OpenCV
Use CMake find_package to find OpenCV

I actually investigated where a qualifying FindOpenCV.cmake file comes from.
It seems it's not included with cmake by default (see
https://cmake.org/cmake/help/v3.9/manual/cmake-modules.7.html). But since the
OpenCV docs don't mention anything about it
(http://docs.opencv.org/2.4/doc/tutorials/introduction/linux_gcc_cmake/linux_gcc_cmake.html)
and it worked out of the box on my system, I think it's safe to assume this
'just works' even if we don't have any idea why. CMake is magic.
