View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0014697CMakeCMakepublic2014-01-14 08:072014-06-02 08:38
ReporterChristian Meyer 
Assigned To 
PrioritynormalSeveritymajorReproducibilityalways
StatusclosedResolutionnot fixable 
PlatformOSlinuxOS Version
Product VersionCMake 2.8.7 
Target VersionFixed in Version 
Summary0014697: CMake does not add files to depend.make which are referenced by #include but not present on disk
DescriptionI added a bash script which should reproduce the problem on any system with a working cmake installation when generating Makefiles.

It boils down to CMake omitting to add a #included file to the depend.make if that include is not present on the hard drive at build time. Unfortunately it does not fix this when that file is added afterwards.

Use Case:
1. User commits new source to a repository but omits a header file (fairly common)
2. Build server initiates an incremental build which fails because the header file is missing
3. User commits the missing header
4. Build server starts incremental build, build succeeds
5. User modifies the header
6. Expected: Build server rebuilds the source file which included the header; Actual: Build server does nothing

Steps To Reproduce#!/bin/bash

# Test script to check for correct dependency updating in cmake when users forget to commit header files to repositories

# Returns a non-zero exit code on test failure.
cmake --version
echo "### Create a minimal test project"
echo "#include \"main.h\"" > main.cpp
echo "int main() {return 0;}" >> main.cpp
echo "add_executable(TestApp main.cpp)" > CMakeLists.txt
echo "### Run CMake and build the project (should fail because main.h is missing)"
cmake .
make
echo "### At this point the build fails because the header is missing"
echo "# Create the header and make (now the build should pass)"
touch main.h
make
echo "### Now the build passes normally"
echo "# Touch the header and make (now main.cpp should be rebuilt)"
touch main.h
make
echo "### The build does not recompile main.cpp even though I touched main.h"
echo "# Display depend.make and observe that main.h is missing"
cat CMakeFiles/TestApp.dir/depend.make
grep -q main.h CMakeFiles/TestApp.dir/depend.make
TEST_PASSED=$?
# Clean up for retest
make clean
rm main.h

exit ${TEST_PASSED}
Additional InformationScript output on my local machine:
cmake version 2.8.7
### Create a minimal test project
### Run CMake and build the project (should fail because main.h is missing)
-- Configuring done
-- Generating done
-- Build files have been written to: /scratch/gridbox/cmake-test
[100%] Building CXX object CMakeFiles/TestApp.dir/main.cpp.o
/scratch/gridbox/cmake-test/main.cpp:1:18: fatal error: main.h: No such file or directory
compilation terminated.
make[2]: *** [CMakeFiles/TestApp.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/TestApp.dir/all] Error 2
make: *** [all] Error 2
### At this point the build fails because the header is missing
# Create the header and make (now the build should pass)
[100%] Building CXX object CMakeFiles/TestApp.dir/main.cpp.o
Linking CXX executable TestApp
[100%] Built target TestApp
### Now the build passes normally
# Touch the header and make (now main.cpp should be rebuilt)
[100%] Built target TestApp
### The build does not recompile main.cpp even tough I touched main.h
# Display depend.make and observe that main.h is missing
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 2.8

CMakeFiles/TestApp.dir/main.cpp.o: main.cpp
TagsNo tags attached.
Attached Files

 Relationships
has duplicate 0014699closed Implicity dependency scanner does not not update depend.make in succeeding incremental make builds if a #include was missing 

  Notes
(0034937)
Brad King (manager)
2014-01-14 09:18

The implicit dependency scanning must operate under the assumption that the sources compile. It ignores #include's that it can't find because it has no idea where they would be if they did exist so it is not possible to add a dependency on them.

A workaround is to use the Ninja generator which gets dependencies from the compiler (but is limited to toolchains that can report these dependencies).
(0036079)
Robert Maynard (manager)
2014-06-02 08:38

Closing resolved issues that have not been updated in more than 4 months.

 Issue History
Date Modified Username Field Change
2014-01-14 08:07 Christian Meyer New Issue
2014-01-14 09:18 Brad King Note Added: 0034937
2014-01-14 09:18 Brad King Status new => resolved
2014-01-14 09:18 Brad King Resolution open => not fixable
2014-01-15 09:31 Brad King Relationship added has duplicate 0014699
2014-06-02 08:38 Robert Maynard Note Added: 0036079
2014-06-02 08:38 Robert Maynard Status resolved => closed


Copyright © 2000 - 2018 MantisBT Team