Qt's moc not running when using cotire, Visual Studio, and CMake 3.12.x.x
Encountered an issue while using building a CMake project that uses Cotire (https://github.com/sakra/cotire/) for pre-compiled headers, and Qt5's Meta-Object Compiler (moc), using Visual Studio as a generator, and CMake 3.12.x. The issue is that moc is not run at all, which causes a build failure because the source files that moc should generate do not exist when Visual Studio tries to compile.
I've attached a minimal project which demonstrates this behaviour.
To generate a build that will fail:
- Use CMake 3.12.0 or greater
- Use Visual Studio as a generator (I use Visual Studio 15 2017 Win64)
- Have Qt5 installed (I use Qt5.9.2)
- You will need to tell CMake where to find Qt5, I set CMAKE_PREFIX_PATH to the installation of Qt.
- Open the generated solution and build. You should get an error along the lines of "Cannot open source file: 'C:\builds\cotire_bug_cmake3_12_0\main\moc_qobject_file.cpp': No such file or directory"
Following the above steps but with CMake 3.11.x will build successfully.