2

I have a large cmake controlled project in which I want a part to use the scxml state machine from qt. My question is the following:

How can i add the scxml module without having a pro file which i understand does not work with cmake?

Something like:

QT += scxm
Donald Duck
  • 8,409
  • 22
  • 75
  • 99

3 Answers3

1

Bisides to adding Scxml to find_package(...) macro, additional CMake steps are required to integrate Qt SCXML into your application:

# Add package
find_package(Qt5 5.10 REQUIRED Core Scxml)

# Link libraries
target_link_libraries(myapp-lib Qt5::Core Qt5::Scxml)

# Process your *.scsml files with Qt SCXML Compiler (qscxmlc)
qt5_add_statecharts(QT_SCXML_COMPILED chart1.scxml chart2.scxml)

# Add to executable
add_executable(myapp main.cpp ${QT_SCXML_COMPILED})
denmaus
  • 66
  • 2
0

You should have a list of Qt components to load in your CMake, just add Scxml to the list.

find_package(Qt5 5.9 REQUIRED
             COMPONENTS Core Gui Widgets Xml Concurrent Scxml
)
ymoreau
  • 3,402
  • 1
  • 22
  • 60
0

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}
)
RAM
  • 2,257
  • 2
  • 19
  • 41