tkem / fsmlite

Lightweight finite state machine framework for C++11
MIT License
156 stars 25 forks source link

Support for CMake #27

Closed hugolm84 closed 3 years ago

hugolm84 commented 3 years ago

Hi, thanks for all the work on this project!

I'm building and using fsmlite via CMake. This way I am able to find, link and test fsmlite on multiple platforms. I was wondering if a PR for support of CMake would be considered? Perhaps even replacing Make.

That way you could easily build and test using MSVC, GCC, Clang or any other compiler. To be able to build the tests with MSVC >=19.14, a change was required for successful compilation, basically:

-    friend class fsm;  // base class needs access to transition_table
+    friend class fsmlite::fsm<state_machine>;  // base class needs access to transition_table

After that, testing is easy as ctest -C Debug

Test project C:/dev/third_party/fsmlite/build
    Start 1: fsmlite_tests_test_basic_row
1/9 Test #1: fsmlite_tests_test_basic_row .....   Passed    1.43 sec
    Start 2: fsmlite_tests_test_mem_fn_row
2/9 Test #2: fsmlite_tests_test_mem_fn_row ....   Passed    1.44 sec
    Start 3: fsmlite_tests_test_notrans
3/9 Test #3: fsmlite_tests_test_notrans .......   Passed    1.63 sec
    Start 4: fsmlite_tests_test_player
4/9 Test #4: fsmlite_tests_test_player ........   Passed    1.63 sec
    Start 5: fsmlite_tests_test_recursive
5/9 Test #5: fsmlite_tests_test_recursive .....   Passed    2.60 sec
    Start 6: fsmlite_tests_test_row
6/9 Test #6: fsmlite_tests_test_row ...........   Passed    0.07 sec
    Start 7: fsmlite_tests_test_scoped
7/9 Test #7: fsmlite_tests_test_scoped ........   Passed    0.05 sec
    Start 8: fsmlite_tests_test_shared
8/9 Test #8: fsmlite_tests_test_shared ........   Passed    1.45 sec
    Start 9: fsmlite_tests_test_traits
9/9 Test #9: fsmlite_tests_test_traits ........   Passed    0.07 sec

100% tests passed, 0 tests failed out of 9

Total Test time (real) =  10.46 sec
tkem commented 3 years ago

@hugolm84 Since fsmlite is a pure header library, the autotools support is basically there for supporting unit tests. Since I'm much more familiar with autotools than CMake, I'll probably continue to make it the default. Especially since support for embedded platforms (my major concern) and cross-compiling is or has been an issue with CMake, but is said to have been improved with "modern" CMake (3.1+), and I'm always curious to learn some new tricks ;-) However, a PR supporting CMake would be more than welcome! If you're not trying to replace autotools but make this optional, doubly so ;-) Instructions for the uninitiated (e.g. cross-compiling for ARM targets) would definitely be a bonus, but that's up to you...

hugolm84 commented 3 years ago

Hi @tkem

Support for embedded platforms and cross compilation should not be an issue using CMake at this time. I am using Modern CMake and support multiple platforms, some more esoteric than others, using the CMake as build configuration tool.

I could do a CMake PR that could work side by side with your autotools and Makefiles. The main objective for me is to let CMake find fsmlite using find_package and allow for linking in existing CMake projects.

Instructions for example ARM should not be an issue 👍