I'm a few years too late, but the replies to this question fail to build.
If the compiled SCXML files go through the MOC then the build will throw the following error.
(...)
duplicate symbol 'chart1::qt_static_metacall(QObject*, QMetaObject::Call, int, void**)' in:
src/CMakeFiles/foo.dir/foo_autogen/mocs_compilation.cpp.o
src/CMakeFiles/foo.dir/chart1.cpp.o
(...)
To avoid this error, the files generated by qt5_add_statecharts
need to be explicitly marked as SKIP_AUTOMOC
.
Also, qt5_add_statecharts
dumps the autogenerated source files in CMAKE_CURRENT_BINARY_DIR
, so that path needs to be featured in target_include_directories
to be reachable.
The example below builds and runs.
find_package(Qt5 5.15 REQUIRED Core Scxml)
target_link_libraries(myapp-lib
Qt5::Core
Qt5::Scxml
)
qt5_add_statecharts(QT_SCXML_COMPILED
chart1.scxml
chart2.scxml
)
set_source_files_properties(${QT_SCXML_COMPILED}
PROPERTIES
SKIP_AUTOMOC TRUE
)
add_executable(myapp
main.cpp
${QT_SCXML_COMPILED}
)
target_include_directories(myapp
PRIVATE
${CMAKE_CURRENT_BINARY_DIR}
)