Qt5, CMake, AUTOMOC and precompiled headers
cmake, qt, qt5, stdafx.h, visual-studio-2010
Solution
After some digging I decided to just turn the AUTOMOC feature off for projects that use precompiled headers:
set_target_properties (ProjectName PROPERTIES AUTOMOC FALSE)
# Set the headers that need moc'ing
file (GLOB MOC_FILES widget_filetransfer.h widget_main_menu.h widget_main_toolbar.h)
QT5_WRAP_CPP (MOC_SOURCES ${MOC_FILES})
...
# Force PCH for the generated MOC files
foreach (src_file ${MOC_SOURCES})
set_source_files_properties (${src_file}
PROPERTIES COMPILE_FLAGS "/Yustdafx.h /FIstdafx.h"
)
endforeach()
Problem
How to specify a precompiled header to the output of CMake (2.8.12.1) AUTOMOC ? So far, in the CMakeLists.txt I've tried these two separately: ``` set(AUTOMOC_MOC_OPTIONS "-bstdafx.h") set(AUTOMOC_MOC_OPTIONS "-fstdafx.h") ``` The generated AUTOMOC output when building the project (project_automoc.cpp) only contains the moc_xxx.cpp files: ``` /* This file is autogenerated, do not edit*/ /// <- stdafx.h should be here ?!?! #include "moc_widget_fps.cpp" #include "moc_widget_sysevents.cpp" ```