So, I have simple project with library compiled from two sources and executable with depends on this library:
./a.cpp
#include "a.h"
int a() {
return X;
}
./a.h
int a();
./b.cpp
#include "b.h"
int b() {
return 2;
}
./b.h
int b();
./c.cpp
#include "a.h"
#include "b.h"
#include "c.h"
int c() {
return a() + b();
}
int main() {
return c();
}
./c.h
int c();
./CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
set_property(
SOURCE a.cpp
APPEND
PROPERTY COMPILE_DEFINITIONS
"X=${X}"
)
add_library(ab a.cpp b.cpp)
add_executable(c c.cpp)
target_link_libraries(c ab)
I compile it by (inside build dir)
cmake .. -DX=4
make
Then I want to change X to 5, I do
cmake .. -DX=5
make
I expect file a.cpp
to be recompiled, and ab
and c
to be relinked (because they both depend on this cpp file), but I expect no recompilation of other cpp's because their compilation options didn't change and they do not depend on a.cpp
What I get is that a.cpp
and b.cpp
are both recompiled (and c.cpp
is correctly not recompiled)
So my questions are:
- Is it expected behaviour. If so, why?
- How do I structure the project, so that changing compile options for 1 file will not recompile each file in the library?
Tried CMake 3.5.1 on Linux and CMake 3.7.2 on MacOS