[CMake] Install optional targets

Tim Gallagher tim.gallagher at gatech.edu
Sun Aug 28 20:47:21 EDT 2011


Thanks for the help! This does exactly what we wanted. 

And, install(OPTIONAL) with EXCLUDE_FROM_ALL also works... perhaps that warning message should only be displayed if OPTIONAL isn't in the install() function as it's rather misleading...

Tim

----- Original Message -----
From: "Michael Hertling" <mhertling at online.de>
To: cmake at cmake.org
Sent: Sunday, August 28, 2011 8:33:47 PM
Subject: Re: [CMake] Install optional targets

On 08/29/2011 01:20 AM, Tim Gallagher wrote:
> Hi,
> 
> I asked about this awhile back and haven't had any luck with it, so I'll try again.
> 
> What we are trying to do is have a project (called Utilities) that has a bunch of targets (the actual utility executables). Let's say there are 4 utils: pre, post, grid, and restart. We would like to do something like:
> 
> make pre
> make post
> make install
> 
> Where the "make install" step only installs the targets that have been built. If each target is created with the add_executable() and then has an install() (without OPTIONAL), then typing "make install" will build pre, post, grid and restart. 
> 
> If each target has EXCLUDE_FROM_ALL and an install() (without OPTIONAL), CMake warns that the behavior is undefined and "make install" does nothing. 
> 
> If each target has EXCLUDE FROM_ALL and OPTIONAL in the install(), the same as above.
> 
> If each target is in all and OPTIONAL is in the install(), then "make install" still builds all the targets, not just the ones already built. 
> 
> So it appears the "install" target depends on the "all" target. And since all the utilities are part of "all," they get built, even when OPTIONAL is specified. 
> 
> Is what we're trying to do possible? We have it working where we create custom targets for each utility, ie:
> 
> make pre
> make post
> make install_pre
> make install_post
> 
> but it would be much nicer/easier if there was just a "install all targets that have been built" step. 
> 
> Any suggestions?
> 
> Tim

You might decouple the "install" target from the "all" one by setting
CMAKE_SKIP_INSTALL_ALL_DEPENDENCY to TRUE in connection with OPTIONAL:

CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
PROJECT(OPTIONALINSTALL C)
SET(CMAKE_VERBOSE_MAKEFILE ON)
SET(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY TRUE)
FILE(WRITE ${CMAKE_BINARY_DIR}/f.c "void f(void){}\n")
ADD_LIBRARY(f SHARED f.c)
FILE(WRITE ${CMAKE_BINARY_DIR}/g.c "void g(void){}\n")
ADD_LIBRARY(g SHARED g.c)
INSTALL(TARGETS f g LIBRARY DESTINATION lib OPTIONAL)

AFAICS, this exemplary project does what you intend, i.e. selecting the
targets to build with the Make command and install each target that has
been built by "make install" later. The combination of EXCLUDE_FROM_ALL
with OPTIONAL should also work since, to the best of my knowledge, the
warning w.r.t. undefined behaviour can be be safely ignored in that
case. However, a "make" or "make all" would not build the affected
targets, in contrast to the approach outlined above.

'hope that helps.

Regards,

Michael
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake


More information about the CMake mailing list