Predator's Vision

画像処理、3D点群処理、DeepLearning等の備忘録

OpenCVを使いたいときのcmakeの書き方

次のように書けばよい。かなりシンプル。link_directoriesの指定は不要。
なぜならば、${OpenCV_LIBS}でライブラリへの絶対パスが指定されるため

OpenCVが見つかった場合のみプロジェクトを作成したければif(DEFINED ${OpenCV_VERSION})でadd_executableやtarget_link_librariesを囲めばよい

cmake_minimum_required(VERSION 2.8 FATAL_ERROR)

project(opencv_project)

find_package(OpenCV 2.4 REQUIRED)

include_directories(${OpenCV_INCLUDE_DIRS})

add_executable (project1 hoge.cpp)
target_link_libraries (project1 ${OpenCV_LIBS})