[CMake] How to compile a file only when linking anyhow?

Mark Jonas toertel at gmail.com
Mon Apr 21 04:51:34 EDT 2008


Hi Alex,

>  > Do you have another idea?
>
>  Hmm, so you need to execute something in case something will actually be
>  built. I don't see a clean way, only hacks:
>
>  Maybe you can do something with add_custom_target() ?
>
>  add_custom_target(DateHelperTarget COMMAND your_fancy_date_tool)
>
>  add_executable(monsterapp ${sources})
>
>  add_dependencies(monsterapp DateHelperTarget)
>
>   This way DateHelperTarget would be always built before monsterapp. It would
>  be up to you to do something clever in your_fancy_date_tool.
>
>
>  Or create a static lib containing just that date file and link it to the
>  executable. Build that static lib everytime and use
>  add_custom_command(POST_BUILD) on that static lib to set its date back, so
>  its older than the executable and will not cause linking ?

I really appreciate all the nice hacks you are proposing but they do
not make me really happy when thinking of getting this to work with
Visual Studio as well. So for now I will stick to the downside that
the linker will always run because the date file is generated every
time the build is run. If the beating I receive from my colleagues is
too much I will start thinking of this again.

Thanks,
Mark


More information about the CMake mailing list