[CMake] Saving/Restoring link_directories and link_libraries
Andreas Mohr
andi at lisas.de
Fri Jun 1 14:34:19 EDT 2012
Hi,
On Fri, Jun 01, 2012 at 11:09:00AM -0400, cmake-request at cmake.org wrote:
> Date: Fri, 01 Jun 2012 15:30:32 +0200
> From: Theodore Papadopoulo <Theodore.Papadopoulo at inria.fr>
>
> I'm using a library XXX which comes with UseXXX.cmake and
> XXXConfig.cmake files (which I cannot touch as they come from linux
> distributions).
>
> Unfortunately, the XXXConfig.cmake directly calls
> include_directories(), add_definitions(), link_directories() and
> link_libraries().
To quote the carpenter: "OUCH!!" (throwing his hammer into a faraway
corner).
> So my question is, is there a way/trick to save the state of these 4
> quantities (link_directories, definitions, link_directories and
> link_libraries) before the FindPackage(XXX) call and to restore to
> these saved values after the call.
Think scoping to the rescue. At least that might be a nice trick
to get it to work.
- create a victim subdirectory (specifically named -
"workaround_braindead_config_file") specifically for the task
of using the project config within its CMakeLists.txt
- reference it there
- grab all of the related values via directory properties or some such
(as far as it is possible to access these config settings, that is - I'm not sure)
- export all these settings via GLOBAL properties (or cache variables?) or some
such
- after the add_subdirectory() "call",
the local config will now *NOT* be changed (subdirectory-only scope,
fortunately!!)
- grab all required elements from the GLOBAL properties set by the sub
directory code and configure your local targets with these
[plus, for possibly target-specific configuration done by the Config file,
provide a dummy victim target to gather these values from]
This mechanism is so stupendously daring that it might just happen to work ;)
Andreas Mohr
More information about the CMake
mailing list