[CMake] Re: Target flags depending on compilation of another target

Alan W. Irwin irwin at beluga.phys.uvic.ca
Fri Dec 21 14:30:47 EST 2007


On 2007-12-21 10:14-0200 Rodolfo Lima wrote:

> Jesper Eskilson escreveu:
>
>> Not generally, no. However, if you know that you'll be using Make with a
>> bourne-shell to build you can sneak in things like "`cat somefile.txt`"
>> into your CMAKE_CXX_FLAGS, and have your custom target write flags to
>> "somefile.txt". This technique is commonly used in Unix makefiles to
>> allow compiler-flags to be generated "on-the-fly" by a utility program.
>
> Wow, that's what McGyver would do if he were a programmer. Thank you!
> With Visual C I think I can write a 'here document' and add with
> @flags.txt, isn't it?
>
> Is there any way to make cmake support things like this? A common use
> case would be like... one of your targets is a custom target which
> compiles wxWidgets (for instance). When it gets installed, it creates a
> bash script (wx-config) which, when run, returns proper compiler and
> linker flags. Those flags are used by another target that has wxWidgets
> as dependency.

Have a look at the internals of FindwxWidgets.cmake that comes with
CMake-2.4.7.  It uses wx-config for the case where wxwidgets is already
externally installed.  It should be straightforward to adapt this module for
the case where you are building wxwidgets internally.

For PLplot we implement the compiler flags returned by
FindwxWidgets.cmakewith using the SET_SOURCE_FILES_PROPERTIES COMPILE_FLAGS
property.  Furthermore, we have historically put the linker flags returned
by that module directly into a TARGET_LINK_LIBRARIES command.  However, a
better way to do it is to parse the link flags string into full pathnames
for libraries that are specified for TARGET_LINK_LIBRARIES and linking
options that are not related to library location that are specified with the
LINK_FLAGS property of SET_TARGET_PROPERTIES.

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________


More information about the CMake mailing list