AUTOMOC_MOC_OPTIONS does not work with CMake 3.21.4 and Visual Studio
I've got some sources files using Qt and <Windows.h>.
They are protected by #ifdef _WIN32 / #endif
to avoid compiling them on other platforms than Windows.
But because of this, on Windows moc does not process them and some symbols are missing at link time.
So I tried to add something like this in cmake to pass some macros to moc :
set_target_properties(${TARGET_NAME} PROPERTIES AUTOMOC ON)
if(WIN32)
set_target_properties(${TARGET_NAME} PROPERTIES AUTOMOC_MOC_OPTIONS "-D _WIN32")
endif()
But my files are still ignored.
In AutogenInfo.json I can see there are no _WIN32
in MOC_DEFINITIONS
.
As a workaround I can see other symbols there that I could use, since it looks like it has imported what comes from add_compile_definitions. (for example I have access to WIN32 without underscore)
But I think there is a bug somewhere, adding something to AUTOMOC_MOC_OPTIONS
should not remain without any consequences on the call to moc.