Makefiles: Cleaning a configured file in a subdirectory
When I have a configured file in a subdirectory that I add to the list of clean files the file does not get regenerated when re-building the project. For illustrating this I have attached a simple project which with the following commands shows the issue that I'm having:
tar -xf clean_configured_file.tar.gz
mkdir build
cd build
cmake ../clean_configured_file
Which gives output:
-- The CXX compiler identification is AppleClang 10.0.1.10010046
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++
-- Check for working CXX compiler: /Library/Developer/CommandLineTools/usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/cmake/build
then:
make
gives the output:
Scanning dependencies of target app
[ 25%] Building CXX object CMakeFiles/app.dir/main.cxx.o
[ 50%] Linking CXX executable app
[ 50%] Built target app
Scanning dependencies of target one_down
[ 75%] Building CXX object level1/CMakeFiles/one_down.dir/lib.cxx.o
[100%] Linking CXX static library libone_down.a
[100%] Built target one_down
then:
make clean
make
gives the output:
[ 25%] Building CXX object CMakeFiles/app.dir/main.cxx.o
[ 50%] Linking CXX executable app
[ 50%] Built target app
Scanning dependencies of target one_down
[ 75%] Building CXX object level1/CMakeFiles/one_down.dir/lib.cxx.o
/tmp/cmake/clean_configured_file/level1/lib.cxx:2:10: fatal error: 'configure_me_level_one.h' file not found
#include "configure_me_level_one.h"
^~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
make[2]: *** [level1/CMakeFiles/one_down.dir/lib.cxx.o] Error 1
make[1]: *** [level1/CMakeFiles/one_down.dir/all] Error 2
make: *** [all] Error 2
If I however configure a file in the root directory of my project then the files (once cleaned) will get properly regenerated. This can be tested by uncommenting lines in the root directories CMakeLists.txt file.
Edited by Brad King