From 7f92fd84cc87c5c7e86aac9cd0342394bb8527c3 Mon Sep 17 00:00:00 2001 From: Jeremy Huffman Date: Wed, 11 Sep 2019 20:04:44 -0400 Subject: [PATCH 1/5] Conditionals to build on MacOS --- lib/smooth/core/network/SocketDispatcher.cpp | 4 ++-- lib/smooth/include/smooth/core/network/ISocket.h | 2 +- .../include/smooth/core/network/SocketDispatcher.h | 9 +++++++-- lib/smooth/include/smooth/core/network/util.h | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/lib/smooth/core/network/SocketDispatcher.cpp b/lib/smooth/core/network/SocketDispatcher.cpp index e66bc0e7..6b211c05 100644 --- a/lib/smooth/core/network/SocketDispatcher.cpp +++ b/lib/smooth/core/network/SocketDispatcher.cpp @@ -361,12 +361,12 @@ namespace smooth::core::network #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wsign-conversion" - void SocketDispatcher::set_fd(std::size_t socket_id, fd_set& fd) + void SocketDispatcher::set_fd(FD socket_id, fd_set& fd) { FD_SET(socket_id, &fd); } - bool SocketDispatcher::is_fd_set(std::size_t socket_id, fd_set& fd) + bool SocketDispatcher::is_fd_set(FD socket_id, fd_set& fd) { return FD_ISSET(socket_id, &fd); } diff --git a/lib/smooth/include/smooth/core/network/ISocket.h b/lib/smooth/include/smooth/core/network/ISocket.h index 0bc98c17..7e9a611d 100644 --- a/lib/smooth/include/smooth/core/network/ISocket.h +++ b/lib/smooth/include/smooth/core/network/ISocket.h @@ -33,7 +33,7 @@ namespace smooth::core::network friend class smooth::core::network::SocketDispatcher; public: static const int INVALID_SOCKET = -1; -#ifdef ESP_PLATFORM +#if defined(ESP_PLATFORM) || defined(__APPLE__) // lwip doesn't signal SIGPIPE static const int SEND_FLAGS = 0; diff --git a/lib/smooth/include/smooth/core/network/SocketDispatcher.h b/lib/smooth/include/smooth/core/network/SocketDispatcher.h index 16663519..b666390b 100644 --- a/lib/smooth/include/smooth/core/network/SocketDispatcher.h +++ b/lib/smooth/include/smooth/core/network/SocketDispatcher.h @@ -43,6 +43,11 @@ namespace smooth::core::network private ISocketBackOff { public: +#ifdef ESP_PLATFORM + typedef size_t FD; +#else + typedef int FD; +#endif ~SocketDispatcher() override = default; static SocketDispatcher& instance(); @@ -90,9 +95,9 @@ namespace smooth::core::network using SocketOperationQueue = smooth::core::ipc::TaskEventQueue; std::shared_ptr socket_op; - static void set_fd(std::size_t socket_id, fd_set& fd); + static void set_fd(FD socket_id, fd_set& fd); - static bool is_fd_set(std::size_t socket_id, fd_set& fd); + static bool is_fd_set(FD socket_id, fd_set& fd); void print_status() const; diff --git a/lib/smooth/include/smooth/core/network/util.h b/lib/smooth/include/smooth/core/network/util.h index 697ffa60..f3f31eb1 100644 --- a/lib/smooth/include/smooth/core/network/util.h +++ b/lib/smooth/include/smooth/core/network/util.h @@ -17,7 +17,7 @@ limitations under the License. #pragma once -#ifdef ESP_PLATFORM +#if defined(ESP_PLATFORM) || defined(__APPLE__) #include #if _BYTE_ORDER == _LITTLE_ENDIAN #define SMOOTH_LITTLE_ENDIAN From 0756637f234f5a85058c3606ee2f328b1b38ee60 Mon Sep 17 00:00:00 2001 From: Jeremy Huffman Date: Wed, 11 Sep 2019 20:11:36 -0400 Subject: [PATCH 2/5] Update docs for MacOS. --- README.md | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 87b94c1e..3e0270ba 100644 --- a/README.md +++ b/README.md @@ -145,9 +145,24 @@ Please see the the different test projects under the test folder. When compiling root of the repo as a CMake project. Select the project you wish to build by setting `selected_test_project` in the top `CMakeLists.txt`. **You will likely have to re-generate your build files after changing the selection.** -## Using Smooth in your project (compiling for Linux) +## Using Smooth in your project (compiling for Linux or MacOS) -To build you application for Linux you must maintain a parallel build configuration as follows: +### System Libraries +Some libraries provided in the ESP distribution need to be installed as system libraries on the host. On Debian / Ubuntu: + +```shell +apt-get install libsodium-dev libmbedtls-dev +``` + +With Homebrew on MacOS: + +```shell +brew install libsodium mbedtls +``` + + +### CMake Config +To build your application on the host platform you must maintain a parallel build configuration as follows: Top `CMakeList.txt` @@ -160,6 +175,10 @@ if(${ESP_PLATFORM}) externals/smooth/smooth_component) project(your_project_name) else() + # first two entries are needed only on MacOS - brew installs libraries into /usr/local + include_directories(SYSTEM /usr/local/include) + link_directories(/usr/local/lib) + add_subdirectory(main) add_subdirectory(externals/smooth/lib) add_subdirectory(externals/smooth/mock-idf) From 4536b132440ba74dc4a33c54d726ee5d6597d5fe Mon Sep 17 00:00:00 2001 From: Jeremy Huffman Date: Wed, 11 Sep 2019 20:19:23 -0400 Subject: [PATCH 3/5] Note GCC --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 3e0270ba..7f503cbd 100644 --- a/README.md +++ b/README.md @@ -207,6 +207,18 @@ else() endif() ``` +### Building on MacOS +Currently only GCC is supported. You can install GCC via homebrew and then pass flags to CMake to use that compiler: + +```shell +brew install gcc +mkdir cmake-macos +cd cmake-macos +cmake -DCMAKE_C_COMPILER=gcc-9 -DCMAKE_CXX_COMPILER=g++-9 .. +make +``` + + Here's an example of how your `main.cpp` could look like if you want to compile for both ESP and Linux. The example assumes you have named your main class `App` and it is derived from `smooth::core::Application`, which most applications based on Smooth do. Doing so is not mandatory, it saves you some setup; see From 90da7370b987d703dfda08873cf1fcec74bf4b30 Mon Sep 17 00:00:00 2001 From: Jeremy Huffman Date: Thu, 12 Sep 2019 08:26:58 -0400 Subject: [PATCH 4/5] Support building Smooth standalone on MacOS. --- CMakeLists.txt | 6 +++++- README.md | 8 +++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e8008660..5bea4be8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,7 +72,11 @@ if(${ESP_PLATFORM}) include($ENV{IDF_PATH}/tools/cmake/project.cmake) project(${selected_test_project}) else() - message(STATUS "Compiling for Linux") + message(STATUS "Compiling for Host Platform") + if(${APPLE}) + include_directories(SYSTEM /usr/local/include) + link_directories(/usr/local/lib) + endif() add_subdirectory(mock-idf) add_subdirectory(lib) add_subdirectory(test/${selected_test_project}) diff --git a/README.md b/README.md index 7f503cbd..80044eee 100644 --- a/README.md +++ b/README.md @@ -175,9 +175,11 @@ if(${ESP_PLATFORM}) externals/smooth/smooth_component) project(your_project_name) else() - # first two entries are needed only on MacOS - brew installs libraries into /usr/local - include_directories(SYSTEM /usr/local/include) - link_directories(/usr/local/lib) + if(${APPLE}) + include_directories(SYSTEM /usr/local/include) + link_directories(/usr/local/lib) + endif() + add_subdirectory(main) add_subdirectory(externals/smooth/lib) From e3396505ba7fef55fafdd02dec97a0b3ee6c48e4 Mon Sep 17 00:00:00 2001 From: Jeremy Huffman Date: Thu, 12 Sep 2019 17:57:37 -0400 Subject: [PATCH 5/5] Prefer using to typedef. --- lib/smooth/include/smooth/core/network/SocketDispatcher.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/smooth/include/smooth/core/network/SocketDispatcher.h b/lib/smooth/include/smooth/core/network/SocketDispatcher.h index b666390b..832d0947 100644 --- a/lib/smooth/include/smooth/core/network/SocketDispatcher.h +++ b/lib/smooth/include/smooth/core/network/SocketDispatcher.h @@ -44,9 +44,9 @@ namespace smooth::core::network { public: #ifdef ESP_PLATFORM - typedef size_t FD; + using FD = size_t; #else - typedef int FD; + using fD = int; #endif ~SocketDispatcher() override = default;