[CMake] using install() with EXCLUDE_FROM_ALL

Daniel Nelson torham at connect2.com
Fri Apr 9 02:02:35 EDT 2010


On Thursday 08 April 2010 8:40:54 am David Cole wrote:
> On Thu, Apr 8, 2010 at 10:28 AM, Daniel Nelson <torham at connect2.com> wrote:
> > On Wednesday 07 April 2010 10:37:54 pm Michael Wild wrote:
> > > On 8. Apr, 2010, at 3:39 , Ryan Pavlik wrote:
> > > > You might consider just setting the EXCLUDE_FROM_ALL property on
> >
> > specific
> >
> > > > targets, instead of an entire subdirectory.
> > > >
> > > > Ryan
> > > >
> > > > On Wed, Apr 7, 2010 at 8:33 PM, Daniel Nelson <torham at connect2.com>
> >
> > wrote:
> > > >> If I use add_subdirectory with the EXCLUDE_FROM_ALL option, then any
> > > >> files whose install commands are in that directory are not installed
> >
> > as
> >
> > > >> part of 'make install'.  Is this on purpose, and if so is there a
> > > >> way
> >
> > I
> >
> > > >> can install these files?
> > > >> --
> > > >> Daniel
> > >
> > > Also there is the OPTIONAL argument to the INSTALL command which might
> > > be of help here.
> > >
> > >
> > > Michael
> >
> > This is probably a pretty good workaround, but it's not ideal because I
> > have
> > several projects that add this directory, and I only want it to be
> > excluded for some of them.  So I'll end up needing to use a variable in
> > the parent directory to control the EXCLUDE_FROM_ALL property.  Then I
> > need to use the OPTIONAL argument to prevent errors if I haven't built
> > the directory, which means I won't be notified if a file is missing.
> >
> > What I'd really like to be able to do, is add new targets, and then
> > manually
> > set them to depend on whichever install commands I want.  Then I could
> > just run: make install/my_exclude_from_all_project.  But it seems that
> > the install
> > commands are outside of the target system.
> 
> Why not use the COMPONENT feature of the various install command signatures
> to separate your installables into components...?
> 
> Then you can run:
>   cd binary_dir
>   cmake -D COMPONENT=MyComponent -P cmake_install.cmake
> and that will run just the install rules associated with the COMPONENT
> MyComponent...
> 
> You could even add a custom target named "install_my_component" to do this
> via "make install_my_component" if you like...
> 
> HTH,
> David
> 

This is a good tip and is something I have wanted to do on a different project 
but didn't know how, but it seems that it doesn't work if you use 
EXCLUDE_FROM_ALL.  The install_manifest file for the component is empty if it 
was created in the subdirectory.  So while you can use EXCLUDE_FROM_ALL to add 
a directory that you can build on demand, it seems that installing the items 
in the folder on demand is not possible.  

However, I think I can use a combination of these techniques: EXCLUDE_FROM_ALL 
only on the targets instead of the directories, and executing the 
cmake_install.cmake script by hand to get most of what I need.
--
Daniel


More information about the CMake mailing list