On Wed, Mar 26, 2014 at 22:38:51 +0000, Alex Merry wrote:
> Actually, yeah, it's mainly the dependency handling that's hairy.  There
> are couple of other things you have to be aware of; for instance, I've
> seen several find modules try to give all the components to
> pkg_check_modules() at once, but you can't do that (pkg_check_modules
> finds everything or nothing).

OK, good to know I'm not missing anything :) . My thought was to do the
following (in that linked module):

    set(${component}_deps ...)

    set(extra_deps)
    foreach (component IN LISTS Derelict_FIND_COMPONENTS)
        foreach (dep IN LISTS ${component}_deps)
            # if dep not in Derelict_FIND_COMPONENTS
                list(APPEND extra_deps "${component}")
        endforeach ()
    endforeach ()

and then to also search for the deps and finally do:

    set(valid_components)
    foreach (component IN LISTS Derelict_FIND_COMPONENTS)
        set(missing)
        foreach (dep IN LISTS ${component}_deps)
            # if dep not found
                list(APPEND missing "${component}")
        endforeach ()

        if (missing)
            # if REQUIRED
                # error out
        else ()
            # Add imported target.
            list(APPEND valid_components "${component}")
        endif ()
    endforeach ()

    foreach (component IN LISTS valid_components)
        # Add dependency links here.
    endforeach ()

This keeps the "find this component" logic free of any of the dependency
logic and falls back gracefully if components aren't found and such.

It is a little verbose though :( . If there were a nice way to do
callbacks[1] (to do the "find a component", "add the import target", and
"add the dependency link" bits), this would actually wrap up into a
module nicely.

--Ben

[1]I don't really like the "file(WRITE path); include(path)" route...
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/cgi-bin/mailman/listinfo/cmake-developers

Reply via email to