Using Cmake as a build tool with WSL Ubuntu 20.04 bash in a VSCode editor.
- Firstly, update your apt
sudo apt update
sudo apt upgrade
- Install pistache (our HTTP server) as described
sudo add-apt-repository ppa:pistache+team/unstable
sudo apt install libpistache-dev
- Install Mosquitto (our MQTT sub/pub/broker).
sudo apt install mosquitto mosquitto-clients libmosquitto-dev
- Install RapidJSON as our JSON reading library.
sudo apt-get install -y rapidjson-dev
- Install Open MP as our multithreading library.
sudo apt-get install libomp-dev
- Install cmake and make
sudo apt install make
sudo apt install cmake
Go to the /build folder and enter cmake .. ; make
in the bash terminal.
- In build/demo/ the file named
main
is our binary executable. - Enter
./main
to run our binary file. - In your browser go to
localhost:9080/test
and see if it works.
- Open a new bash terminal so we can make some curl requests (but keep the old terminal with the server running).
- Type
curl -X GET http://localhost:9080/settings/soilType
, you should receive the answer "soilType is Negru". - Type
curl -X PUT http://localhost:9080/settings/soilType/Roz
, you should receive "soilType was set to Roz". - Try some setting that do not exist, like
curl -X GET http://localhost:9080/settings/mortiSiRanitiInGhiveci
, you should receive "mortiSiRanitiInGhiveci was not found".
- Open a MQTT broker daemon, in any wsl bash run:
sudo service mosquitto start
- Now, publish something and see if our MQTT server is listening.
mosquitto_pub -t 'test' -m 'Nu-i caruta ca mertanu'
The message shall appear in the opened server.
As long as you don't add files or add god knows what weird libraries, you can simple go to the build/ folder and run make
after each change (we don't have to run cmake ..
again) and the code will compile with the last changes.
But if you want to add files to be compiled or additional libraries, we'll need to get our hands dirty and touch the CMakeLists.txt files.
You can install the library in ubuntu and link them in demo/CMakeLists.txt in the function target_link_libraries(main SmartPotLib pistache crypto ssl pthread DESIRED_INSTALLED_LIBRARY)
. DONE
If you need to download the library folder and use it in our programme separately from the ubuntu then I'll look into it another time cuz it's late now and I need to test this approach.
For now you can simply delete ALL the contents of build/ and rerun the cmake for a fresh build.
This is just a test.