[CMake] New version forces rebuild all?

Cristian Adam cristian.adam at gmail.com
Wed Dec 5 17:54:24 EST 2018


On Wed, Dec 5, 2018 at 10:19 PM Andy <borucki.andrzej at gmail.com> wrote:

> (previously I send this mail not to mail list, but user)
> Maybe my cmake files are bad?
> I have created test project
> https://gitlab.com/andrzejbor/test_rebuild_all
> after commit is rebuild whole project
> what I might change?
> I don't want moving all but .git to one directory src/
>
>
The problem is that you add the GIT variables as compile time defines,
which means that after every commit you will have different compile command
lines, which trigger recompilation of whole project because you have used
add_definitions.

You should instead write those GIT variables in a file, like this:

file(WRITE ${CMAKE_BINARY_DIR}/git_version.h.in "
#define GIT_SHA1 \"@GIT_SHA@\"
#define GIT_TAG \"@GIT_TAG@\"
#define GIT_LOCAL_CHANGES \"@GIT_LOCAL_CHANGES@\""
)

configure_file(${CMAKE_BINARY_DIR}/git_version.h.in
    ${CMAKE_BINARY_DIR}/git_version.h @ONLY)

Make sure you have ${CURRENT_BINARY_DIR} as part of your target's include
directories. And then somewhere in your code do an #include "git_version.h".

Cheers,
Cristian.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20181205/2a420b11/attachment.html>


More information about the CMake mailing list