OpenCV 3.1.0 won't compile with CMake
<p>I know there are many supposed duplicates for this matter, but since none of the answers worked for me I'd rather ask another question.</p>

<p>My project won't compile with CMake:</p>

<blockquote>
  <p>Found package configuration file: /usr/share/OpenCV/OpenCVConfig.cmake but it set OpenCV_FOUND to FALSE so package "OpenCV" is considered to be NOT FOUND.</p>
</blockquote>

<p>My CMakeLists.txt is as follows:</p>

<pre><code>cmake_minimum_required( VERSION 2.8 )
project( Tests )
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11" )

if(WIN32)
#    set( CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH} C:\\OpenCV" )
    set( OpenCV_DIR "C:\\OpenCV\\build" )
elseif(UNIX)
    set( OpenCV_DIR "/usr/share/OpenCV" )
    set( PKG_CONFIG_PATH "/usr/lib/pkgconfig" )
endif()

find_package( OpenCV REQUIRED )
if( OpenCV_FOUND )
    message( "Found OpenCV" )
    message( "Includes: " ${OpenCV_INCLUDE_DIRS} )
else()
    message( "OpenCV not found, woot" )
endif( OpenCV_FOUND )

add_executable( Test ShapeRecognition/prog.cpp )
target_link_libraries( Test ${OpenCV_LIBS} )
</code></pre>

<p>The error happens on the line find_package(OpenCV REQUIRED), thus none of the messages below are displayed anyway.</p>

<p>BUT while compiling in console, with the command:</p>

<pre><code>g++ -o prog -std=c++11 `pkg-config --libs --cflags opencv` prog.cpp 
</code></pre>

<p>The compilation happens without a problem, and the program can be launched perfectly fine.</p>

<p>The command "pkg-config --libs opencv" gives me (a bit long, I agree):</p>

<blockquote>
  <p>-lopencv_stitching -lopencv_superres -lopencv_videostab -lopencv_aruco -lopencv_bgsegm -lopencv_bioinspired -lopencv_ccalib -lopencv_dnn -lopencv_dpm -lopencv_fuzzy -lopencv_line_descriptor -lopencv_optflow -lopencv_plot -lopencv_reg -lopencv_saliency -lopencv_stereo -lopencv_structured_light -lopencv_rgbd -lopencv_surface_matching -lopencv_tracking -lopencv_datasets -lopencv_text -lopencv_face -lopencv_xfeatures2d -lopencv_shape -lopencv_video -lopencv_ximgproc -lopencv_calib3d -lopencv_features2d -lopencv_flann -lopencv_xobjdetect -lopencv_objdetect -lopencv_ml -lopencv_xphoto -lopencv_highgui -lopencv_videoio -lopencv_imgcodecs -lopencv_photo -lopencv_imgproc -lopencv_core</p>
</blockquote>

<p>The command "pkg-config --cflags opencv" simply gives me (CMAKE_INSTALL_PREFIX is set to /usr):</p>

<blockquote>
  <p>-I/usr/include/opencv</p>
</blockquote>

<p>If anyone has a solution, I'd gladly take it.</p>