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

Crni Gorac cgorac at gmail.com
Sat Mar 29 13:13:53 EDT 2008


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.


More information about the CMake mailing list