janoliver
janoliver

Reputation: 7824

force refresh of cmake script in subsequent runs of 'make'

In my cmake script I determine the current date and hand it to my c++ program source, so that the build date is compiled into the program. The problem is, that in subsequent runs of make, in which cmake is acutally not run at all, the date is not updated.

How can I force cmake to refresh it's variables and recompile the program by using make only? Alternatively: What is the best way to compile the build date into the binary?

The cmake script contains this:

INCLUDE(Today)
TODAY(DATE)

ADD_DEFINITIONS(
    ...
    -DBUILD_DATE=\"${DATE}\"
)

Upvotes: 2

Views: 1862

Answers (1)

user1283078
user1283078

Reputation: 2006

you could use a custom target to execute whatever you want. custom targets are always considered out of date and run on every build.

add_custom_target(RerunCmake ${CMAKE_COMMAND} ${CMAKE_SOURCE_DIR})
add_dependencies(YourTarget RerunCmake)

this works fine with makefiles. but visual studio for example will nag you after every build asking to reload the project because the project files changed on disk.

maybe it would be better to make a custom target that just updates a header file with the correct date so cmake doesn't rerun on every build

Upvotes: 2

Related Questions