[CMake] Selecting INSTALL target in Visual Studio Configuration by default

David Cole david.cole at kitware.com
Mon Mar 14 11:07:08 EDT 2011


On Mon, Mar 14, 2011 at 10:16 AM, Paul Baumer
<paul.baumer2 at googlemail.com> wrote:
> Sorry for not being clear enough. I meant (2).
>
>> (2) included in the "Build Solution" command, executing after all
>> other targets have been built, so that "F7" or "Build All" will
>> actually build the INSTALL target?
>>
>
>

In CMake's C++ code, in the
cmGlobalGenerator::CreateDefaultGlobalTargets method, the "install"
target depends on the "all" target. (i.e. -- all has to be up-to-date
before the install rules can be run...)

The net result of this is that:

  make install

...will build things first, if necessary, before executing the install
scripts to copy files around.

What you are asking for is for "install" to be *included* in "all" --
which is difficult to do, since, traditionally, people are used to
install depending on all.

One way you could nearly achieve this, without any sort of CMake C++
changes at all, would be to add a custom target at the bottom of the
top level CMakeLists.txt file, which would execute "make install"
*after* all other targets are built. You could even do it generically,
regardless of the underlying build system being used, by using
something like this in a custom target or custom command call:

  add_executable(exe1 ...)
  add_executable(exe2 ...)
  install( ... install rules for all libs and exes here ...)
  ...
  add_custom_target(install_after_all ALL
    COMMAND ${CMAKE_COMMAND} --build . --target install --config
${CMAKE_CFG_INTDIR}
  )
  add_dependencies(install_after_all exe1 exe2 ... any other
"important" target names here, too ... )


More information about the CMake mailing list