Strange commit to FindKDE4Internal.cmake

Alexander Neundorf neundorf at kde.org
Sun Feb 19 16:20:54 UTC 2012


On Sunday 19 February 2012, Pau Garcia i Quiles wrote:
> On Sun, Feb 19, 2012 at 4:24 PM, Alexander Neundorf <neundorf at kde.org> 
wrote:
> >> - A reference FindLibFoo.cmake is useful for developers who want to
> >> make sure libfoo will be located on *any* platform, be it Linux,
> >> Windows, Mac or something else. FooConfig.cmake is probably of little
> >> use on Windows,
> > 
> > Why do you think that ?
> 
> Because on Windows there are no standard paths to search for libraries
> or anything, including FooConfig.cmake. See below for more.

CMake searches in a set of self-defined standard locations, as documented in 
the find_package() section of the man page.
I don't have experience with this myself on Windows, but doesn't this make it 
kind of work ?
 
> >> which is why I, as a developer of TheGreatApp (an
> >> application based on libfoo) would copy
> >> /usr/share/doc/libfoo-dev/cmake/FindLibFoo.cmake to TheGreatApp/cmake,
> >> add TheGreatApp/cmake to CMAKE_MODULE_PATH and use find_package(foo
> >> REQUIRED). Especially if TheGreatApp is not a KDE application, which
> >> has no reason to use or know about extra-cmake-modules.
> > 
> > As written above, extra-cmake-modules is not intended to be in any way
> > bound to KDE.
> > 
> > Right now, for Qt5 you have to do
> > 
> > find_package(Qt5 REQUIRED)
> > 
> > Serious question: if you then get the following error message from cmake,
> > what do you think is the problem ?
> > 
> > CMake Error at CMakeLists.txt:3 (find_package):
> >  Could not find module FindQt5.cmake or a configuration file for package
> >  Qt5.
> > 
> >  Adjust CMAKE_MODULE_PATH to find FindQt5.cmake or set Qt5_DIR to the
> >  directory containing a CMake configuration file for Qt5.  The file will
> >  have one of the following names:
> > 
> >    Qt5Config.cmake
> >    qt5-config.cmake
> > 
> > -- Configuring incomplete, errors occurred!
> 
> That's exactly my point.
> 
> If TheGreatApp does a find_package(LibFoo REQUIRED) this is what happens:
> 
> - If LibFooConfig.cmake and/or FindLibFoo.cmake is available (either
> from CMake itself or bundled with my *application* in
> TheGreatApp/cmake), either LibFoo is found and all goes well, or
> LibFoo is not found and the error the user will see is "LibFoo not
> found" because either LibFooConfig.cmake or FindLibFoo.cmake would
> provide what find_package needs (configuration and/or module).
> 
> - If LibFooConfig.cmake is installed on Windows but it's on a path
> CMake does not look into (the *norm* on Windows), or if I do not
> bundle FindLibFoo.cmake with my application, this is the error a user
> would see on Windows: an incomprehensible error. Same error as if
> LibFooConfig.cmake is not available.
> 
> I cannot see the advantage of LibFooConfig.cmake on non-Unix
> platforms, or even on Unix platforms when libraries (including
> FooConfig.cmake) is installed on non-standard locations. It will make
> find_package fail at the very first step (trying to locate
> FooConfig.cmake or FindLibFoo.cmake) without even delving into the
> very finding operation.

We are discussing exactly this currently on the cmake-developers list.

My proposal for cmake 2.8.8 is:

find_package(Qt5)

only uses FindQt5.cmake (and doesn't look for a Qt5Config.cmake), and if 
FindQt5.cmake is not found, it says:
-----------------------------------------------
"CMake Error at CMakeLists.txt:7 (find_package):
  Could not find module FindQt5.cmake.

  Adjust CMAKE_MODULE_PATH to find FindQt5.cmake.

  FindQt5.cmake must either be part of this project itself, in this case
  adjust CMAKE_MODULE_PATH so that it points to the correct location inside
  your source tree.

  Or it must be installed by a package which has already been found via
  find_package().  In this case make sure that this package has indeed been
  found and adjust CMAKE_MODULE_PATH to contain the location where that
  package has installed FindQt5.cmake.  This must be a variable provided by
  that package or something similar, i.e.  for instance not your current
  CMAKE_INSTALL_PREFIX.  This error in general means that you are relying on
  a Find-module without ensuring that this Find-module exists."

-----------------------------------------------

OTOH
find_package(Qt5 NO_MODULE)
will look only for a Qt5Config.cmake, i.e. you have to enforce Config mode, 
and thus make is possible for cmake to generate better error messages, and so 
for the user to know better what went wrong:

-----------------------------------------------
"CMake Error at CMakeLists.txt:7 (find_package):
  Could not find a configuration file for package Qt5 with one of the
  following names:

    Qt5Config.cmake
    qt5-config.cmake

  To find the configuration file, set CMAKE_PREFIX_PATH to the installation
  prefix of Qt5, or set Qt5_DIR to the directory containing a CMake
  configuration file for Qt5.
"
-----------------------------------------------


What do you think about this ?


Alex


More information about the Kde-buildsystem mailing list