[CMake] 3rd party cmake files
Brad King
brad.king at kitware.com
Mon Jun 5 15:23:57 EDT 2006
Alexander Neundorf wrote:
> what's the preferred way to distribute cmake files for 3rd party projects ?
>
> Currently cmake looks for files in ${CMAKE_ROOT}/Modules and in CMAKE_MODULE_PATH.
>
> Now (e.g. the QtDBUS package) builds with cmake and actually should come with its own cmake files.
> One way is to contribute these files (FindQtDBUS.cmake or something like this) to cmake so that it becomes part of the official cmake distribution.
>
> Another option would be if QtDBUS installs FindQTDBUS.cmake into ${CMAKE_ROOT}/Modules .
> This won't work if the user doesn't have root access.
>
> How about adding something like ${HOME}/.CMake/Modules/ to the cmake search path ?
We don't want to require a 3rd-party file or user environment variable
to be set for a project to work with CMake. This is just as bad as not
finding it automatically in the first place. If QtDBUS were to install
its own FindQtDBUS, then CMake would have to first find FindQtDEBUS
before loading it. If it has found this file then why does it need a
find script to find QtDBUS since it has just found something from the
package?
The FIND_PACKAGE command was designed to deal with this. Since the
QtDBUS project is CMake-aware it should install a "QtDBUSConfig.cmake"
file that knows where to find everything in the installation. Then
writing just
find_package(QtDBUS)
is enough to find it. If there is no FindQtDBUS.cmake file then this
will create a variable called QtDBUS_DIR that is documented
automatically to ask the user for the location of QtDBUSConfig.cmake.
If project developers are unhappy with the automatic attempts to set
QtDBUS_DIR then they can create their own FindQtDBUS.cmake file and put
it in their project. The file can contain simply
find_path(QtDBUS_DIR FindQtDBUS.cmake PATHS ...)
if(EXISTS ${QtDBUS_DIR}/QtDBUSConfig.cmake)
include(${QtDBUS_DIR}/QtDBUSConfig.cmake)
else(EXISTS ${QtDBUS_DIR}/QtDBUSConfig.cmake)
# ...report not found...
endif(EXISTS ${QtDBUS_DIR}/QtDBUSConfig.cmake)
This code does not depend on the QtDBUS version so it does not have to
come with the package. Instead all the version and package-specific
install information can be in QtDBUSConfig.cmake. It doesn't even have
to do any finding because it is configured by the package when it is
installed to know exactly where things are located.
-Brad
More information about the CMake
mailing list