[CMake] how to define a target that will be run on request only, and always on install?

Timenkov Yuri ytimenkov at parallels.com
Mon Mar 31 02:03:06 EDT 2008


You may try to add install(SCRIPT/CODE) command which ensures that 
translations are built.

install(code "
	execute_process(
		COMMAND \${CMAKE_MAKE_PROGRAM} translations
		WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
	)
	FILE(INSTALL
		DESTINATION translations
		TYPE FILE
		FILES \"${CMAKE_CURRENT_BINARY_DIR}/foo.trans\")
")

This may work only on linux / or only with make program.

Also, you may wish to consider following case:
move code, which generates translation into separate file,
like GenerateTranslation.cmake and call it from 2 places: one is  
add_custom_command with cmake -P, and second is installation script. (That is 
if you'll have to change this process later, you need to change only one 
file).

On Saturday 29 March 2008 20:13:53 Crni Gorac wrote:
> On Sat, Mar 29, 2008 at 6:01 PM, Crni Gorac <cgorac at gmail.com> wrote:
> > I have some translation files, defined ADD_CUSTOM_COMMAND() to
> >  generate them on request:
> >   ADD_CUSTOM_COMMAND(
>
> Apologies for above; bad GMail, bad!
>
> So:
>
> Say I have a translation file, defined ADD_CUSTOM_COMMAND() to generate
> it on request:
>   ADD_CUSTOM_COMMAND(
>     OUTPUT foo.trans
>     COMMAND abracadabra -o foo.trans
>   )
> Let's say that it would be complicated to specify dependencies of this
> file from all source code files in my project, and that I prefer to not
> have it regenerated each time when some of source files changed anyway.
>
> Further, I have "translations" target defined, so that I could generate
> these files upon request:
>   ADD_CUSTOM_TARGET(
>     translations
>     DEPENDS foo.trans
>     )
>
> Finally, translations file is installed through corresponding INSTALL()
> command:
>   INSTALL(
>     FILES foo.trans
>     DESTINATION translations
>     PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
>   )
>
> Now, I'd need 2 additional things to achieve:
>
> 1. If foo.trans doesn't exists when "make install" run (or more
> precisely, if I haven't remembered to run "make translations"
> beforehand), I'd still like foo.trans to be generated.  So what I'd like
> to achieve would be to have "make install" dependent on "translations"
> target, but reading through mailing list archives I saw this is not
> possible.
>
> 2. Actually, in both cases ("make translations" and "make install"), I'd
> like foo.trans to be re-generated, which means to have the command
> "abracadabra -o foo.trans" re-run.  I know I could add:
>     COMMAND ${CMAKE_COMMAND} -E remove foo.trans
> immediately after OUTPUT line above in ADD_CUSTOM_TARGET(), but I'm
> wondering is there a more elegant solution?
>
> Thanks.
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake




More information about the CMake mailing list