[CMake] find_package() Config mode iteration gravely broken (Mac OpenCV KISS installation fails)

Andreas Mohr andi at lisas.de
Tue Apr 30 09:03:23 EDT 2013


Hi,

tried to grab OpenCV on Mac OS 10.6 (via standard macports install),
expected it to be a walk in the park.
Imagine my surprise when this failed persistently and stubbornly.

Turns out internet is full of reports of OpenCV Config failure
(and, I have to say, the sufficiently condescending tone of OpenCV website
and its non-editability (immutable page / restricted registration) DOES NOT HELP).
And those multiple *contemporary* reports/comments (stack overflow)
are SHOCKINGLY uninformed (even a 3 minute cross reading of the relevant docs
would have told people that there's something other than Module mode only,
yet everybody is raising the complaint that "there is no FindOpenCV.cmake"!).



minimum-code reproducer sample (executed on current CMake master):

find_package_opencv/CMakeLists.txt:

cmake_minimum_required(VERSION 2.6)

# Fully UNDOCUMENTED debug helper var (I'm going to correct this
# in my next round of submissions):
set(CMAKE_FIND_DEBUG_MODE 1)

project(find_package_opencv CXX)

# opensnoop -n -a marker helper:
file(WRITE /tmp/PRE_FIND_PACKAGE_CALL "")

# Does not matter whether NO_MODULE is specified...
find_package(OpenCV REQUIRED NO_MODULE)



$ cmake ../find_package_opencv
Checking framework prefix [/opt/local/]
Consider /opt/local
Consider /opt/local
Consider /opt/local
Consider /opt/local
Checking framework prefix [/sw/]
Consider /sw
Consider /sw
Consider /sw
Consider /sw
Checking framework prefix [/usr/]
Consider /usr
Consider /usr
Consider /usr
Consider /usr
Checking framework prefix [/]
Consider 
Consider 
Consider 
Consider 
Checking framework prefix [/usr/local/]
Consider /usr/local
Consider /usr/local
Consider /usr/local
Consider /usr/local
Checking framework prefix [/usr/X11/]
Consider /usr/X11
Consider /usr/X11
Consider /usr/X11
Consider /usr/X11
Checking framework prefix [/Users/USERNAME/Library/Frameworks/]
Consider /Users/USERNAME/Library/Frameworks
Consider /Users/USERNAME/Library/Frameworks
Consider /Users/USERNAME/Library/Frameworks
Consider /Users/USERNAME/Library/Frameworks
Checking framework prefix [/Library/Frameworks/]
Consider /Library/Frameworks
Consider /Library/Frameworks
Consider /Library/Frameworks
Consider /Library/Frameworks
Checking framework prefix [/Network/Library/Frameworks/]
Consider /Network/Library/Frameworks
Consider /Network/Library/Frameworks
Consider /Network/Library/Frameworks
Consider /Network/Library/Frameworks
Checking framework prefix [/System/Library/Frameworks/]
Consider /System/Library/Frameworks
Consider /System/Library/Frameworks
Consider /System/Library/Frameworks
Consider /System/Library/Frameworks
Checking framework prefix [/Applications/]
Consider /Applications
Consider /Applications
Consider /Applications
Consider /Applications
Checking framework prefix [/Developer/Applications/]
Consider /Developer/Applications
Consider /Developer/Applications
Consider /Developer/Applications
Consider /Developer/Applications
Checking bundle prefix [/opt/local/]
Consider /opt/local
Consider /opt/local
Checking bundle prefix [/sw/]
Consider /sw
Consider /sw
Checking bundle prefix [/usr/]
Consider /usr
Consider /usr
Checking bundle prefix [/]
Consider 
Consider 
Checking bundle prefix [/usr/local/]
Consider /usr/local
Consider /usr/local
Checking bundle prefix [/usr/X11/]
Consider /usr/X11
Consider /usr/X11
Checking bundle prefix [/Users/USERNAME/Library/Frameworks/]
Consider /Users/USERNAME/Library/Frameworks
Consider /Users/USERNAME/Library/Frameworks
Checking bundle prefix [/Library/Frameworks/]
Consider /Library/Frameworks
Consider /Library/Frameworks
Checking bundle prefix [/Network/Library/Frameworks/]
Consider /Network/Library/Frameworks
Consider /Network/Library/Frameworks
Checking bundle prefix [/System/Library/Frameworks/]
Consider /System/Library/Frameworks
Consider /System/Library/Frameworks
Checking bundle prefix [/Applications/]
Consider /Applications
Consider /Applications
Checking bundle prefix [/Developer/Applications/]
Consider /Developer/Applications
Consider /Developer/Applications
Checking prefix [/opt/local/]
CheckDirectory (dir /opt/local/, suffix , d /opt/local/)
FindConfigFile #2
Checking file [/opt/local/OpenCVConfig.cmake]
dir /opt/local *ci OpenCVConfig.cmake
Checking file [/opt/local/opencv-config.cmake]
dir /opt/local *ci opencv-config.cmake
Consider /opt/local
Consider /opt/local
Consider /opt/local
Consider /opt/local
Consider /opt/local/lib64
Consider /opt/local/lib64/cmake
Consider /opt/local/lib
Consider /opt/local/lib/cmake
Consider /opt/local/lib/cmake/OpenCVConfig-version.cmake
Visit /opt/local/lib/cmake/OpenCVConfig-version.cmake/
CheckDirectory (dir /opt/local/lib/cmake/OpenCVConfig-version.cmake/,
suffix , d /opt/local/lib/cmake/OpenCVConfig-version.cmake/)
FindConfigFile #2
Checking file
[/opt/local/lib/cmake/OpenCVConfig-version.cmake/OpenCVConfig.cmake]
dir /opt/local/lib/cmake/OpenCVConfig-version.cmake *ci
OpenCVConfig.cmake
Checking file
[/opt/local/lib/cmake/OpenCVConfig-version.cmake/opencv-config.cmake]
dir /opt/local/lib/cmake/OpenCVConfig-version.cmake *ci
opencv-config.cmake
Consider /opt/local/lib/cmake/OpenCVConfig.cmake
Visit /opt/local/lib/cmake/OpenCVConfig.cmake/
CheckDirectory (dir /opt/local/lib/cmake/OpenCVConfig.cmake/, suffix , d
/opt/local/lib/cmake/OpenCVConfig.cmake/)
FindConfigFile #2
Checking file
[/opt/local/lib/cmake/OpenCVConfig.cmake/OpenCVConfig.cmake]
dir /opt/local/lib/cmake/OpenCVConfig.cmake *ci OpenCVConfig.cmake
Checking file
[/opt/local/lib/cmake/OpenCVConfig.cmake/opencv-config.cmake]
dir /opt/local/lib/cmake/OpenCVConfig.cmake *ci opencv-config.cmake
Consider /opt/local/share
Consider /opt/local/share/cmake
Consider /opt/local
Consider /opt/local/lib64
Consider /opt/local/lib
Consider /opt/local/share
Consider /opt/local/share/OpenCV
Visit /opt/local/share/OpenCV/
CheckDirectory (dir /opt/local/share/OpenCV/, suffix , d
/opt/local/share/OpenCV/)
FindConfigFile #2
Checking file [/opt/local/share/OpenCV/OpenCVConfig.cmake]
dir /opt/local/share/OpenCV *ci OpenCVConfig.cmake
Checking file [/opt/local/share/OpenCV/opencv-config.cmake]
dir /opt/local/share/OpenCV *ci opencv-config.cmake
Consider /opt/local
Consider /opt/local/lib64
Consider /opt/local/lib
Consider /opt/local/share
Consider /opt/local/share/OpenCV
Checking prefix [/sw/]
CheckDirectory (dir /sw/, suffix , d /sw/)
FindConfigFile #2
Checking file [/sw/OpenCVConfig.cmake]
dir /sw *ci OpenCVConfig.cmake
Checking file [/sw/opencv-config.cmake]
dir /sw *ci opencv-config.cmake
Consider /sw
Consider /sw
Consider /sw
Consider /sw
Consider /sw/lib64
Consider /sw/lib64/cmake
Consider /sw/lib
Consider /sw/lib/cmake
Consider /sw/share
Consider /sw/share/cmake
Consider /sw
Consider /sw/lib64
Consider /sw/lib
Consider /sw/share
Consider /sw
Consider /sw/lib64
Consider /sw/lib
Consider /sw/share
Checking prefix [/usr/]
CheckDirectory (dir /usr/, suffix , d /usr/)
FindConfigFile #2
Checking file [/usr/OpenCVConfig.cmake]
dir /usr *ci OpenCVConfig.cmake
Checking file [/usr/opencv-config.cmake]
dir /usr *ci opencv-config.cmake
Consider /usr
Consider /usr
Consider /usr
Consider /usr
Consider /usr/lib64
Consider /usr/lib64/cmake
Consider /usr/lib
Consider /usr/lib/cmake
Consider /usr/share
Consider /usr/share/cmake
Consider /usr
Consider /usr/lib64
Consider /usr/lib
Consider /usr/share
Consider /usr
Consider /usr/lib64
Consider /usr/lib
Consider /usr/share
Checking prefix [/]
CheckDirectory (dir /, suffix , d /)
FindConfigFile #2
Checking file [/OpenCVConfig.cmake]
dir  *ci OpenCVConfig.cmake
Checking file [/opencv-config.cmake]
dir  *ci opencv-config.cmake
Consider 
Consider 
Consider 
Consider 
Consider /lib64
Consider /lib64/cmake
Consider /lib
Consider /lib/cmake
Consider /share
Consider /share/cmake
Consider 
Consider /lib64
Consider /lib
Consider /share
Consider 
Consider /lib64
Consider /lib
Consider /share
Checking prefix [/usr/local/]
CheckDirectory (dir /usr/local/, suffix , d /usr/local/)
FindConfigFile #2
Checking file [/usr/local/OpenCVConfig.cmake]
dir /usr/local *ci OpenCVConfig.cmake
Checking file [/usr/local/opencv-config.cmake]
dir /usr/local *ci opencv-config.cmake
Consider /usr/local
Consider /usr/local
Consider /usr/local
Consider /usr/local
Consider /usr/local/lib64
Consider /usr/local/lib64/cmake
Consider /usr/local/lib
Consider /usr/local/lib/cmake
Consider /usr/local/share
Consider /usr/local/share/cmake
Consider /usr/local
Consider /usr/local/lib64
Consider /usr/local/lib
Consider /usr/local/share
Consider /usr/local
Consider /usr/local/lib64
Consider /usr/local/lib
Consider /usr/local/share
Checking prefix [/usr/X11/]
CheckDirectory (dir /usr/X11/, suffix , d /usr/X11/)
FindConfigFile #2
Checking file [/usr/X11/OpenCVConfig.cmake]
dir /usr/X11 *ci OpenCVConfig.cmake
Checking file [/usr/X11/opencv-config.cmake]
dir /usr/X11 *ci opencv-config.cmake
Consider /usr/X11
Consider /usr/X11
Consider /usr/X11
Consider /usr/X11
Consider /usr/X11/lib64
Consider /usr/X11/lib64/cmake
Consider /usr/X11/lib
Consider /usr/X11/lib/cmake
Consider /usr/X11/share
Consider /usr/X11/share/cmake
Consider /usr/X11
Consider /usr/X11/lib64
Consider /usr/X11/lib
Consider /usr/X11/share
Consider /usr/X11
Consider /usr/X11/lib64
Consider /usr/X11/lib
Consider /usr/X11/share
Checking prefix [/Users/USERNAME/Library/Frameworks/]
Checking prefix [/Library/Frameworks/]
CheckDirectory (dir /Library/Frameworks/, suffix , d
/Library/Frameworks/)
FindConfigFile #2
Checking file [/Library/Frameworks/OpenCVConfig.cmake]
dir /Library/Frameworks *ci OpenCVConfig.cmake
Checking file [/Library/Frameworks/opencv-config.cmake]
dir /Library/Frameworks *ci opencv-config.cmake
Consider /Library/Frameworks
Consider /Library/Frameworks
Consider /Library/Frameworks
Consider /Library/Frameworks
Consider /Library/Frameworks/lib64
Consider /Library/Frameworks/lib64/cmake
Consider /Library/Frameworks/lib
Consider /Library/Frameworks/lib/cmake
Consider /Library/Frameworks/share
Consider /Library/Frameworks/share/cmake
Consider /Library/Frameworks
Consider /Library/Frameworks/lib64
Consider /Library/Frameworks/lib
Consider /Library/Frameworks/share
Consider /Library/Frameworks
Consider /Library/Frameworks/lib64
Consider /Library/Frameworks/lib
Consider /Library/Frameworks/share
Checking prefix [/Network/Library/Frameworks/]
Checking prefix [/System/Library/Frameworks/]
CheckDirectory (dir /System/Library/Frameworks/, suffix , d
/System/Library/Frameworks/)
FindConfigFile #2
Checking file [/System/Library/Frameworks/OpenCVConfig.cmake]
dir /System/Library/Frameworks *ci OpenCVConfig.cmake
Checking file [/System/Library/Frameworks/opencv-config.cmake]
dir /System/Library/Frameworks *ci opencv-config.cmake
Consider /System/Library/Frameworks
Consider /System/Library/Frameworks
Consider /System/Library/Frameworks
Consider /System/Library/Frameworks
Consider /System/Library/Frameworks/lib64
Consider /System/Library/Frameworks/lib64/cmake
Consider /System/Library/Frameworks/lib
Consider /System/Library/Frameworks/lib/cmake
Consider /System/Library/Frameworks/share
Consider /System/Library/Frameworks/share/cmake
Consider /System/Library/Frameworks
Consider /System/Library/Frameworks/lib64
Consider /System/Library/Frameworks/lib
Consider /System/Library/Frameworks/share
Consider /System/Library/Frameworks
Consider /System/Library/Frameworks/lib64
Consider /System/Library/Frameworks/lib
Consider /System/Library/Frameworks/share
Checking prefix [/Applications/]
CheckDirectory (dir /Applications/, suffix , d /Applications/)
FindConfigFile #2
Checking file [/Applications/OpenCVConfig.cmake]
dir /Applications *ci OpenCVConfig.cmake
Checking file [/Applications/opencv-config.cmake]
dir /Applications *ci opencv-config.cmake
Consider /Applications
Consider /Applications
Consider /Applications
Consider /Applications
Consider /Applications/lib64
Consider /Applications/lib64/cmake
Consider /Applications/lib
Consider /Applications/lib/cmake
Consider /Applications/share
Consider /Applications/share/cmake
Consider /Applications
Consider /Applications/lib64
Consider /Applications/lib
Consider /Applications/share
Consider /Applications
Consider /Applications/lib64
Consider /Applications/lib
Consider /Applications/share
Checking prefix [/Developer/Applications/]
CheckDirectory (dir /Developer/Applications/, suffix , d
/Developer/Applications/)
FindConfigFile #2
Checking file [/Developer/Applications/OpenCVConfig.cmake]
dir /Developer/Applications *ci OpenCVConfig.cmake
Checking file [/Developer/Applications/opencv-config.cmake]
dir /Developer/Applications *ci opencv-config.cmake
Consider /Developer/Applications
Consider /Developer/Applications
Consider /Developer/Applications
Consider /Developer/Applications
Consider /Developer/Applications/lib64
Consider /Developer/Applications/lib64/cmake
Consider /Developer/Applications/lib
Consider /Developer/Applications/lib/cmake
Consider /Developer/Applications/share
Consider /Developer/Applications/share/cmake
Consider /Developer/Applications
Consider /Developer/Applications/lib64
Consider /Developer/Applications/lib
Consider /Developer/Applications/share
Consider /Developer/Applications
Consider /Developer/Applications/lib64
Consider /Developer/Applications/lib
Consider /Developer/Applications/share
CMake Error at CMakeLists.txt:9 (find_package):
  Could not find a package configuration file provided by "OpenCV" with
any
  of the following names:

    OpenCVConfig.cmake
    opencv-config.cmake

  Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
  "OpenCV_DIR" to a directory containing one of the above files.  If
"OpenCV"
  provides a separate development package or SDK, be sure it has been
  installed.


-- Configuring incomplete, errors occurred!
$




For some reason the

Consider /opt/local/lib/cmake/OpenCVConfig-version.cmake
Visit /opt/local/lib/cmake/OpenCVConfig-version.cmake/
CheckDirectory (dir /opt/local/lib/cmake/OpenCVConfig-version.cmake/,
suffix , d /opt/local/lib/cmake/OpenCVConfig-version.cmake/)
FindConfigFile #2
Checking file
[/opt/local/lib/cmake/OpenCVConfig-version.cmake/OpenCVConfig.cmake]
dir /opt/local/lib/cmake/OpenCVConfig-version.cmake *ci

part decides to go into la-la land,
rather than actually checking the supposed-to-be-sibling-to-Config.cmake
foo-version.cmake **file**.



All the while

# ls /opt/local/lib/cmake
OpenCVConfig-version.cmake	OpenCVConfig.cmake

has been ready waiting for the takin'
(oh and I forgot to mention that CMAKE_PREFIX_PATH contained /opt/local,
as seen in custom-augmented log above).

# port list opencv
opencv                         @2.4.5          graphics/opencv



At least the find failure message is sufficiently semi-informative, though.

Setting the OpenCV-specific manual OpenCV_DIR variable then works, for a change.
THIS SHOULD NOT BE WHAT A USER IS SUPPOSED TO DO (read: I consider it to
be a HACK, since this is way more specific than what a user would
normally care to specify).
PREFIX-only operation should be the universal default
(unless there are specific requirements on certain installations),
thus that should be working without any issues whatsoever.


The entire lookup handling seems grossly overly complex (for better or
worse, given usual very heavy requirements and expectations on a build system).
Have to say that at least it is implemented as very nice helper classes...

One conclusion is: CMake should definitely try to reduce its complexity soon
(spend efforts to merely contain the massive amounts of required complexity,
discarding any outdated one!), especially in such highly involved areas.
IMHO it's high time for compiling a sizeable list of
outdated/rotten "features" to axe, then once a list has been agreed on,
prepare releasing a FEATURE-BREAKING version 3 which drastically cuts needless and
bug-inducing featuritis
(I'm talking e.g. the <lowercase>-config.cmake vs. <RealCase>Config.cmake here,
but there are many other things that are e.g.
deprecated/mis-implemented/confusing).
Docs per each command are already sky-high as is (especially in Find areas),
there's no need to complicate handling (and thus memorability!!)
even more by retaining support of needless/Darwin-disadvantaged variations.


Locating installed packages on a system should not be that hard,
especially when going the KISS "specify PREFIX only" way (combined with
COTS-installed packager packages!), and, to add insult to injury,
in combination with a CMake poster child package (OpenCV is fully CMake-enabled!).

And, I have to add that, this should especially be the case in light of
the uninformedness of many users (and, after all, a system should
ideally just work, intuitively... but that's the usual rather unattainable goal).


</rant> (sorry! :)

(oh well, at least some users will be able to gather some important
find_package() debugging help from my posting ;)

Andreas Mohr


More information about the CMake mailing list