[cmake-developers] Making Config.cmake files safer

Alexander Neundorf neundorf at kde.org
Tue Nov 15 13:19:56 EST 2011


On Monday 14 November 2011, you wrote:
> On 11/14/2011 4:01 PM, Alexander Neundorf wrote:
> >> Instead of adding the code to the bottom of GenerateImportPropertyCode
> >> please create a separate method next to it for that part.
> > 
> > Done, in an updated version of the
> > CheckImportedFileExistenceInConfigDotCMakeFiles branch.
> 
> Looks good.  My remaining hesitation is that the message gets duplicated
> many times in the targets file and takes a lot of (visual) space but
> its presence does not add much information for a (human) reader.  I
> wonder if we can accumulate a list of files to be checked and add one
> test at the end of the targets file that looks for everything and
> fails with a single message.

I could do

function(check_for_file _file _target)
  if(NOT EXISTS _file)
    message(FATAL_ERROR "... long error message...")
endfunction()

check_for_file(libFoo123.so  Foo)
...
check_for_file(libBar123.so  Bar)


Or I could collect the files and targets together, but then the error message 
becomes less straigh forward.
Right now it is:

The file "libbar.so.1.2.3" for the imported target "bar" does not exist.
There are multiple possible reasons:
 * the file "libbar.so.1.2.3" has been manually deleted, renamed or moved to
   another location
 * a previous install or uninstall procedure did not run  successfully to its
   end
 * the installation package was faulty, and contained "BarTargets.cmake",
   but not "libbar.so.1.2.3", which must always be installed together.


Then it could be:

There were files missing for imported targets. There are multiple possible 
reasons:
 * the files have been manually deleted, renamed or moved to
   another location
 * a previous install or uninstall procedure did not run  successfully to its
   end
 * the installation package was faulty, and contained "BarTargets.cmake",
   but not the corresponding files, although they must always be installed
   together.

Missing files:
   libbar123.so (for target "bar")


I'm not sure in the second version is as clear to understand as the first one, 
since it has to talk generally about "the files" in the text, while the first 
one can directly use "libbar.so.123".

Also, since this should be a rare error case, I'm not sure it makes sense to 
optimize it for the case of multiple missing files.

Alex



More information about the cmake-developers mailing list