Search code examples
qtcmakescxml

Qt statemachine scxml in cmake project without pro file?


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

Solution

  • 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})