[CMake] Subdirectories and FIND_LIBRARY routines

Clifford Yapp cliffyapp at gmail.com
Mon Jul 26 11:59:18 EDT 2010

Hi!  I have a rather oddball question, and I'm not quite sure if I'm
even asking the right question, but I'll describe the circumstances
and see if it makes sense...

I am trying to set up a CMake project which includes as subdirectories
other CMake projects, but it does so only conditionally.  I.e., I


and want to provide the user with the options to either:

a)  Use system libraries (disable the compilation and use of the local
libz and libpng)
b)  Use local libraries (compile and use libz and libpng from local
tree - libpng should also use the local libz in this situation)
c)  Use a mix of the two (system libz but local libpng, in this case
libpng would use the system libz)

I am getting the hang of setting variables using CACHE and FORCE
options, and the VTK CMake files offer valuable hints, but I'm getting
stuck on a detail.  FindZLIB sets ZLIB_LIBRARY, and if I alter the
configuration from local to system selection FindZLIB is run.  All
well and good, but if I switch back to local, the ZLIB_LIBRARY remains
and remains set to the system lib.  This raises two questions - if
ZLIB_LIBRARY is set by FindZLIB, does it also need to be set when
building the local libz (and if so, how, since libz is not built at
configure time...) - also, since ZLIB_LIBRARY is now set in the cache
by FIND_LIBRARY, what mechanism can I use to override that value with
the local settings?  Presumably I can't point FIND_LIBRARY at libz
when it's not built yet and expect ZLIB_LIBRARY to get set, and even
if I could would FIND_LIBRARY override and reset the cache settings?

I've tried poking around various websites and wikis, and I apologize
if I missed a tutorial covering these points.  (For those of you
thinking it, I've already lost the argument against any sort of local
libz copy... the policy is that the option needs to be there).

Autotools allows subconfigures, but the process has never been all
that robust as most projects don't write their files with the notion
of being a subconfigure in mind.  I'm hoping CMake might provide a
more robust solution to this issue?


More information about the CMake mailing list