[CMake] add_subdirectory cache configuration via cmake script

Dario Oliveri oliveridario89 at gmail.com
Tue Jan 6 15:09:57 EST 2015


How can I prevent variables cache pollution in CMAKE?

My real problem is the following:

I have library A and library B, both libraries have some cmake variable
used to configure there and there and that's ok, but what
when variables are semantically duplicated?

Library A depends on Library B

both libraries provide "CompileForLinux" cache variable, I want be able to
just compile library A and check the checkbox for "CompileForLinux" just
once.

This example is the minimum of course, but it would be nice if there's
someway to wrap variables of dependencies so that I can compile a library
with less chance of "human error prone" misconfiguration and to provide
final user of library A only the few real needed options/variables.

Libray A is actually including library B using "add_subdirectory"

So assume the following boolean cache variables:

LIBA_STATIC
LIBA_SHARED
LIBA_OBJECT
LIBB_STATIC
LIBB_SHARED
LIBB_OBJECT
LIBA_EXCLUDE_MODULE1
LIBB_EXCLUDE_MODULE1
COMPILE_FOR_LINUX   #from libA
COMPILE_FOR_LINUX   #from libB

It would be nice letting LIB A to hide unecessary staff that can be
configured by the cmake script without the user have to know it.

Final expected list to be showed in Cmake-gui


LIBA_STATIC      # configure libB accordingly
LIBA_SHARED
LIBA_OBJECT
LIBA_EXCLUDE_MODULE1
LIBB_EXCLUDE_MODULE1   #not hided by libA because necessary for final
configuration
COMPILE_FOR_LINUX   #from libA

I Hope you see how that can be tremendously usefulll especially in
opensource cross-platform projects with many dependencies
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150106/dd929392/attachment.html>


More information about the CMake mailing list