maco_optional_find_package magic

Jeff Mitchell mitchell at kde.org
Fri Mar 13 19:04:02 CET 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Alexander Neundorf wrote:
> On Friday 13 March 2009, Jeff Mitchell wrote:
>> Can someone clue me in as to how macro_optional_find_package manages to
>> not have the configure abort (at the end) if the package isn't found?  I
>> thought it might be something in KDE4Defaults, but didn't find it in
>> there either.
>>
>> I need to do a check before I add the KDE4 includes/find_package, so I
>> can't use the macro (because I can't rely on KDE4 being installed)...but
> 
> The file MacroOptionalFindPackage.cmake can be used completely independent 
> from the rest of KDE, there is nothing in it which depends on anything 
> KDE-related.

Yes, I know.

> So you could just copy that file into your project and use it.

Or use its 5 lines of code, which I said is what I tried doing.

> If you use it with the keyword REQUIRED, it will also fail with FATAL_ERROR if 
> the package is not found.

I said that I wasn't.

> The one thing it does additionally compared to plain FIND_PACKAGE() is that it 
> automatically provides an option WITH_<name_of_the_package>, which you can 
> disable, then it will not even try to search for the package.

Okay, let me restate my question, since it was totally ignored.

When macro_optional_find_package is used, if a package is not found,
CMake finishes configuring and writes build files.

If you simply use find_package, even if you are *not* using REQUIRED, if
a package is not found, CMake finishes configuring but does *not* write
build files, saying that an error had occurred.

So, what is allowing macro_find_optional_package to allow configuration
to finish if the package is not found?  This may be something in some
other KDE4 defaults macro, but I couldn't find it.

To be more explicit, this doesn't work (configuring is canceled):

if( WITH_TAGLIB-EXTRAS )
    set(TAGLIB-EXTRAS_MIN_VERSION "0.1")
    find_package(TaglibExtras)
    if( TAGLIB-EXTRAS_FOUND )
        add_definitions( -DTAGLIB_EXTRAS_FOUND )
    endif( TAGLIB-EXTRAS_FOUND )
endif( WITH_TAGLIB-EXTRAS )

But this does (configuring finishes successfully even if GDK is not
found...this occurs later, after doing a find_package on KDE4 and
include on KDE4Defaults):

    if( WITH_IPOD )
        macro_optional_find_package(Gdk)
        macro_log_feature( GDK_FOUND "Gdk" "Support for artwork on iPod
audio devices via GdkPixbuf"
"http://developer.gnome.org/arch/imaging/gdkpixbuf.html" FALSE "2.0.x" "" )
    endif( WITH_IPOD )

So, what is allowing macro_optional_find_package to be truly optional?
Or is the behavior of find_package itself being modified somewhere along
the way?

Thanks,
Jeff
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (MingW32)

iEYEARECAAYFAkm6oBEACgkQANYdqNCuGCVv7QCgws/pmeKqWOopXXjPRdRuJOc+
qpsAoM6GO6/bJy+KRHs95E/pdYDTTxcg
=yPPy
-----END PGP SIGNATURE-----


More information about the Kde-buildsystem mailing list