Include files specified by "-include" compiler options are not tracked as dependencies
- On Linux, create the following
CMakeLists.txt
:
cmake_minimum_required(VERSION 3.9)
project(foo C)
add_library(foo foo.c)
target_compile_options(foo PRIVATE "-include${CMAKE_CURRENT_SOURCE_DIR}/h2.h")
- Create 2 empty files named
h1.h
andh2.h
, and createfoo.c
containing the single line#include "h1.h"
. - Generate using "Unix Makefiles" and build
- touch h2.h
- Build again
Expected results:
foo is rebuilt, since the source was updated
Actual results:
foo is not rebuilt
This appears to be because CMake thinks that foo.c.o
depends only on foo.c
and h1.h
, not h2.h
. CMake should specify that foo.c.o
depends on all three files.