[CMake] calling a macro from add_custom_target [was "add_custom_target / add_definitions cache issues"]

Reto Glauser gentoo at blinkeye.ch
Fri May 15 04:32:06 EDT 2009


On Thu, 14 May 2009 07:49:34 -0700, Tyler Roscoe <tyler at cryptio.net> wrote:
> 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.
> 

All right. I introduced a FILE command in the macro:

file( WRITE version.h "#define VERSION \"${BRANCH}:${REVISION_HASH}\"\n" )

and include the generated version.h in my source files. 

Now I still have the problem the macro is executed only once. I tried to
call the macro from a custom_target:

add_custom_target(
   version ALL ${Git_INFO} ${${CMAKE_SOURCE_DIR}} ${GIT}
   COMMENT "git_version_info ${PROJECT_NAME} ${BRANCH}:${REVISION_HASH}"
)

but this doesn't seem to work.

How do I force the macro to be called each time?





More information about the CMake mailing list