Why cmake compiles everything after git commit

Let's say that I have a compilation of code at some point from cmake 2.8 to linux.

I change the file "my_changed_file", run cmake, and only this file is created. So far so good.

Now I want to fix this:

git add my_changed_file
git commit

If I started cmake again, I would expect nothing to happen. But all my files were recompiled, despite the fact that I did not touch anything! The timestamp seems untouched when I do ls -l.

I have the following lines:

execute_process(
  COMMAND git describe --abbrev=8 --dirty --always --tags
  WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
  OUTPUT_VARIABLE GIT_CODE_VERSION
  OUTPUT_STRIP_TRAILING_WHITESPACE
)
add_definitions("-DCODE_VERSION=${GIT_CODE_VERSION}")

But this only affects the main.cpp file

What's happening?

thank

0
source share
1 answer

CMake , . , CMake , .

. , , ( ):

version.h.in

#define CODE_VERSION @GIT_CODE_VERSION@

main.cpp

#include "version.h"
...

CMakeLists.txt

# Calculate value of variable GIT_CODE_VERSION
...
configure_file("version.h.in" "version.h")

configure_file , , . , cmake git commit, . cmake git commit main.cpp ( ) .


COMPILE_DEFINITIONS ( add_definition()):

set_property(SOURCE main.cpp APPEND
    PROPERTY COMPILE_DEFINITIONS "-DCODE_VERSION=${GIT_CODE_VERSION}")

cmake , main.cpp .

, , , makefile: , ( ) . .

+3

All Articles