[CMake] find_package with ###Config.cmake

Micha Renner Micha.Renner at t-online.de
Fri Dec 3 03:34:51 EST 2010


Am Freitag, den 03.12.2010, 08:45 +0100 schrieb Andreas Pakulat:
> On 03.12.10 07:11:23, Micha Renner wrote:
> > There is a small library "TLib" which is installed like this
> > 
> > Install the project...
> > -- Install configuration: "Debug"
> > -- Installing: /usr/local/lib/libTLibd.so
> > -- Installing: /usr/local/lib/TLib/TLibExport.cmake
> > -- Installing: /usr/local/lib/TLib/TLibExport-debug.cmake
> > -- Installing: /usr/local/include/TLib/cmFile.h
> > -- Installing: /usr/local/lib/TLib/TLIBConfig.cmake
> > -- Installing: /usr/local/lib/TLib/TLIBConfigVersion.cmake
> > 
> > The CMakeLists file for the application program has the following line
> > to find the library
> > 
> > FIND_PACKAGE(TLIB)
> > 
> > This works, surprisingly, very good. No CMAKE_MODULE_PATH, no TLIB_DIR
> > in this case. 
> > 
> > But...
> > 
> > If I call FIND_PACKAGE with version:
> > FIND_PACKAGE(TLIB 1.3)
> > 
> > I get the std-warning:
> > -----------------
> > CMake Warning at TestDLL/CMakeLists.txt:20 (FIND_PACKAGE):
> >   Could not find module FindTLIB.cmake or a configuration file for
> > package
> >   TLIB.
> > 
> >   Adjust CMAKE_MODULE_PATH or TLIB_DIR...
> > -----------------
> > 
> > 
> > Why can't CMake find the TLIBConfig file, if FIND_PACKAGE is called with
> > version and TLIB_DIR is not set? 
> 
> The problem might not be finding the Config file, but rather that the
> ConfigVersion file doesn't set the VERSION_COMPATIBLE or VERSION_EXACT
> variables. Or maybe it even sets the VERSION_UNSUITABLE to indicate that
> the installed version of TLib doesn't match the version you request.
> 
> Unfortunately cmake currently cannot seem to distinguish between these
> two cases (non-matching version vs. no config-file found), hence it
> produces the same message in both cases.
> 

This was my first impression, so I used the ConfigVersion file of
http://www.cmake.org/Wiki/CMake_2.6_Notes to be on the safe side.
SET(PACKAGE_NAME "TLib")
SET(PACKAGE_VERSION 1.3)
IF("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL 1)
	SET(PACKAGE_VERSION_COMPATIBLE 1)
	IF("${PACKAGE_FIND_VERSION_MINOR}" EQUAL 3)
		SET(PACKAGE_VERSION_EXACT 1)# exact match for version 1.3
	ENDIF("${PACKAGE_FIND_VERSION_MINOR}" EQUAL 3)
ENDIF("${PACKAGE_FIND_VERSION_MAJOR}" EQUAL 1)

But this also does not work.

Greetings

Micha




More information about the CMake mailing list