[CMake] add_custom_target / add_definitions cache issues

Tyler Roscoe tyler at cryptio.net
Thu May 14 10:49:34 EDT 2009


On Thu, May 14, 2009 at 11:59:53AM +0200, Reto Glauser wrote:
> add_definitions( -DVERSION="${PROJECT_VERSION}" )
> 
> Now, I'd like to rerun and redefine -DVERSION each time I commit a change
> to the SCM or change the branch but fail to see how to achieve that. 
> 
> I tried to add a add_custom_target which calls the macro. But even though
> the add_custom_target is called each time (I verified that with the COMMENT
> argument), the macro isn't. So, how do I force the macro to be called each
> time? And how to properly redefine the compiler definition
> -DVERSION="${PROJECT_VERSION}" afterwards?

It's hard to say what's wrong with your custom_target/macro workflow
without seeing some CMakeLists code.

I would solve this problem a different way: put #define VERSION whatever
into a header, include that header from a source file in your
library/executable, and generate the header using a custom_target. This
workflow is a little more "standard" in CMake so it might be easier to
get working.

tyler


More information about the CMake mailing list