[CMake] install target

Timenkov Yuri ytimenkov at parallels.com
Sun May 4 02:47:46 EDT 2008


On Saturday 03 May 2008 23:09:16 Alin M Elena wrote:
> Hi,
>
> Thanks Yuri.
> Based on your observations I got a solution.
> Note that I use doxygen to generate the documentation so I use the
> find_package(Doxygen)   somewhere before in CMakeLists.txt
>
> Here is what I did
> if(DOXYGEN)
>   configure_file(${CMAKE_SOURCE_DIR}/Doxyfile.cmake Doxyfile)
>   add_custom_target(docs
>     ${DOXYGEN_EXECUTABLE} ${PROJECT_BINARY_DIR}/Doxyfile)
Not exactly, I suggested using add_custom_command. add_custom_target doesn't 
set proper dependencies, instead it always runs at install time. Moreover, I 
don't think it is cross-platform way, because it may not work for 
VisualStudio or similar generators.

>   install(CODE "execute_process(COMMAND ${CMAKE_BUILD_TOOL} docs)")
>   install(DIRECTORY ${CMAKE_BINARY_DIR}/doc/html/ DESTINATION doc)
> endif(DOXYGEN)
>
> and now make install and make package behaves as I need.
> One may note two things.
> 1. because I used add_custom_target I get an out-of-date target each time
> so make docs gets executed always when make install or make package.
> 2. install(CODE hase to be always before install(DIRECTORY otherwise
> doc/html may not exist and one gets an error.
So it's good if this solution works for you. :)

>
> Alin
>
> > Hi,
> >
> > There were many discussions on this subject, but I don't remember final
> > solution. I suppose, in your case it is better to add special target via
> > ADD_CUSTOM_COMMAND, where OUTPUT is your documentation file(s), and
> > MAIN_DEPENDENCY/DEPENDS are source files. Later you can install output
> > file as usually. This is based on several points:
> > 1) "install" ensures that everything is built by executing make all
> > target. 2) ADD_CUSTOM_COMMAND while used properly sets correct
> > dependencies between target file and it's sources, so if anything
> > changed, CMake will rebuild this and all dependent targets.
> > 3) INSTALL command will install generated target.
> >
> > Of course, this will not work with ADD_CUSTOM_TARGET.
> >
> > So the drawback is that your documentation will be built (if something
> > has changed, that is actually only dependencies will be checked) every
> > time you run make. I suppose in CMake this is handled by some kind
> > of "BUILD_Documentation" variables to speed-up regular development.
> >
> > And if you need something really exotic at install time, you can refer to
> > INSTALL(CODE/SCRIPT) commands :).
> >
> > Yuri




More information about the CMake mailing list