Impossible to build single cpp file using mingw32-make when the header file needed is generated from subfolder
In my project, lot of c++ source files includes generated header. It is possible to successfully build whole project but it is not possible to compile single cxx file. Minimal example project attached.
command:
mingw32-make tutorial.obj
output:
Building CXX object CMakeFiles/Tutorial.dir/tutorial.cxx.obj
D:\Workset\cmake_example\tutorial.cxx:5:19: fatal error: Table.h: No such file or directory
looks like CMake doesn't add dependency between Table.h and tutorial.cxx. So let's add it by hand:
If #SET_SOURCE_FILES_PROPERTIES(tutorial.cxx PROPERTIES OBJECT_DEPENDS ${PROJECT_BINARY_DIR}/Table.h)
is uncommented:
command:
mingw32-make tutorial.obj
output:
mingw32-make[1]: *** No rule to make target 'Table.h', needed by 'CMakeFiles/Tutorial.dir/tutorial.cxx.obj'. Stop.
Makefile:157: recipe for target 'tutorial.cxx.obj' failed
mingw32-make: *** [tutorial.cxx.obj] Error 2
CMake still doesn't know, how to produce file Table.h, so lets put custom target building this file instead of filename to tutorial.cxx dependencies.
Replace #SET_SOURCE_FILES_PROPERTIES(tutorial.cxx PROPERTIES OBJECT_DEPENDS ${PROJECT_BINARY_DIR}/Table.h)
by SET_SOURCE_FILES_PROPERTIES(tutorial.cxx PROPERTIES OBJECT_DEPENDS generate_res)
:
command:
mingw32-make tutorial.obj
output:
mingw32-make[1]: *** No rule to make target 'generate_res', needed by 'CMakeFiles/Tutorial.dir/tutorial.cxx.obj'. Stop.