I have a header like this:
#ifdef WITH_QT
#include <QObject>
#endif
namespace foo {
#ifdef WITH_QT
Q_NAMESPACE
#endif
enum class Letters {A, B, C };
#ifdef WITH_QT
Q_ENUM_NS(Letters)
#endif
}
And a cmake file:
cmake_minimum_required(VERSION 3.13)
find_package(Qt5 COMPONENTS Core)
qt5_wrap_cpp(moc_source foo.h)
add_library(foo STATIC ${moc_source})
target_compile_definitions(foo PUBLIC WITH_QT)
make VERBOSE=1 shows (abbreviated):
/usr/bin/moc foo.h
foo.h:0: Note: No relevant classes found. No output generated.