diff --git a/CMakeLists.txt b/CMakeLists.txt index f0b6f39..022b8a0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,12 +8,17 @@ include(projectheader) project_header(osdev_mqtt) add_subdirectory(src) -add_subdirectory(examples/connect) -add_subdirectory(examples/pub) -add_subdirectory(examples/sub) -add_subdirectory(examples/subunsub) -add_subdirectory(test) +if(ENABLE_EXAMPLES) + add_subdirectory(examples/connect) + add_subdirectory(examples/pub) + add_subdirectory(examples/sub) + add_subdirectory(examples/subunsub) +endif() + +if(ENABLE_TESTS) + add_subdirectory(test) +endif() include(packaging) package_component() diff --git a/README.md b/README.md index 4c3ff93..06d03a0 100644 --- a/README.md +++ b/README.md @@ -30,9 +30,15 @@ Just check your package manager for the correct package-name. $ cmake ../ $ gmake ( or make, depending on your platform ) ``` -And you're all set. In build/bin there are two examples, test_mqtt_pu and test_mqtt_sub. Have a broker running, -like mosquitto or flashmq capable of accepting anonymous connections. Start the "sub" part and couple of moments -later the "pub" part. If all went well, you should see two screens in sync running. + +## Building the examples and tests +### Tests +Normally only the library is being build. By adding `-DENABLE_TESTING` to the cmake step, the unittests are being build also. Make sure a broker is running on localhost and type `test/mqtt_test` to run the tests. + +### Examples +By adding the flag `-DENABLE_EXAMPLES` to the cmake step, the examples are being build together with the library. + +In build/bin there are two examples, test_mqtt_pu and test_mqtt_sub. Have a broker running, like mosquitto or flashmq capable of accepting anonymous connections. Start the "sub" part and couple of moments later the "pub" part. If all went well, you should see two screens in sync running. ``` Open terminal 1 @@ -41,6 +47,7 @@ later the "pub" part. If all went well, you should see two screens in sync runni Open terminal 2 $ bin/test_mqtt_pub ``` + Screen 2 is sending, Screen 1 is receiving. # Using the library.