[CMake] 3rd party modules

Brad King brad.king at kitware.com
Fri Sep 22 09:16:45 EDT 2006


Kedzierski, Artur CIV NAVSURFWARCENDIV CORONA wrote:
> 	Thanks Brad.
> 	Let's say for project Foo and project Bar, I've created
> a FooConfig.cmake and BarConfig.cmake. Project Foo uses Cmake
> but Bar doesn't. During the installation, where should Foo and Bar place
> the Config.cmake so that another project's CMake can easily find it?
> Consider these scenarios:
> 1) Foo (cmake based) is installed on a system that has cmake
> 	Is there CMakeConfig.cmake that would tell me where 
>       to install the FooConfig.cmake?
> 2) Bar (not cmake based) is installed on a system that has cmake.
>       Is there cmake-config that would tell me where to install 
>       BarConfig.cmake?
> 3) Bar (not cmake based) is installed on a system that doesn't have cmake.
> 
> 	Should I install BarConfig.cmake in 
> 	$(datarootdir)/CMake/Modules (if Bar is using autotools)
> 	so that when CMake is installed later, BarConfig.cmake will be
> 	available.

There is no way to ask CMake where to install these files.  The reason
is that doing so would require CMake to be installed already and would
support only one copy of CMake.  There could be 10 different
installations of CMake on the machine and all of them should be equally
able to find Foo and Bar no matter where they are installed.  Somehow
either the project being installed has to find CMake or CMake has to
find the project.  We've decided that CMake can take responsibility for
having the complicated logic to find all projects rather than requiring
each project to have the logic to find CMake.

Foo and Bar should both install their (Foo|Bar)Config.cmake files in a
sensible place under their own installation prefix.  In the future
FIND_PACKAGE will look for these files under a set of paths like

  PREFIX/                      (useful on windows)
  PREFIX/(cmake|CMake)/        (useful on windows)
  PREFIX/(share|lib)/(Foo|foo|FOO).*/
  PREFIX/(share|lib)/(Foo|foo|FOO).*/(cmake|CMake)/
  PREFIX/(share|lib)/(cmake|CMake)/(Foo|foo|FOO).*/

Take your pick.  For example:

> 	Please consider that they would be installed under
> a) Linux

PREFIX/lib/foo-1.2/cmake/FooConfig.cmake
PREFIX/lib/bar-1.2/cmake/BarConfig.cmake

> b) Windows

PREFIX/cmake/FooConfig.cmake
PREFIX/cmake/BarConfig.cmake

Until this support is implemented in FIND_PACKAGE directly you can write
your own FindFoo.cmake and FindBar.cmake files that look for these
config files and load them with the INCLUDE() command.  The convention
for finding them should be something like

# FindFoo.cmake
FIND_PATH(Foo_DIR NAMES FooConfig.cmake PATHS ...)
IF(EXISTS ${Foo_DIR}/FooConfig.cmake)
  SET(Foo_FOUND 1)
  INCLUDE(${Foo_DIR}/FooConfig.cmake)
ELSE(EXISTS ${Foo_DIR}/FooConfig.cmake)
  SET(Foo_FOUND 0)
ENDIF(EXISTS ${Foo_DIR}/FooConfig.cmake)

Then code in FooConfig.cmake can use GET_FILENAME_COMPONENT and other
commands to compute Foo's installation prefix relative to Foo_DIR and
report the rest of the information about Foo.

-Brad


More information about the CMake mailing list